# glShadeModel(GL\_FLAT) causing access violation using glad.h and not glew.h

**URL:** https://discourse.glfw.org/t/glshademodel-gl-flat-causing-access-violation-using-glad-h-and-not-glew-h/874
**Category:** support
**Created:** [March 10, 2017, 7:28pm UTC](https://discourse.glfw.org/t/glshademodel-gl-flat-causing-access-violation-using-glad-h-and-not-glew-h/874 "2017-03-10T19:28:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![efpkop](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@efpkop](https://discourse.glfw.org/u/efpkop)
#### Post date: [March 10, 2017, 7:28pm UTC](https://discourse.glfw.org/t/glshademodel-gl-flat-causing-access-violation-using-glad-h-and-not-glew-h/874/1 "2017-03-10T19:28:20Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)
#### Post date: [March 10, 2017, 7:41pm UTC](https://discourse.glfw.org/t/glshademodel-gl-flat-causing-access-violation-using-glad-h-and-not-glew-h/874/2 "2017-03-10T19:41:44Z")

</div>

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](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](https://github.com/Dav1dde/glad/blob/master/README.md#cc)

---

<div class="post-metadata">

### Author: ![efpkop](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@efpkop](https://discourse.glfw.org/u/efpkop)
#### Post date: [March 10, 2017, 9:02pm UTC](https://discourse.glfw.org/t/glshademodel-gl-flat-causing-access-violation-using-glad-h-and-not-glew-h/874/3 "2017-03-10T21:02:20Z")

</div>

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.
