Backgrounds

I am trying to create a static background. I have written some code to do this but I have encountered a problem. Anything I draw after the background doesn’t show up. I know that it’s viewable on the screen because when I disable the background it shows up. Here is my code:

// The loading of the background. From NeHe’s site.
LoadBackGroundTexture(Filename, *texture);

// The displaying of the background.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 128, 0, 128);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_TRIANGLES);
glTexCoord2f(1.0, 1.0); glVertex2i(128, 0);
glTexCoord2f(0.0, 0.0); glVertex2i(0, 128);
glTexCoord2f(1.0, 0.0); glVertex2i(128, 128);

glTexCoord2f(0.0, 0.0); glVertex2i(0, 128);
glTexCoord2f(1.0, 1.0); glVertex2i(128, 0);
glTexCoord2f(1.0, 0.0); glVertex2i(0, 0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glLoadIdentity();

What am I doing wrong?

hmmm i would guess the last glLoadIdentity() is either unnesessary or your prob…

can’t see anything else in this code

Thanks for trying but removing that last glLoadIdentity() didn’t solve the problem. Here is my actual code when I try to draw both the background and a triangle on top of it.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix

background.Draw();

glTranslatef(0.0, -0.5, -6.0);
textures.Bind(0);
glRotatef(rotate, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, 0.0, 0.0);
glEnd();
rotate += 0.5f;

Try disabling depth testing when you draw the background. Then enable it before drawing the rest of the polygons.

Thank You!!! That was my problem! It is fixed now. If you want to see the result go to http://gen.gserver.com/running_wolf/index.html