-1

I have been advised against using immediate calls in opengl so I am trying to move over to vertex arrays. Whenever I run my program I get this error when it tries to read glBindVertexArray: "Unhandled exception at 0x7540CB49 in TestOpenGL.exe: 0xC0000005: Access violation executing location 0x00000000."

Why is it giving me this error?

WhyYouNoWork
  • 273
  • 5
  • 18
  • 2
    you didn't get the proc-address for it. windows only binds the gl 1.1 functions for you you have to do the rest yourself or lat a library do it for you – ratchet freak Dec 23 '14 at 01:53
  • @ratchetfreak I don't understand. What do I have to do to fix it? – WhyYouNoWork Dec 23 '14 at 02:40
  • 2
    @WhyYouNoWork You need to load the OpenGL functions for the version of OpenGL you wish to use (in your case, at least 3.0). See https://www.opengl.org/wiki/Load_OpenGL_Functions. This is most easily accomplished using a library such as GLEW: http://glew.sourceforge.net/. – RA. Dec 23 '14 at 05:05
  • @RA. How do I know what version of Opengl I have or can use? I did include the glew library. If I didn;t it would appear in the shortcuts in visual studio. – WhyYouNoWork Dec 23 '14 at 05:46
  • 2
    @WhyYouNoWork: Have you initialized GLEW? Pointers are only set after the call to glewInit(). The available OpenGL version depends on your graphiccard. You can check the supported version e.g. with [this tool (OpenGL Extension Viewer)](http://www.realtech-vr.com/glview/) – BDL Dec 23 '14 at 09:58
  • 1
    @WhyYouNoWork: Also glewInit must be called *after* the OpenGL context has been created. If you call it before that, it won't do anything. – datenwolf Dec 23 '14 at 10:12
  • @BDL I downloaded that program you sent me a link to. It says I have version 3.1 of opengl. Also I copied the code from the opengl site to check glewinit and it says it failed. Why would that happen? (This is the link) https://www.opengl.org/wiki/OpenGL_Loading_Library#GLEW_.28OpenGL_Extension_Wrangler.29 – WhyYouNoWork Dec 23 '14 at 15:39
  • @datenwolf where would I call glewInit? – WhyYouNoWork Dec 23 '14 at 15:40
  • @WhyYouNoWork: After the OpenGL context has been created. It depends on the way you create your OpenGL window, when that happend. If using GLUT, GLFW or SDL the OpenGL context is available after the window has been created. If you program directly against the OS APIs, then after the OpenGL context "make current" function has been called. – datenwolf Dec 23 '14 at 17:31
  • @datenwolf moving my check below the window did fix it. Thank you! It no longer crashes, but it doesn't seem to draw my vertex array. Do you know any good tutorials or have any suggestions so I can use/understand them better? – WhyYouNoWork Dec 23 '14 at 18:39
  • @WhyYouNoWork: I suggest you work yourself through http://arcsynthesis.org/gltut – vertex buffer objects are essential to modern OpenGL so they get covered pretty early on in that tutorial. – datenwolf Dec 23 '14 at 18:41
  • @datenwolf Thank you. I will read through it now. If you would like make your comment about moving the glewinit below the window into an answer and I will approve it. – WhyYouNoWork Dec 23 '14 at 23:33

1 Answers1

1

glewInit must be called after the OpenGL context has been created. If you call it before that, it won't do anything. It depends on the way you create your OpenGL window, when that happend. If using GLUT, GLFW or SDL the OpenGL context is available after the window has been created. If you program directly against the OS APIs, then after the OpenGL context "make current" function has been called.

datenwolf
  • 159,371
  • 13
  • 185
  • 298