Header for automatic wglGetProcAddress calls?

Hello.

I have learned OpenGL few years ago and now trying to “update” my knowledge, so that I will use only forward-compatible functions from OpenGL 3.0. While I seem to have already understood the basic changes and find them reasonable, I only have only one annoying problem when programming. Since I am programming on Windows I have to use wglGetProcAddress to get a proc address for every function that I have to use. Is there any header file that will automate this for me? In other words I would to replace this:

glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) wglGetProcAddress("glGenVertexArrays");
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC) wglGetProcAddress("glBindVertexArray");
glGenBuffers = (PFNGLGENBUFFERSPROC) wglGetProcAddress("glGenBuffers");
glBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress("glBindBuffer");
glBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress("glBufferData");
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) wglGetProcAddress("glVertexAttribPointer");
glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) wglGetProcAddress("glEnableVertexAttribArray");
glVertexAttrib3f = (PFNGLVERTEXATTRIB3FPROC) wglGetProcAddress("glVertexAttrib3f");
...

with something like that:

#include "someHeader.h"
...
glBindFunctions()

GLEW is one option I’ve used quite successfully in the past: http://glew.sourceforge.net/

I’m not certain how well it interoperates with other libraries such as SDL or GLUT, but it works perfectly fine with native code, and has support for OpenGL 4.1

Thanks for the tip. I was not able to find full documentation on the official web-site. Do I have to create window and initialize context using this library’s functions or is there something like glBindFunctions that I have mentioned before?

The problem is that I would like to have full control over creating context and window and at the same time to avoid using wglGetProcAddress.

Update: I am not using SDL or MFC. I create windows and context using low-level WinAPI and wgl library.
Update 2: This is the code that I am currently running. It is mostly based on some examples that I have found online: http://tinypaste.com/a0774

If you plan to use GLEW, the only thing you have to do after you have set up an appropriate OpenGL context is to call glewInit.

GLEW does not subsumes the context initialization so it should be fine for you. It only does the extension loading, i.e. what you meant by that “glBindFunctions” thing.

I have tried doing as you suggested, but it does not work. Here is my current code: http://tinypaste.com/3cac7. Look at EnableOpenGL() function. This is where I create the context and call glewInit(). The program fails when it tries to call to glGenVertexArrays in function init().

Hmm, strange. It should work.

You should double-check whether OpenGL 3.0 is really supported on your driver and whether you’ve really successfully created a GL3 context.

I know this is extremely late to the party, but I was in the same predicate as you and found out that you have to define the preprocessor GLEW_STATIC and all should build just fine. Hopefully this helps other newcomers who end up here with a similar issue :slight_smile: