Hi, I'm experiencing an issue with OpenGL and SFML. I'm using SFML 2.0 and OpenGL 3.2.
Basically, I'd like to draw an in game GUI that is drawn over the OpenGL context, when OpenGL is not being drawn, my GUI shows fine. However, as soon as I start drawing something (with glDrawElements, the GUI vanishes. I do draw the GUI
after I draw my objects, and I keep UI drawing inside window.pushGLStates() and window.popGLStates();. Here is my game loop:
while (window.isOpen())
{
window.setActive();
sf::Event event;
while (window.pollEvent(event)) // Event loop
{
switch (event.type)
{
// Will send most input to the InputHandler to be processed there after the event has ended
case sf::Event::MouseButtonPressed:
inputHandler.mouseClicked();
break;
case sf::Event::KeyPressed:
inputHandler.keyPressed(event.key.code);
break;
case sf::Event::Closed:
closeGame();
break;
case sf::Event::GainedFocus:
inputHandler.gainedFocus();
break;
case sf::Event::LostFocus:
inputHandler.lostFocus();
break;
case sf::Event::Resized:
inputHandler.windowWasResized = true;
break;
case sf::Event::MouseMoved:
inputHandler.mouseMoved = true;
break;
default:
break;
}
}
if (!closing)
inputHandler.onFrame();
if (renderingGL && !closing)
{
currentCamera->onTick(); // Refresh camera
renderer->render(); // This draws the OpenGL stuff with glDrawElements!
}
window.pushGLStates();
fontRenderer.drawString("Hello World!", 50, 50, 30, 0, 0, 0, &window); // This draws a nice "Hello World" in the corner when OpenGL is not being drawn to. Otherwise, it dissapears.
window.popGLStates();
window.display();
}
I suspect my issue might be because I'm defining the matrices myself and passing to my shaders instead of using glPush/PopMatrix.
If you need more code, just ask.
Thanks,
Jishaxe