OpenGL error (1282) is really annoying

Started by kuso4ek, 01 June 2022, 19:24:54

kuso4ek

Hello, I started working with TGUI recently (SFML, OpenGL3). When I'm not using OpenGL stuff, everything works as expected, but when I'm rendering my 3D OpenGL scene
// OpenGL...
//--------------------
window.pushGLStates();
gui.draw();
window.popGLStates();
in addition to (surprisingly) working gui, I get countless SFML errors
OpenGL error (1282) detected in user code, you should check for errors with glGetError()
in terminal. I'd love to turn off SFML errors, but this, as I understand it, is impossible.
So, how to solve this? I really don't want to leave things as they are.

texus

Are you using sfml-graphics in your project? You should use the SFML_GRAPHICS backend instead of SFML_OPENGL3 in this case.
The SFML_OPENGL3 backend was created in case you just wanted sfml-window with OpenGL but without sfml-graphics.

kuso4ek

Yep, I'm using sfml-graphics. There's the same problem, when using SFML_GRAPHICS backend. So, I think, I need to get rid of sfml-graphics and hope it'll work. Thanks.

texus

Are you using OpenGL in your own code? I think this is a conflict between sfml-graphics and your OpenGL code (maybe you are trying to use OpenGL >= 3 while sfml-graphics uses OpenGL 2.1).

When using the SFML_GRAPHICS backend, TGUI doesn't use OpenGL directly and forwards all drawing calls to sfml-graphics, so it is not possible to get such an OpenGL error unless you are calling OpenGL in your own code (or if there is an incompatibility with the libraries that are linked).

I would suspect that you get the same error if you replace gui.draw() with rendering an sf::Text or sf::Sprite.

kuso4ek

I removed sfml-graphics and now there's no error. Again, without OpenGL everything is alright, but, when rendering OpenGL scene, there's no text. Just empty buttons, labels etc. What could be the problem now?

texus

Can you create a small example project (just a single cpp file) that shows the issue?
Then I'll check if I can reproduce it here and see if I can find why no text is rendered.

kuso4ek

I think I figured something out. Text isn't rendering after I create a cube maps or use shadows. These actions are similar because they use framebuffers. I tried to render GUI to a framebuffer (when the text actually works), and there was the same problem: no text. TGUI doesn't like framebuffers? If it's not true, then it probably depends on the hardware.

texus

QuoteTGUI doesn't like framebuffers?
It's possible. I don't have much experience with OpenGL, so it hasn't really been tested what exactly you need to do to mix TGUI's rendering with your own.

It would be helpful for me if you could create a sample project that uses framebuffers and TGUI, then I can investigate further what has to be changed to make it work.

The only difference that I can think of between rendering images and rendering text, is that the texture used for the text is created on the fly while the ones used for images are created upfront. So maybe something is going wrong with texture creation within the gui.draw call.

kuso4ek

There's a sample.
https://pastebin.com/sMYZr75c // form
https://pastebin.com/VhCqJNyq // vertex shader
https://pastebin.com/tPcPdyLq // fragment shader
https://pastebin.com/NXQ4H3E0 // main
This project uses my own engine. If you have time and will to build it, I can send you a github page.


texus

QuoteThis project uses my own engine. If you have time and will to build it, I can send you a github page.
If you send me a link to the github page then I will build it (or copy the relevant code). I need to know exactly what the Framebuffer class is doing in order to debug this, so I would need to see the source code.


texus

Thanks. I have the code working and can reproduce the problem now.
I will try to find the issue tomorrow.

texus

#13
The error seems to be the GL_DEPTH_TEST capability.

I don't really get why it works without the framebuffer and not with one, but the reason it only renders the button background and not the text is because they both have the same depth and OpenGL only draws the first one. This is why rendering a Label still works, it has nothing behind it.

I will fix this in TGUI later, for now just call the gui.draw() function like this:
Code (cpp) Select
glDisable(GL_DEPTH_TEST);
gui.draw();
glEnable(GL_DEPTH_TEST);

Edit: The latest TGUI 0.10-dev release now handles GL_DEPTH_TEST and you no longer have to disable it yourself with that version.

kuso4ek

I did that and got https://drive.google.com/file/d/1fBEMN2IC5PhOmWFSHoXKbAsgKZD-Wq4t/view?usp=sharing
But, at least, text is here. Moving to my main project. And there's, again, no text. It happens after I create a bunch of PBR stuff (https://github.com/1Kuso4ek1/3Dev/blob/master/3Dev/physics_test.cpp line 63-73) or a shadow manager (line 137). Labels don't work either. Maybe there's an issue with textures?