SFML community forums

Help => Window => Topic started by: eglomer on June 04, 2015, 09:50:46 pm

Title: Cannot draw 2D elements with modern OpenGL
Post by: eglomer on June 04, 2015, 09:50:46 pm
Hi!

I'm trying to draw some 2D elements mixed with some 3D elements using OpenGL 3.3, but 2D elements never appears in the screen.

I prepared a full example to test this issue:
http://pastebin.com/BvJbK5K9

Some info:
- SFML: I tried it with version 2.1 and 2.3 with the same result.
- OS: Win7 64b (but game is compiled in x86).

Can anybody help me to make this works?

Thanks!!
Title: Re: Cannot draw 2D elements with modern OpenGL
Post by: Nexus on June 04, 2015, 09:52:48 pm
Please provide a minimal complete example (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368). Remove all the code (e.g. shaders) that's not required to reproduce the problem.

And read the documentation about resetGlStates() once more.
Title: Re: Cannot draw 2D elements with modern OpenGL
Post by: SpeCter on June 04, 2015, 10:14:12 pm
Removing shaders would be a pretty bad idea considering he wants to use the 3.3 core profile...
Title: Re: Cannot draw 2D elements with modern OpenGL
Post by: eglomer on June 04, 2015, 11:05:34 pm
Hi Nexus.

I think that this is a very minimal example that fits to my game structure and shows that 2D elements are not appearing in the screen. There are only three functions to draw a 3D triangle and a 2D shape, and one of them is just to compile shaders, so you can ignore it. Furthermore, as SpeCter said, I think that is not a good idea remove shaders using OpenGL 3.3. ;D

And about resetGlStates(), it doesn't matter if you put or not this function; you will get the same result (in this case). I just put it in one of my tests.

Regards!

Title: Re: Cannot draw 2D elements with modern OpenGL
Post by: binary1248 on June 04, 2015, 11:44:13 pm
resetGLStates() only bothers setting states that SFML itself "knows about" which only covers legacy states at the moment (up to circa OpenGL 1.2 + shaders). You will have to manually restore any "modern GL states" to their default values before rendering with SFML's graphics module. In this specific case, you aren't unbinding your VAO or VBO before trying to render with SFML's graphics module, which does not understand/use VAOs/VBOs.