glShadeModel(GL_FLAT) causing access violation using glad.h and not glew.h


#1

I’m trying to add some basic rendering settings to some of my code, such as
glShadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

But, when I run it, I get an access violation. As an example, if I take the Boing example program in the GLFW distribution and simply add the line

 glShadeModel(GL_FLAT); 

after the glfwMakeContextCurrent(window); line, I get the error:

Exception thrown at 0x0000000000000000 in GLFW_boing.exe: 0xC0000005: Access violation executing location 0x0000000000000000.

I’m pretty certain the error is related to the fact that I am trying to replace my use of glew.h with glad.h in my code.

Is there another command I need to issue before implementing any of these rendering settings when using glad?


#2

This sounds like glShadeModel function pointer is NULL. Have you initialized glad after GL context is created?

See the GLFW example for more details: https://github.com/Dav1dde/glad/blob/master/example/c%2B%2B/hellowindow2.cpp#L62

Here’s the documentation on it: https://github.com/Dav1dde/glad/blob/master/README.md#cc


#3

That was it. Thanks @mmozeiko!

For others looking at this, just had to add the following lines after creating my window and making the context ‘current’:

	if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
	{
		std::cout << "Failed to initialize OpenGL context" << std::endl;
		return -1;
	}

Then I was able to call the regular render settings.