A small tip for getting all glFunctions...

Started by
1 comment, last by Wytter 18 years, 8 months ago
Greetings all, After messing a bit with one of my new projects (is going to end up as an OpenGL screensaver) I felt like creating a loader for an OpenGL library that'd make sure that all functions are available to the programmer. Now, I really didn't want to write all of the PFNGL... glWhatever(GLsomething)=SDL_GL_GetProcAddress("glWhatever"); by hand, so I started playing a bit with the preprocessor. I figured that by putting all of the functions from gl.h and glext.h to a single file inside macro statements it'd be possible to handle all external declarations, set the initial function pointer to NULL and to get it's real address using SDL_GL_GetProcAddress(). Here's the gl_loader.h that I'm using as a wrapper: gl_loader.h This will create function pointers named as sglFunction (with an s in front of all function names). The functions marked as NEEDED are the ones that I require in my application, while the ones marked as OPTIONAL are not required. I didn't get the time go through all functions and mark them as either NEEDED or OPTIONAL yet though, but it's a planned feature. You can find gl_functions.h here: gl_functions.h Whenever a new function is added to gl.h and glext.h it will have to be added to gl_functions.h as well. Here's the relevant files where I get the function pointers: extensions.cpp extensions.hpp generic.hpp errors.hpp errors.cpp The extensions.[c,h]pp will also get the supported extensions from the GL_EXTENSIONS string and check them as either supported or not supported in the GL_Extensions :: supported_extensions[]. To query whether an extension is supported or not, you'll have to use the lowercase name of the extension (not as pretty sadly, could also make it just use the string name, but that'd hog some ressources if I ever need to do a query in the renderer). It seemed like a fairly clean way of doing this, but do you know of an even better way? Don't mind the horrible C++, I'm just learning it :) /Wytter
Nemo enim fere saltat sobrius, nisi forte insanit.
Advertisement
Very cool. But you do realize that there are libraries like GLEW that will do this for you?
Yes, I'm just somewhat reluctant to add more library dependencies, when it's something that can be done this easily :)

Furthermore I learned more ways to "abuse" the preprocessor, and it has given me some tools that I'll definately use in the future - just wanted to share it with everyone else here.
Nemo enim fere saltat sobrius, nisi forte insanit.

This topic is closed to new replies.

Advertisement