Pregunta

Para mis últimos proyectos, he estado usando algunos de los archivos de utilidad que encontré mientras miraba algunas demostraciones aquí.

A saber, un archivo llamado OpenGL.h - se usa principalmente para administrar los sombreadores un poco como GLEW y otro archivo GL_FONT.

GL_FONT es una clase que usan para representar las fuentes en la pantalla usando los objetos de búfer de vértice.

Sin embargo, cuando uso esto para representar la fotograma en mi juego, dibuja todo menos el Skybox correctamente. Por alguna razón, el Skybox se vuelve blanco como se ve aquí, si no represento la fuente, parece este.

Aquí hay algunas partes de la clase GL_FONT que creo que son más importantes:

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();
}

Tengo trie cambiando glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT); a GLPUSHATTRIB (GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT); Y la textura de fondo regresa, pero la fuente no se representa.

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();
}

Este es una imagen del búfer de profundidad cuando se representa la fuente y este es lo que parece cuando no lo es.

¿Alguien podría arrojar algo de luz sobre este problema, por favor?

¡Cualquier ayuda sería muy apreciada!

Gracias.

¿Fue útil?

Solución

Parece begin() carece de un glPushMatrix() después glMatrixMode(GL_MODELVIEW). Esto podría hacer que la escena se renderice incorrectamente cuando también se representa algún texto.

No glGetError() Reportar un GL_STACK_UNDERFLOW ¿error?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top