Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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 );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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