Question

I am trying to create a window with freeglut and then use glew to create a 3.2 context in order to use modern OpenGL functions (using c++ and a Windows pc). My Problem is that the context creation (which i tried to do both before and after the freeglut init) does not seem to work and I get an Access Violation every time i try to use a function like glCreateShader.

The code I use Looks like this (it is located right at the start of the int main(int argc, char **argv) method):

glutInit(&argc, argv);
glutInitWindowPosition(-1, -1);
glutInitWindowSize(640, 480);
glutInitDisplayMode(GLUT_RGBA || GLUT_DOUBLE || GLUT_DEPTH);

glutCreateWindow("some title");


glewExperimental = GL_TRUE;
GLenum err = glewInit();

 if (GLEW_OK != err)
 {
   fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
 }
 fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
 if (GLEW_VERSION_3_2)
 {
    fprintf(stdout, "OpenGL 3.2 ready", glewGetString(GLEW_VERSION));
 }
...
vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER); //<-- Access Violation

Also, the glew init code is copied 1:1 from their Website. I hope that my mistake is not too obvious and that someone finds the time to help me.

Was it helpful?

Solution

You got a problem there:

glutInitDisplayMode(GLUT_RGBA || GLUT_DOUBLE || GLUT_DEPTH);

Boolean OR || is something different than bit OR |. You want to bit OR bitmasks |, not boolean or them. Apart from that, in this way you will get a OpenGL-3 compatibility profile context, not a core context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top