Question

I'm new to OpenGL, and I've been going through NeHe's tutorials and various other web sources, and I'm testing some things to render text as a HUD of sorts over everything else. After a very long night, I can't get this to work and I can't find any solutions here that work, so I thought I'd ask.

My code:

GLvoid glLoadHUD(GLvoid)
{
    glPushAttrib(GL_LIGHTING_BIT |
                    GL_DEPTH_BUFFER_BIT |
                    GL_TEXTURE_BIT);

    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);

    glMatrixMode(GL_PROJECTION);
        glPushMatrix();
            glLoadIdentity();
            glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
            glRasterPos2f(0.1f, 0.6f);
            glColor3f(1.0f,1.0f,1.0f);
            glPrint("Test.");
            glRasterPos2f(0.0f, 0.0f);
        glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopAttrib();

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);  
    glEnable(GL_DEPTH_TEST);
}    

Which is the code to render the text, and this is the code for drawing the scene:

int DrawGLScene(GLvoid)                                         
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears buffers
glLoadIdentity();

// If I put glLoadHUD(); here, it renders but the models render over it,
    //  which is useless.

for (xloop = 0; xloop < 3;)
{
    glLoadIdentity();
    glTranslatef(-4.0f+(float(xloop)*4.0f),0.0f,-12.0f);
    glCallList(dlstBox);    // This is the call to create a box.
    xloop++;
}


glLoadHUD();  // If I put it here though, it doesn't render at all.

return TRUE;
}

Thank you in advance for any help you could give, I know I'm pretty green and I'm sure it's staring me right in the face, but this is driving me mad and I'm not sure how to make it work.

Was it helpful?

Solution

With glLoadHud after the rest of the scene, your MODELVIEW matrix is still on the stack, and you do not clear it as part of glLoadHud. Thus all of the glTranslatef translations that you accumulate during the scene are still active when you're drawing the hud, which translates it right out of your viewable window.

Clear the MODELVIEW matrix as part of the start of glLoadHud and see if that makes a difference.

OTHER TIPS

It might be printing inside your z-clipping so it will not show up on your screen. So, move out of the screen a little bit and see if it shows up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top