문제

For my last few projects I have been using some of the utility files that I found whilst looking at a few demos here.

Namely a file called opengl.h - mainly used to manage shaders a bit like glew and another file gl_font.

gl_font is a class they use to render fonts on screen using vertex buffer objects.

However, when I use this to render the framerate in my game it draws everything but the skybox correctly. For some reason the skybox is rendered white as seen here, if I do not render the font it looks like this.

Here are some parts of the gl_font class that I think are most important:

void GLFont::begin()
{
    HWND hWnd = GetForegroundWindow();
    RECT rcClient;

    GetClientRect(hWnd, &rcClient);

    int w = rcClient.right - rcClient.left;
    int h = rcClient.bottom - rcClient.top;

    glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT);

    glDisable(GL_LIGHTING);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, m_fontTexture);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0f, w, h, 0.0f, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);

    drawTextBegin();
}

I have trie changing glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT); to glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT); and the background texture returns, but the font isn't rendered.

void GLFont::end()
{
    drawTextEnd();

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);

    glDisable(GL_BLEND);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glPopAttrib();
}

This is an image of the depth buffer when the font is rendered and this is what is looks like when it is not.

Could anyone shed some light on this problem please?

Any help would be much appreciated!

Thanks.

도움이 되었습니까?

해결책

Looks like begin() lacks a glPushMatrix() after glMatrixMode(GL_MODELVIEW). This might cause the scene to be rendered incorrectly when some text is also rendered.

Didn't glGetError() report a GL_STACK_UNDERFLOW error?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top