An overlay image

Say I have a spinning cube like so:

How do I add a 2d image in the forground like so:

Disable depth test, set up an ortho projection and draw your image.

Erm, could you give me the code to see (I am very new to this, sorry).

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.

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

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?

You are right… you also have to “deactivate” the modelview matrix; simply load it to be the identity matrix. You’ll figure it out :wink:

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

Sorted Now!!