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

Author Topic: [SOLVED] sf::Text messed up with OpenGL calls.  (Read 2438 times)

0 Members and 1 Guest are viewing this topic.

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
[SOLVED] sf::Text messed up with OpenGL calls.
« on: October 13, 2011, 11:09:09 am »
First of all : if there is topic already covering this problem, please PM me a link and delete the thread.

If not :
Laurent, you wrote someday that in order to keep this working, one needs to
"(...) call SaveGLStates/RestoreGLStates around SFML code."

I am using many OpenGL functions beside SFML, and was wondering, what does sf::Text actually need to be displayed properly?

I'm pretty certain that GL_TEXTURE_2D must be enabled, but what else? I'd like to skip all the unnecessary state preserves, since they would be used probably only in this one particular point of my code.

I won't be sending my code examples, since it changes so much in OpenGL states (i'm using native 4.0 shaders, for example) that it won't give much help anyway.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SOLVED] sf::Text messed up with OpenGL calls.
« Reply #1 on: October 13, 2011, 11:28:17 am »
Quote
I'd like to skip all the unnecessary state preserves, since they would be used probably only in this one particular point of my code.

If you use it at only one location in your code, then don't bother and use the SFML functions to save/restore GL states.
Doing it manually is harder than what the doc suggests :D
Laurent Gomila - SFML developer

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
[SOLVED] sf::Text messed up with OpenGL calls.
« Reply #2 on: October 13, 2011, 11:39:48 am »
I sometimes love the times when expectations meet reality ;)

From documentation :
Quote
"Note that this function is quite expensive and should be used wisely. It is provided for convenience, and the best results will be achieved if you handle OpenGL states yourself (because you really know which states have really changed, and need to be saved / restored)."


I wrapped my sfml drawing call in Save/Restore openGL states, but it didn't help. Should I reset the states for sfml? Is there any function for it?

(So it would look like:
Code: [Select]

App.SaveGLStates();
App.ResetGLStatesSoThatSfTextWontBeSeenAsAWhiteRectangles();
/* My sophisticated GUI renders here */
App.RestoreGLStates();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SOLVED] sf::Text messed up with OpenGL calls.
« Reply #3 on: October 13, 2011, 11:43:54 am »
What is ResetGLStatesSoThatSfTextWontBeSeenAsAWhiteRectangles? You don't need such a function if you use Save/RestoreGLStates.

What is "My sophisticated GUI renders here"? Is it pure SFML drawing?
Laurent Gomila - SFML developer

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
[SOLVED] sf::Text messed up with OpenGL calls.
« Reply #4 on: October 13, 2011, 11:55:05 am »
I've actually disabled all of the features of my GUI, leaving only
Code: [Select]
void CGUI::Print (const string& msg, const float x, const float y)
{
sf::Text Title (msg, sf::Font::GetDefaultFont(), 20);
Title.SetPosition (x, y);
m_Wnd->SaveGLStates();
m_Wnd->Draw(Title);
m_Wnd->RestoreGLStates();
}


I asked about this weird function, because i was wondering how these functions actually work.
I'm sure you know the code like this:
Code: [Select]
glMatrixMode(/*choose any */);
// equivalent of save
glPushMatrix();

// now the reset function:
glLoadIdentity()

/* DRAWING */

// and restore
glPopMatrix();


So i was missing the reseting part[/code]

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
[SOLVED] sf::Text messed up with OpenGL calls.
« Reply #5 on: October 13, 2011, 09:12:27 pm »
I was fighting with it for about 1,5 hour, trying to turn on/off different opengl attributes in different combinations, but with no success.

Don't you just have a list of what should be enabled in order to sf::Text to render text properly? It would make my day, i spent countless hours on it in my previous project, and eventually made it randomly to work, though i don't have the slightest clue what actually solved the problem.

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
[SOLVED] sf::Text messed up with OpenGL calls.
« Reply #6 on: October 15, 2011, 12:50:54 am »
Ok, FINALLY!!

The key was:
Code: [Select]
glActiveTexture(GL_TEXTURE0);
It's an ARB extension function, used basically for multitexturing.

Now both sf::Text AND my shaders run properly ;)

 

anything