Upside down glDrawPixels (again)

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()
  glOrtho(0, width, 0, height, 0.1, 1);
  glPixelZoom(1, -1);
  glRasterPos3f(0, height, -0.3);

// ...
glDrawPixels(width, height, format,
		 GL_UNSIGNED_BYTE, (void*)buffer);
// ...

However it produces only blackness. Replacing

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


  glPixelZoom(1, 1);
  glRasterPos3f(0, 0, -0.3);

produces the image, only upside down (as expected.)

What am I doing wrong?

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.

Fixed it!

Seems like I have to use

glRasterPos3f(0,height-1, -0.3

Odd, anyone know why this is?

Yes. Because for an image with height of say 480,
the last pixel would be the 479th (0 to 479 = 480 pixels).