1
\$\begingroup\$

I writing a OpenGL game using SFML.

I'm using the push/pop function to combine OpenGL with SFML like the tutorial SFML+OpenGL but, when I added textures to my model, the SFML text rendering appears broken and wrong rendered.

The simplified loop I used is:

while( true ){
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glUseProgram( programID );

    // Draw the 3d textured object
    glActiveTexture( GL_TEXTURE0 );
    glBindTexture( GL_TEXTURE_2D, tex_2d0 );

    object.draw();

    window->pushGLStates();

    window->setView( view );
    window->draw( text );
    window->setView( window->getDefaultView() );

    window->popGLStates();

    window->display();
}

My 3d model is draw right but something in the glActiveTexture/glBindTexture mess up the text in the SFML part.

If I add:

glActiveTexture( 0 );
glBindTexture( GL_TEXTURE_2D, 0 );

And the end of my OpenGL rendering code, nothing is fixed anyway.

\$\endgroup\$
3
\$\begingroup\$

SFML but it can only saves/restores OpenGL 2.x states. We must disable what we enable in +3.x states. It works adding:

It's fixed adding at the end of own drawing something like:

glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
glBindTexture( GL_TEXTURE_2D, 0 );
glDisableVertexAttribArray( 0 );
glDisableVertexAttribArray( 1 );
glUseProgram( 0 );
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.