Work / Other Stuff
2011-02-19 23:27:11
Enjoy
A Simple Way To Load OpenGL Extensions
Here is a simple way of loading any OpenGL extensions you may require. I find its best loading only what you actually use, rather than relying on a library like GLEW to do it for you - I feel it adds a bit too much complexity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #ifndef STRINGIFY #define STRINGIFY(x) #x #endif #ifdef WIN32 #include <windows.h> #define glGetProcAddress(a) wglGetProcAddress(a) #endif #ifdef X11 #define glGetProcAddress(a) glXGetProcAddress(reinterpret_cast<const unsigned char*>(a)) #endif #ifndef GetExtension #define GetExtension(Type, ExtenName) \ ExtenName = (Type) glGetProcAddress(STRINGIFY(ExtenName)); \ if(!ExtenName) \ { \ std:cout << "GL extension not supported: " \ << STRINGIFY(ExtenName) << std::endl; \ } \ #endif // example usage GetExtension(PFNGLGENBUFFERSARBPROC, glGenBuffersARB); |