glDrawArrays works, while glDrawElements fails. Why?

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:

And this is the result of using glDrawElements:

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. :slight_smile:

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)?

Ah, that must be it - the VAO isn’t bound. I’ll post a trace after work tonight.

[QUOTE=carsten neumann;1261233]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)?[/QUOTE]

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