283
285
void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, void *rect)
285
287
unsigned char *uc_rect= (unsigned char*) rect;
286
float origin_x= 0.375;
287
float origin_y= 0.375;
290
if (x>=origin_x && y>=origin_y) {
292
glDrawPixels(img_w, img_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect);
294
int old_row_length= glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
295
float xzoom= glaGetOneFloat(GL_ZOOM_X);
296
float yzoom= glaGetOneFloat(GL_ZOOM_Y);
298
/* The pixel space coordinate of the intersection of
299
* the [zoomed] image with the origin.
301
float ix= (origin_x-x)/xzoom;
302
float iy= (origin_y-y)/yzoom;
289
float xzoom= glaGetOneFloat(GL_ZOOM_X);
290
float yzoom= glaGetOneFloat(GL_ZOOM_Y);
292
/* The pixel space coordinate of the intersection of
293
* the [zoomed] image with the origin.
304
/* The maximum pixel amounts the image can cropped
305
* without exceeding the origin.
307
int off_x= floor((ix>origin_x)?ix:origin_x);
308
int off_y= floor((iy>origin_y)?iy:origin_y);
310
/* The zoomed space coordinate of the raster
313
float rast_x= x + off_x*xzoom;
314
float rast_y= y + off_y*yzoom;
316
if (off_x<img_w && off_y<img_h) {
317
glaRasterPosSafe2f(rast_x, rast_y, origin_x, origin_y);
318
glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
319
glDrawPixels(img_w-off_x, img_h-off_y, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect+off_y*img_w*4+off_x*4);
320
glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length);
298
/* The maximum pixel amounts the image can be cropped
299
* at the lower left without exceeding the origin.
301
int off_x= floor(MAX2(ix, 0));
302
int off_y= floor(MAX2(iy, 0));
304
/* The zoomed space coordinate of the raster position
305
* (starting at the lower left most unclipped pixel).
307
float rast_x= x + off_x*xzoom;
308
float rast_y= y + off_y*yzoom;
313
/* Determine the smallest number of pixels we need to draw
314
* before the image would go off the upper right corner.
316
* It may seem this is just an optimization but some graphics
317
* cards (ATI) freak out if there is a large zoom factor and
318
* a large number of pixels off the screen (probably at some
319
* level the number of image pixels to draw is getting multiplied
320
* by the zoom and then clamped). Making sure we draw the
321
* fewest pixels possible keeps everyone mostly happy (still
322
* fails if we zoom in on one really huge pixel so that it
323
* covers the entire screen).
325
glGetFloatv(GL_SCISSOR_BOX, scissor);
326
draw_w = MIN2(img_w-off_x, ceil((scissor[2]-rast_x)/xzoom));
327
draw_h = MIN2(img_h-off_y, ceil((scissor[3]-rast_y)/yzoom));
329
if (draw_w>0 && draw_h>0) {
330
int old_row_length = glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
332
/* Don't use safe RasterPos (slower) if we can avoid it. */
333
if (rast_x>=0 && rast_y>=0) {
334
glRasterPos2f(rast_x, rast_y);
336
glaRasterPosSafe2f(rast_x, rast_y, 0, 0);
339
glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
340
glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect + (off_y*img_w + off_x)*4);
341
glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length);
364
384
float wo_w, wo_h;
366
glGetIntegerv(GL_VIEWPORT, di->orig_vp);
367
glGetIntegerv(GL_SCISSOR_BOX, di->orig_sc);
368
glGetFloatv(GL_PROJECTION_MATRIX, di->orig_projmat);
369
glGetFloatv(GL_MODELVIEW_MATRIX, di->orig_viewmat);
386
glGetIntegerv(GL_VIEWPORT, (GLint *)di->orig_vp);
387
glGetIntegerv(GL_SCISSOR_BOX, (GLint *)di->orig_sc);
388
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)di->orig_projmat);
389
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)di->orig_viewmat);
371
391
di->screen_rect= *screen_rect;
372
392
if (world_rect) {
437
/* **************** glPoint hack ************************ */
439
static int curmode=0;
440
static int pointhack=0;
441
static GLubyte Squaredot[16] = { 0xff,0xff,0xff,0xff,
444
0xff,0xff,0xff,0xff};
446
void bglBegin(int mode)
450
if(mode==GL_POINTS) {
452
glGetFloatv(GL_POINT_SIZE_RANGE, value);
454
glGetFloatv(GL_POINT_SIZE, value);
455
pointhack= floor(value[0]+0.5);
456
if(pointhack>4) pointhack= 4;
463
void bglVertex3fv(float *vec)
469
glBitmap(pointhack, pointhack, (float)pointhack/2.0, (float)pointhack/2.0, 0.0, 0.0, Squaredot);
471
else glVertex3fv(vec);
476
void bglVertex2fv(float *vec)
482
glBitmap(pointhack, pointhack, (float)pointhack/2, pointhack/2, 0.0, 0.0, Squaredot);
484
else glVertex2fv(vec);
492
if(pointhack) pointhack= 0;
497
/* *************** glPolygonOffset hack ************* */
499
// both temporal, so here for now (ton)
500
#include "BKE_global.h"
501
#include "DNA_view3d_types.h"
503
/* dist is only for ortho now... */
504
void bglPolygonOffset(float dist)
506
static float winmat[16], offset=0.0;
511
// glEnable(GL_POLYGON_OFFSET_FILL);
512
// glPolygonOffset(-1.0, -1.0);
514
/* hack below is to mimic polygon offset */
515
glMatrixMode(GL_PROJECTION);
516
glGetFloatv(GL_PROJECTION_MATRIX, (float *)winmat);
518
/* dist is from camera to center point */
520
if(winmat[15]>0.5) offs= 0.00001*dist*G.vd->dist; // ortho tweaking
521
else offs= 0.0005*dist; // should be clipping value or so...
526
glLoadMatrixf(winmat);
527
glMatrixMode(GL_MODELVIEW);
531
glMatrixMode(GL_PROJECTION);
534
glLoadMatrixf(winmat);
535
glMatrixMode(GL_MODELVIEW);