1

I am trying to implement HUD to my 3d application, what I have achieved is I have a rectangle at certain position, with texture over it. The problem is that whenever I rotate or move camera, texture scales or moves with the camera, looks very weird. Any ideas why it might happen?

This is what I do to add the HUD:

glDisable(GL_DEPTH_TEST);  
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
gluOrtho2D( 0, 1, 0, 1);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();



        glEnable (GL_TEXTURE_2D);
        glBindTexture (GL_TEXTURE_2D,4 );
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


        glBegin( GL_QUADS );
            glColor3f( 1.0f, 1.0f, 0.0f );

            glTexCoord2f(0,0);
            glVertex2f( 0.0f, 0.0f );
            glTexCoord2f(1,0);
            glVertex2f( 0.4f, 0.0f );
            glTexCoord2f(1,1);
            glVertex2f( 0.4f, 0.4f );
            glTexCoord2f(0,1);
            glVertex2f( 0.0f,0.4f );
        glEnd();

    glPopMatrix();


glMatrixMode( GL_PROJECTION );
glPopMatrix();
 glEnable(GL_DEPTH_TEST); 
glEnable( GL_LIGHTING );
Bart
  • 19,692
  • 7
  • 68
  • 77
  • Are you trying to draw the HUD in 2D, or 3D? Can you post a screenshot of the problem you've described? – Bojangles Apr 21 '12 at 13:09
  • Are you drawing it in Orthographic projection then, and using pixel values? – Bojangles Apr 21 '12 at 13:16
  • I am using a third-party code, I just wanted to add Hud somehow. I am using one of the textures they supplied (it is number 4 in the code), should I look in that direction? – Ivan Konanykhin Apr 21 '12 at 13:20

1 Answers1

0

You're code lacks another call, glMatrixMode(GL_MODELVIEW); after you call glPopMatrix() for the second time.

Perhaps this is lower in your code, but from your description of what's happening, it does sound like an issue with the matrices.