Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Backgrounds

  1. #1

    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?

  2. #2
    Junior Member Newbie
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    15

    Re: Backgrounds

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

    can't see anything else in this code
    yes

  3. #3

    Re: Backgrounds

    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;

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: Backgrounds

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

  5. #5

    Re: Backgrounds

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •