Jump to content
  • Advertisement
Sign in to follow this  
Wytter

OpenGL A small tip for getting all glFunctions...

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!