PDA

View Full Version : Backgrounds



Running_Wolf
07-02-2001, 01:57 PM
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?

DaViper
07-02-2001, 02:08 PM
hmmm i would guess the last glLoadIdentity() is either unnesessary or your prob...

can't see anything else in this code

Running_Wolf
07-02-2001, 02:26 PM
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;

DFrey
07-02-2001, 02:38 PM
Try disabling depth testing when you draw the background. Then enable it before drawing the rest of the polygons.

Running_Wolf
07-02-2001, 05:41 PM
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