OpenGL 1.X functions and gl3.h

How-to bind OpenGL 1.0 and 1.1 functions in the new OpenGL 3.2 context (core profile) on Windows when using the gl3.h header

For OpenGL 3 and above it is a good practice to use the new gl3.h header which does not include any deprecated functions from older OpenGL versions.

If you replace your gl.h (and maybe also the glext.h) header with the new gl3.h file the first thing you may notice is that the fundamental functions like glGetError() are not ready to use.

You could define GL3_PROTOTYPES but maybe that is not what you want to do because Windows’s opengl32.dll does not provide the necessary implementations for all the functions defined in gl3.h’s #ifdef GL3_PROTOTYPES […] #endif blocks. In fact Windows’s native OpenGL implementation only contains implementations for OpenGL 1.0 and 1.1 since Microsoft left the Khronos Group.

So instead of defining GL3_PROTOTYPES one has to use the function pointers provided below each #ifdef GL3_PROTOTYPES […] #endif block.

But the 1.0 and 1.1 functions declared in gl3.h cannot be bound via wglGetProcAddress()! Instead one has to load the opengl32.dll and then bind the functions via GetProcAddress():

HMODULE handle = NULL;

PROC getGlAddr(string procedure)
  PROC address= wglGetProcAddress(procedure.c_str());
  if (!address)
    address= GetProcAddress(handle, procedure.c_str());

  return address;

handle= LoadLibraryA("opengl32.dll");

glGetError= (PFNGLGETERRORPROC) getGlAddr("glGetError");

Dieser Beitrag wurde unter IT abgelegt und mit , , , , , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.