Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Drawing a textured 3D object breaks SFML text rendering  (Read 2751 times)

0 Members and 2 Guests are viewing this topic.

zhensydow

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
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 );

    mydraw();

    window->pushGLStates();
    window->draw( text );
    window->popGLStates();
    window->display();
}
 

Using this simple mydraw function causes the SFML text not drawing:

   
    glUseProgram( myprogram );
    glEnableVertexAttribArray( 0 );
    glBindBuffer( GL_ARRAY_BUFFER, verts_buffer );
    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, nullptr );
 

If I commented out the mydraw call, the text is visible again.
« Last Edit: August 25, 2013, 01:12:02 pm by zhensydow »

zhensydow

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Drawing a textured 3D object breaks SFML text rendering
« Reply #1 on: August 25, 2013, 10:52:35 am »
I were using SFML 2.0 and I just upgrade to 2.1, but the problem remains.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing a textured 3D object breaks SFML text rendering
« Reply #2 on: August 25, 2013, 11:22:02 am »
You must disable what you enable. SFML does its best to reset all OpenGL states for drawing, but it can only handle OpenGL 2.x states.
Laurent Gomila - SFML developer

zhensydow

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Drawing a textured 3D object breaks SFML text rendering
« Reply #3 on: August 25, 2013, 01:08:46 pm »
Great! I added:

   
    glBindBuffer( GL_ARRAY_BUFFER, 0 );
    glDisableVertexAttribArray( 0 );
    glUseProgram( 0 );
 

And now it works.

Also, If I use only  3.3 core   Can I remove pushGLStates/popGLStates saving a few nanoseconds/per frame?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SOLVED] Drawing a textured 3D object breaks SFML text rendering
« Reply #4 on: August 25, 2013, 02:48:54 pm »
Quote
Can I remove pushGLStates/popGLStates saving a few nanoseconds/per frame?
Yes. You can remove them even with OpenGL 2.x, if you know exactly what you do with the states. And don't forget to call window.resetGLStates() before drawing with SFML.
Laurent Gomila - SFML developer

 

anything