14

I am trying to learn how to program in opengl and am using this tutorial. Tutorial 1 works fine, tutorial 2 crashes with return 1.

It fails on this:

GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);

Specifically:

glGenVertexArrays(1, &VertexArrayID);

Any suggestions? Also related but never solved OpenGL, FreeGlut and Glew crash with glGenVertexArrays call

Community
  • 1
  • 1
asbumste
  • 451
  • 3
  • 12

3 Answers3

19

After reading this thread it appears that calling

glewExperimental = GL_TRUE; 
glewInit();

Would fix the problem. Reading up on glewExperiemental here, it says that

GLEW obtains information on the supported extensions from the graphics driver. Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed.

I'm not too sure how that helps with glGenVertexArrays, but it's worth the try

Community
  • 1
  • 1
emartel
  • 7,712
  • 1
  • 30
  • 58
  • 2
    Wow, GLEW's rhetoric is worthy of a politician. Basically, GLEW doesn't really support core profile OpenGL contexts, even though we've had them for 3 years now. They have this hack in there, which they use to switch whatever prevents them from doing what [other GL loaders](http://www.opengl.org/wiki/OpenGL_Loading_Library) do just fine without an explicit switch. Personally, I'd say that you should stop using GLEW, since they haven't been able to get their act together on this for years. – Nicol Bolas Nov 26 '12 at 04:14
  • Thanks, this worked. If GLEW is going to be this bad, I might not even use it. – asbumste Nov 26 '12 at 22:45
  • Thanks for the quick fix. Now I'm off to rip glew out of my project. – 3Dave Dec 13 '13 at 21:15
1

Update your glew to 2.0.0. This was caused by this bug.

dfelinto
  • 111
  • 1
0

Using OpenGL 4.3 on an nvidia GPU and GLEW this trick still works.

i was able to use this fix to get the 'Our First Program: A Detailed Discussion' from the 8th edition 4.3 Chapter 1 to run.

commenting out

glewExperimental = GL_TRUE; 

results in an unhandled exception, so i'm fairly certain this is the issue. add it back into the code and the program runs as expected.

Updating answer to clarify what is new from original answer:

[1] Notice the date on the original answer was over two years old so i validated this is still true in newer versions of OpenGL. A major issue with OpenGL sample code on the web is the aging of tutorial content that might still work but is not considered a best practice or most performant path. When I read the original answer my thoughts were:

'Well, but this is two years old...is GLEW still not updated and this answer is out of date?', so now the reader will know as of Sept 13, 2014 it is in fact true.

[2] I would expect many readers trying to make the very simple first example in the OpenGL Programmer's Guide to run and it will not without this fix. By including the name of the book I hope they turn up this answer in a web search.

[3] I specified the platform I am certain this works to clarify I did not test it on all platforms.

atlake
  • 51
  • 3
  • 2
    How is this different from the accepted answer? If you wish to add details you may edit the answer and expand upon it. Or you could leave a comment asking for clarification or offering new insights. – EWit Sep 13 '14 at 20:23
  • if you notice the data on the original answer was over two years old so i validated this is still true in newer versions of OpenGL. – atlake Oct 01 '14 at 15:47
  • Thank you for verifying it. However, a comment or edit on the accepted answer would have sufficed, not every visitor scrolls down to read all answers, so the odds are that your verification is missed by many. – EWit Oct 01 '14 at 16:32