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

Author Topic: mixing sf::String with OpenGL - text is always white.  (Read 4624 times)

0 Members and 1 Guest are viewing this topic.

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
mixing sf::String with OpenGL - text is always white.
« on: January 06, 2009, 07:46:40 pm »
Hi, I want to use SFML to create a window and handle input for OpenGL but I also want to use SFML for drawing strings(because it seams easy to me and I don't want to search for another OpenGL textlibrary).
Now I have a code to draw an image(with texturemapping) but when I execute the function, no matter if it is before or after the textdrawing, the drawn string is always white.
That's the relevant codepart:
Code: [Select]

img->draw(); // if I comment this line out the text is red as it should be

if(m_show_fps)
{
static int i(0);
stringstream fps("");
fps << "fps: " << static_cast<int>(1/m_window->GetFrameTime()) << endl;
sf::String fps_drawable(fps.str(), Font::GetDefaultFont(), 10);
fps_drawable.SetColor(Color::Red);
m_window->Draw(fps_drawable);
}

And image::draw
Code: [Select]

void image::draw() const
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, m_tex_name);

glVertexPointer(coord_per_vertex, GL_SHORT, coord_per_vertex*sizeof(GLshort), &m_vertices[0]);
glTexCoordPointer(texel_per_vertex, GL_FLOAT, texel_per_vertex*sizeof(GLfloat), &m_tex_coords[0]);

glDrawElements(GL_QUADS, vertices_per_square, GL_UNSIGNED_BYTE, &m_indices[0]);
glFlush();
}

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
mixing sf::String with OpenGL - text is always white.
« Reply #1 on: January 10, 2009, 02:57:09 am »
Any solutions?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
mixing sf::String with OpenGL - text is always white.
« Reply #2 on: January 10, 2009, 11:20:37 am »
Try using RenderWindow::PreserveOpenGLStates.
Laurent Gomila - SFML developer

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
mixing sf::String with OpenGL - text is always white.
« Reply #3 on: January 10, 2009, 12:44:10 pm »
can't see any changes, it's still white.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
mixing sf::String with OpenGL - text is always white.
« Reply #4 on: January 10, 2009, 01:00:12 pm »
Can you show us a minimal and complete example which reproduces the problem?
Laurent Gomila - SFML developer

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
mixing sf::String with OpenGL - text is always white.
« Reply #5 on: January 12, 2011, 11:22:52 pm »
I apologize for bumping this old thread ... but I was having a similar problem. I didn't find a solution on the forum so I experimented some more and found a solution (at least in my case). I found that I have to add
Code: [Select]
glDisable(GL_LIGHTING);
before drawing the sf::String
And, of course, enable lighting again when I redraw my scene.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
mixing sf::String with OpenGL - text is always white.
« Reply #6 on: January 13, 2011, 07:29:25 am »
Even with RenderWindow::PreserveOpenGLStates? It should take care of disabling lightning.
Laurent Gomila - SFML developer

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
mixing sf::String with OpenGL - text is always white.
« Reply #7 on: January 15, 2011, 02:34:21 am »
:oops: my bad... PreserveOpenGLStates took care of my problem, also. I had the notion that it would slow things down a lot and that the previous poster couldn't get it to work in his case.

 :oops: my bad #2... using PreserveOpenGLStates revealed another problem in my code - I had neglected to explicitly turn on blending and sfml was doing that for me, so I didn't notice.

Well, now my code is better - PreserveOpenGLStates doesn't affect anything so I know I have everything tightened up.
I'm enjoying working with sfml. The more I learn, the better it gets!  :D

 

anything