PDA

View Full Version : An overlay image



fatquack
07-12-2008, 10:01 AM
Say I have a spinning cube like so:
http://fatquack.net/1.PNG
How do I add a 2d image in the forground like so:
http://fatquack.net/2.PNG

Zengar
07-12-2008, 10:12 AM
Disable depth test, set up an ortho projection and draw your image.

fatquack
07-12-2008, 10:32 AM
Erm, could you give me the code to see (I am very new to this, sorry).

dletozeun
07-12-2008, 10:37 AM
this set ortho projection



/**
* @brief Sets the orthographic projection to draw 2D objects. Here it is used to display texts on the screen.
* Note that origin is the upper left corner and coordinates unit is the pixel. w= screen width, h= screen height
*/
void setOrthographicProjection()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, w, 0, h);
// invert the y axis, down is positive
glScalef(1, -1, 1);
// mover the origin from the bottom left corner
// to the upper left corner
glTranslatef(0, -h, 0);
glMatrixMode(GL_MODELVIEW);
}


taken from lighthouse3D glut tutorial (http://www.lighthouse3d.com/opengl/glut/).

Zengar
07-12-2008, 11:19 AM
Some pseudocode:



# width and height are width and height of the window
glMatrixMode(GL_PROJECTION)
glPushMatrix # save the current projection matrix
glLoadIdentity
gluOrtho(0, width, 0, height)

# now one GL unit corresponds to one window pixel, so you can position your image
# draw image

glPopMatrix # restore old matrix

fatquack
07-12-2008, 12:14 PM
Okay, thank you this works at first but as i change gluLookAt it looks at the picture in the over from a different angle as well, and how would i go about stopping gluLookAt from applying to this one image?

Zengar
07-12-2008, 01:55 PM
You are right... you also have to "deactivate" the modelview matrix; simply load it to be the identity matrix. You'll figure it out ;)

fatquack
07-12-2008, 03:23 PM
No, I am really not that good. I tried putting
glMatrixMode(GL_PROJECTION);
before i drew the image and then
glMatrixMode(GL_MODELVIEW);
afterwards, but that had no effect

fatquack
07-13-2008, 05:46 AM
Sorted Now!!