SFML community forums
Help => Graphics => Topic started 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:
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
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();
}
-
Any solutions?
-
Try using RenderWindow::PreserveOpenGLStates.
-
can't see any changes, it's still white.
-
Can you show us a minimal and complete example which reproduces the problem?
-
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
glDisable(GL_LIGHTING);
before drawing the sf::String
And, of course, enable lighting again when I redraw my scene.
-
Even with RenderWindow::PreserveOpenGLStates? It should take care of disabling lightning.
-
: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