2
\$\begingroup\$

I'm using GLEW 1.13.0, (GLUT), SDL2 and OpenGL 3.3 core.

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

int main(int argc, char* args[]){
  Engine::init(); // Initializes SDL_GL_* attributes

  glutInit(&argc, args); // Don't know if needed
  glewExperimental = GL_TRUE;
  glewInit();

  WINDOW["main"] = new Window("Test", {800, 600}, false, true);

  GLfloat vertices[] ={
    -0.5f, -0.5f, 0.0f,
    0.5f, -0.5f, 0.0f,
    0.0f, 0.5f, 0.0f
  };
  GLuint VBO[1];
  glGenBuffers(1, VBO); // Here my program crashes as glGenBuffers is NULL
  glBindBuffer(GL_ARRAY_BUFFER, VBO[0]);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

  ...
}
\$\endgroup\$
2
  • \$\begingroup\$ Are you verifying glutInit/glewInit works properly and what version of opengl it is initializing? \$\endgroup\$
    – Elva
    May 23, 2016 at 14:35
  • \$\begingroup\$ @KevinvanderVelden Glew is returning "Missing GL version", how can I tell it which version to load? \$\endgroup\$
    – Xriuk
    May 23, 2016 at 14:46

1 Answer 1

2
\$\begingroup\$

As far as I know, you must initialize GLEW after creating GL context. Which means, after creating a window.


If it wont work, please post an entire code of Engine::init().

\$\endgroup\$
2
  • \$\begingroup\$ Ok, this works. And what if later destroy the context and create a new one, will GLEW be fine? \$\endgroup\$
    – Xriuk
    May 23, 2016 at 15:55
  • 1
    \$\begingroup\$ It may or may not work depending on your system. Thus, you should re-init it for each new context. \$\endgroup\$ May 23, 2016 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .