0

I get segmentation fault when I call glGenVertexArrays(). I tryed to set glewExperimental = GL_TRUE but I still get the error. Here is my small code.

#include <GL/glew.h>
#include <GL/gl.h>

#include <iostream>

int main(int argv, char **argc)
{    

   glewExperimental = GL_TRUE;
   glewInit();

   GLuint vao = 0;
   glGenVertexArrays(1, &vao);
   glBindVertexArray(vao);

   std::cout << "WHY?" << std::endl;

   return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
vktrbhm
  • 35
  • 5
  • 1
    Try creating a gl-context and setting it as current before using glew or any gl-command. – Ripi2 Jun 02 '17 at 15:45

1 Answers1

3

You never verify that glewInit() returns GLEW_OK (and it won't because you don't have a current GL context) so glGenVertexArrays() and glBindVertexArray() are both still NULL function pointers.

Calling NULL is bad.

You should also check that the current GL context supports VAOs before using them, either via a GL version check (if(GLEW_VERSION_3_0)...) or extension (if(GLEW_ARB_vertex_array_object)...).

As far as creating a GL context and making it current goes I'd recommend SDL2 or GLFW3.

genpfault
  • 51,148
  • 11
  • 85
  • 139