SFML community forums

Help => Graphics => Topic started by: Ankou on January 06, 2009, 07:46:40 pm

Title: mixing sf::String with OpenGL - text is always white.
Post by: Ankou 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();
}
Title: mixing sf::String with OpenGL - text is always white.
Post by: Ankou on January 10, 2009, 02:57:09 am
Any solutions?
Title: mixing sf::String with OpenGL - text is always white.
Post by: Laurent on January 10, 2009, 11:20:37 am
Try using RenderWindow::PreserveOpenGLStates.
Title: mixing sf::String with OpenGL - text is always white.
Post by: Ankou on January 10, 2009, 12:44:10 pm
can't see any changes, it's still white.
Title: mixing sf::String with OpenGL - text is always white.
Post by: Laurent on January 10, 2009, 01:00:12 pm
Can you show us a minimal and complete example which reproduces the problem?
Title: mixing sf::String with OpenGL - text is always white.
Post by: DoctorJ 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.
Title: mixing sf::String with OpenGL - text is always white.
Post by: Laurent on January 13, 2011, 07:29:25 am
Even with RenderWindow::PreserveOpenGLStates? It should take care of disabling lightning.
Title: mixing sf::String with OpenGL - text is always white.
Post by: DoctorJ 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