2D projection/drawing question

Following on from my previous problem (drawing a bitmap) Im having trouble with actually drawing it to a fixed part of the screen.
I draw my 3D scene, then switch to 2D and then draw the bitmap to the lower left corner. The problem is I find the bitmap stays at the corner and it wont draw anywhere else on the screen.

Heres the code Im using:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluOrtho2D(0, WIDTH, 0, HEIGHT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//glTranslatef(0, WIDTH, 0);
//glRasterPos2f(0.0, 0.5);
glDrawPixels(64, 32, GL_RGB, GL_UNSIGNED_BYTE, scramble_bitmap);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

Where HEIGHT and WIDTH are the window size.

I have tried both of the commented out lines, but one only draws it at the corner and the other doesnt at all.

Anyone see where Im going wrong?

You need to use glRasterPos()

Yeah I know, but when I set it to (0.0, 0.0) the bitmap isnt drawn at all. (0,0) should be the center of my screen.

Sorry didn’t look what you were doing. You’re problem is that you are not treating rasterPos in window coordinates like it is.

You lost me there

That’s OK. What he said wasn’t actually in English.

I guess I should work on my english then, but I am trying to help…

Lets state it this way. You know the difference between screen coordinates, window coordinates, model coordniates, and world coordinates correct? Raster position is in window coordinates. So this means if you don’t do any modification to your modelview matrix (no rotates and no translates) you will get the following results on a window that is 256x256 pixels.
0,0 = lower left corner
128,128 = center

The only reason to use floats with raster position is to take advantage of sub-pixel precision.

The raster position is specified in world coordinates, not window coordinates, and is affected by both the modelview and projection matrix. It is treated just like any other vertex you pass to OpenGL; it get transformed by first the modelview, then the projection matrix, and after that, it’s clipped agains the view volume, and will be marked as an invalid raster position if outside the view volume.

To be 100% sure where the raster position will be located, replace glRasterPos2(x,y) with

glBegin(GL_POINTS);
glVertex2(x,y);
glEnd();

and see where the point appears on the window.

So, with identity matrices in both the modelview and projection stack, raster position (0,0) will be in the middle of the screen, (-1, -1) will be the lower left corner, and (1, 1) will be the upper right corner. And that is independent of the physical size of the window.

Most people that wants a 1-to-1 correspondence between the raster position and window pixel coodinated usually sets an orthograpic projection matrix that matches the dimensions of the viewport. This is done because the raster position is affected by the projection matrix (as I said above), which maps the position to window coordinates in a convenient way.

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, WIDTH, 0, HEIGHT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//glTranslatef(0, WIDTH, 0);
//glRasterPos2f(0.0, 0.5);
glDrawPixels(64, 32, GL_RGB, GL_UNSIGNED_BYTE, scramble_bitmap);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

Pushing a matrix stack will produce a copy of the last matrix, if you want to start over (ie apply a new projection, new modelview), you still have to clear it to identity first.

Also try ARB_window_pos if it’s supported on your card. It rocks.