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


I’m trying to add some basic rendering settings to some of my code, such as

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


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?


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

See the GLFW example for more details:

Here’s the documentation on it:


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.