In my graphics application (https://github.com/ComputerGame/GraphicsApplication/) I use OpenGL calls, vertex buffers and shaders for rendering a scene. Onto that scene I want to draw text using SFML's graphics capabilities. (I use the last SFML 2.0 snapshot and SFML's internaly used GLEW (http://en.sfml-dev.org/forums/index.php?topic=10291.0).)
Since SFML internally uses OpenGL for drawing, I need to store the OpenGL state before, reset it for SFML, and restore it afterwards. I know that there is a function called "RenderTarget::pushGLStates() (https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/RenderTarget.cpp#L241)" which first stores the current OpenGL state and resets it to the SFML defaults. But I figured out that this function isn't enough.
Using just the function mentioned above there is no text displayed even if I comment out the draw calls for the scene. (By the way, font loading is successful.)
// draw scene using OpenGL
// ...
// store the state
window.pushGLStates();
// draw text using SFML
Text text("Hello World", font, 15);
window.draw(text);
// restore the state
window.popGLStates();
// display and swap buffers
// ...
Still not drawing scene objects, added the following calls for resetting the OpenGL state, the text is displayed.
// draw scene using OpenGL
// ...
// store the state
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
window.pushGLStates();
// draw text using SFML
Text text("Hello World", font, 15);
window.draw(text);
// restore the state
window.popGLStates();
// display and swap buffers
// ...
But when I enable the scene drawing again, no text is displayed. What of the OpenGL state do I have to reset by myself for displaying text using SFML? Do I have to care about shader uniforms I set for rendering the scene?
Hi,
I've tried to follow the example but it hasn't been very successful so far.
Briefly, I'm in the same situation where I need to combine at some part of my code real openGL calls with some utility functions of RenderTexture such as polygons, circle everything to get more straightforward source code.
Here's the rendering routine that gets call all the time but only the triangle will get drawn.
BOOL renderSC()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glColor3f(0, 1, 1);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
glPopMatrix();
sf::RenderTexture rt;
rt.create (h, w);
sf::CircleShape shape(100.f);
shape.setFillColor (sf::Color::Green);
rt.pushGLStates ();
rt.draw (shape);
rt.popGLStates ();
glFlush();
return 0;
}
What am I doing wrong here according to you folks?
Cheers!