vktrbhm
vktrbhm

Reputation: 35

Segmentation fault when creating VertexArray

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;
}

Upvotes: 0

Views: 289

Answers (1)

genpfault
genpfault

Reputation: 52167

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.

Upvotes: 3

Related Questions