Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GLEW mandatory for an up-to-date OpenGL application?

I've been reading on the gl.h header file included with my version of Visual Studio and it seems heavily outdated.

I do not want GLUT or any other middleware/utility library in between to do the dirty work for me, that includes GLEW. Could someone elaborate on why and how does one acquire/query for the modern feature set of the 4.0 specification and what's the idea behind GLEW in general?

like image 795
Fractal Resurgence Avatar asked May 20 '12 03:05

Fractal Resurgence


2 Answers

The gl.h shipping with MSVC++ covers only the functions exported by the opengl32.dll shipping with Windows. This DLL is mostly only a so called "trampoline" into the actual driver. But it only exports a very old version of OpenGL, namely OpenGL-1.1.

Any functionality beyond that must be accessed through the extension mechanism.

I do not want GLUT or any other middleware/utility library in between to do the dirty work for me, that includes GLEW.

GLUT is completely unrelated to GLEW

Could someone elaborate on why and how does one acquire/query for the modern feature set of the 4.0 specification and what's the idea behind GLEW in general?

You aquire the modern feature set through the already mentioned extension system.

There is a function ?glGetProcAddress (exact name depending on the OS environment, in Windows wglGetProcAddress). Using this function you retrieve function pointers to the procedures of extensions for the current OpenGL context (in GLX the function pointers are the same for all contexts, but in Windows they may differ).

Loading a extension goes about this:

typedef (*OGLEXTP_SOMEEXTENSIONFUNCTION)(...)
OGLEXTP_SOMEEXTENSIONFUNCTION oglextp_glSomeExtensionFunction = NULL;
#define glSomeExtensionFunction oglextp_glSomeExtensionFunction;


struct Extensions
{
    bool SomeExtensionFunction;
}

errorcode initGLExtensions(){
    Extensions available;

    GLubyte extensions = glGetStrings(GL_EXTENSIONS);
    parse_extension_string(extensions, available);

    if( available.SomeExtensionFunction ) {
        oglextp_glSomeExtensionFunction = wglGwtProcAddress("glSomeExtensionFunction");
        if( !oglextp_glSomeExtensionFunction )
             return errorcode;
    }
}

And you have to write the bulk code of this for each and every function. Nobody wants to write this. So the developers of GLEW came up with a set of scripts, that fetch the extension specifications from opengl.org and automatically create the whole extension loading and wrap this into a small library, that creates no additional dependencies.

If you want to use higher OpenGL functionality: Use GLEW. Not because it's mandatory, but because it's the most straightforward way to go about this.

like image 146
datenwolf Avatar answered Nov 12 '22 06:11

datenwolf


Don't be afraid of GLEW. First, I've actually seen GLEW used in Nvidia OpenGL SDK examples. It's obviously a reliable tool with a friendly license. Second, you can statically link the library and vaporize it as a dependency. (Personally, I just add the source code to my project and #define GLEW_STATIC to make it work.)

like image 34
TheBuzzSaw Avatar answered Nov 12 '22 06:11

TheBuzzSaw