PDA

View Full Version : glDrawArrays works, while glDrawElements fails. Why?



Mango Man
08-28-2014, 02:34 AM
Here is a code sample of what I mean: https://github.com/nucleartide/grapes/blob/master/main.cpp

This is the result of using glDrawArrays:

http://i.imgur.com/0yI4kFX.png

And this is the result of using glDrawElements:

http://i.imgur.com/H6gYP2q.png

In the code, window.DrawElements just calls glDrawElements with some default values. Most OpenGL objects are abstracted away into C++ classes; I don't think there are any problems in my classes, since glDrawArrays works perfectly.

What the heck is going on? For what it's worth, here's my glxinfo:


$ optirun glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GT 750M/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 331.38
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.4.0 NVIDIA 331.38
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:

Thanks in advance. :)

carsten neumann
08-28-2014, 04:06 AM
Have you run this under a debugger to figure out where it crashes?
On possibility I can see after skimming the wrapper classes is that I don't think you have a VAO bound at the time you bind the index buffer, so there is not source for index data stored in the VAO. Can you post a trace of the OpenGL calls issued (e.g. using apitrace (http://apitrace.github.io/))?

Mango Man
08-28-2014, 07:42 AM
Ah, that must be it - the VAO isn't bound. I'll post a trace after work tonight.

Mango Man
08-28-2014, 06:21 PM
Have you run this under a debugger to figure out where it crashes?
On possibility I can see after skimming the wrapper classes is that I don't think you have a VAO bound at the time you bind the index buffer, so there is not source for index data stored in the VAO. Can you post a trace of the OpenGL calls issued (e.g. using apitrace (http://apitrace.github.io/))?

It worked! I got confused since setting GL_ARRAY_BUFFER doesn't require a bound VAO. Thanks so much. :D