PDA

View Full Version : Upside down glDrawPixels (again)



jonkje84
03-09-2005, 09:37 AM
Hello, I'm trying to draw a buffer to screen using glDrawPixels, but it ends up upside down. I know this is because OpenGL has (0,0) in lower-left corner while my image has (0,0) in top-left corner. So I've read some threads here and from what I understand this should solve the problem:


void setup_2d()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, 0.1, 1);
glPixelZoom(1, -1);
glRasterPos3f(0, height, -0.3);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

// ...
glDrawPixels(width, height, format,
GL_UNSIGNED_BYTE, (void*)buffer);
// ...However it produces only blackness. Replacing

glPixelZoom(1, -1);
glRasterPos3f(0, height, -0.3);with:

glPixelZoom(1, 1);
glRasterPos3f(0, 0, -0.3);produces the image, only upside down (as expected.)

What am I doing wrong?

dvm
03-09-2005, 09:45 AM
Maybe when you flip it upside down, you try to print outside the visible raster position? That would explain why the image doesn't show I think. Also have you considered rearranging the image yourself? I mean after you load the image, manipulate the pixels so you flip them. Maybe if you do a search on google you'll find something.

jonkje84
03-09-2005, 09:54 AM
Fixed it!

Seems like I have to use
glRasterPos3f(0,height-1, -0.3Odd, anyone know why this is?

uruk
03-14-2005, 02:24 AM
Yes. Because for an image with height of say 480,
the last pixel would be the 479th (0 to 479 = 480 pixels).