Original Post
Is there any way to make glDrawPixels draw slightly out the left or top sides of the Viewport? I''ll explain what I mean...
I''m using OpenGL in Orthographic projection to draw the GUI for a game, and I need to add a cursor. The problem arises when the hot-spot of the cursor is not in the top left of the image. If I had a 32x32 cursor with the hot-spot at 16,16 and the user moves the cursor to the top left of the window (where the cursor image would be drawn from (-16 -> +16, -16 -> +16), then glDrawPixels doesn''t draw the image. It works fine on the right and bottom sides of the window where the other sides of the cursor disappear out the side. Any ideas?
Here''s my code:
The tgaImage variable defines the RGBA data of the cursor taken from my CTGAImage class, the wX and wY variables specify the cursor position, while the wHotX and wHotY variables define the hot-spot of the cursor (16, 16 in the above example). The wWidth and wHeight are the dimensions of the cursor and wScreenCX and wScreenCY specify the dimensions of the screen.
I tried changing glOrtho to -16.0f, 640.0f, 480.0f, -16.0f, but that didn''t work either, as you would expect.
glMatrixMode(GL_PROJECTION); // Change to Projection Matrix glPushMatrix(); // Save the current Projection Matrix glLoadIdentity(); // Clear the current Projection Matrix glOrtho(0.0f, (float)wScreenCX, (float)wScreenCY, 0.0f, -1.0f, 1.0f); // Create Orthographic Projection glMatrixMode(GL_MODELVIEW); // Change to ModelView Matrix glPushMatrix(); // Save the current ModelView Matrix glLoadIdentity(); // Clear the current ModelView Matrix // Draw TGA glPixelZoom(1.0f, -1.0f); // Flip images (they appear upside-down otherwise) glRasterPos3f((float)wX - (float)wHotX, (float)wY - (float)wHotY, 0.0f); // Set drawing position glDrawPixels(wWidth, wHeight, GL_RGBA, GL_UNSIGNED_BYTE, tgaImage); glPopMatrix(); // Restore ModelView Matrix glMatrixMode(GL_PROJECTION); // Change to Projection Matrix glPopMatrix(); // Restore Projection Matrix glMatrixMode(GL_MODELVIEW); // Change to ModelView Matrix