conflict with OpenGL

Started by Sagittarius, 01 February 2015, 15:31:00

Sagittarius

Hey, have a bit of an urgent problem while trying to use TGUI(0.6.6.2 for VS 2010) in a program that already uses SFML 2.2 for window\opengl_context\input.

First i initialize TGUI:
tgui::Gui mainGui;
...
mainGui.setWindow(mainWindow);
mainGui.setGlobalFont("Calibri.ttf");


i have mainGui.handleEvent(currentEvent); and mainGui.draw(); in my main loop;

It compiles and runs fine.
But as soon as i create picture like this:

tgui::Picture::Ptr dashboard_bg(mainGui, "dashboard_bg");
dashboard_bg->load("dashboard_bg.tga");
dashboard_bg->setSize(600, 100);


It breaks my OpenGL render. Causing it to crash on glBindVertexArray or glDrawElements. According to gDebugger, the vertex array i use is not valid when i pass it to glBindVertexArray , although it is allocated after i setup gui create picture. Is this for reals(i dunno, maybe you expect me to use SFML's classes instead of proper OpenGL :)) or is this a bug\my misunderstanding of how TGUI works?

P.S. commenting out mainGui.draw() doesn't stop the problem; it's the creation of gui object that cuases it.

texus

TGUI just uses the graphics module from SFML for everything it draws, there should be nothing that TGUI influences that SFML doesn't do already (except perhaps clipping, but the way I implemented it should not give problems).

So could it be that you are not saving and restoring OpenGL states around the draw calls?
https://www.sfml-dev.org/tutorials/2.2/window-opengl.php#using-opengl-together-with-the-graphics-module

If you are doing that already then you should test if you get the same crash or not when loading and drawing an sf::Texture and sf::Sprite.

Edit: If it is the creating of the widgets then the problem is more serious. But does it work when just creating a sf::Texture instead of loading a widget?

Sagittarius

Thanks, i didn't know that, changed the draw code to:

if(!windowClosed) {
renderScene(); //my render

mainWindow.pushGLStates();

mainGui.draw();
mainWindow.display();

mainWindow.popGLStates();
}


But unfortunately, behavior is the same.

Sagittarius

Yes, it does crash if i put

sf::Texture texture;
if (!texture.loadFromFile("dashboard_bg.tga"))
    return -1;


instead of picture creation code.

texus

Then you should probably create a minimal code that reproduces the error that doesn't use tgui and go ask on the sfml forum. I can't help you with this.