Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Cannot draw 2D elements with modern OpenGL  (Read 2569 times)

0 Members and 1 Guest are viewing this topic.

eglomer

  • Newbie
  • *
  • Posts: 13
    • View Profile
Cannot draw 2D elements with modern OpenGL
« 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!!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Cannot draw 2D elements with modern OpenGL
« Reply #1 on: June 04, 2015, 09:52:48 pm »
Please provide a minimal complete example. Remove all the code (e.g. shaders) that's not required to reproduce the problem.

And read the documentation about resetGlStates() once more.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Cannot draw 2D elements with modern OpenGL
« Reply #2 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...

eglomer

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Cannot draw 2D elements with modern OpenGL
« Reply #3 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!


binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Cannot draw 2D elements with modern OpenGL
« Reply #4 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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything