PDA

View Full Version : Solaris / Linux, glDrawPixels or personal problem?



bitshifter
03-01-2002, 04:23 PM
Hello,

I'm trying to display a 640x480 image using glDrawPixels. On Solaris it displays correctly, on a Linux box with an NVidia Riva TNT2 it doesn't show up at all. However, I've discoverd that if I alter the glRasterPos2i command from glRasterPos2i(0,480)
to glRasterPos2i(0,479) then the image appears but shifted one row of pixels down. Why won't it show up when I just use the 480, and why does this only happen on my linux box?

Thanks for any help.

Here's the code:

glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640,0.0,480);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRasterPos2i(0,480);
glPixelZoom(1,-1); glDrawPixels(scene->xRes,scene->yRes,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,image_pixels) ;

Bob
03-02-2002, 07:51 AM
Because the coordinate (0, 480) is not the center of the pixel, but the edge of that pixel. Due to difference in the implementations, you might be hitting different pixels. If you happen to hit the pixel outside the screen, you get an invalid raster position, and nothing will be drawn.

Try offset the coordinates in glOrtho by -0.5 to



gluOrtho2D(0.0 - 0.5, 640 - 0.5, 0.0 - 0.5, 480 - 0.5);

and you will hit the center of the pixel instead of the edge, which can cause trouble.

bitshifter
03-04-2002, 12:38 PM
That worked. Thanks a bunch for your help!