Loading extensions from scratch, win32 & OpenGL

Hi all,
Inspite of all advices I’m trying to load opengl function-pointers. I’m using code::blocks and mingw and added
#include <wglext.h>
#include <glext.h>

to a functioning opengl-template for a start. I’ve parsed the extensions-string and found ONE wgl-function: wgl-swapinterval. The entrance to other wgl-functions are supposed to be extracted from the extension wglGetExtensionsStringARB, but this extension is not exposed in the 242 available extensions that I have parsed from ‘the other’ extension-string [glGetString(GL_EXTENSIONS)]. So I’ve made a shot in the dark writing:

wglGetExtensionsStringARB =(PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress(“wglGetExtensionsStringARB”);

after getting a current rendercontext.
The *wglGetExtensionsStringARB is not NULL, but I don’t know how to take it from here. If it’s supposed to be a string right away, it doesn’t respon like it in
Should the functionpointer be ‘instantiated’ further [as say freeglut key- & mouse-function pointers are ‘instantiated’ in main() ] ?

I’m armed with “Open Superbible 5”, “OpenGL Programming Guide”, “OpenGL ES 2.0” and the web … none of them go much further than their own frameworks. If someone has a good link, I would be greatful. I’m currently scrutinizing

wglGetExtensionsStringARB is a function pointer. After initializing the pointer to the correct address, you simply call the function (“dereference” the pointer) by adding parentheses and expected arguments:

// declare funtion pointer

// initialize function pointer to the address returned by wglGetProcAddress
wglGetExtensionsStringARB =(PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");

// call the function 

AFAIK wglGetExtensionsStringARB() itself should return a string (char*) containing space-separated extension names. You use this string to check if wanted extension is supported and then proceed to attain function pointers pertaining to that extension. You get the pointers same way you’ve got wglGetExtensionsStringARB pointer, by calling wglGetProcAddress.

It’s much easier to use glew though.

Hi nenad*,
When adding this line in code
wglGetExtensionsStringARB() ;
I get the error that wglGetExtensionsStringARB() is not a function.
I think that I already tried something like this
char *txt = wglGetExtensionsStringARB() ;
and got the same error.

I just tested this:
wglGetExtensionsStringARB =(PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress(“wglGetExtensionsStringARB”);

if( wglGetExtensionsStringARB != NULL ){
printf("wglGetExtensionsStringARB sucessful?
") ;
// printf(wglGetExtensionsStringARB);
const char *txt = wglGetExtensionsStringARB() ; -> error-provoking code
printf( txt ) ;
printf("wglGetExtensionsStringARB erroneous?
") ;
and get the error: called object is not a function.
But my previous test is in accordance with your suggestion, and the usage I found online “OpenGL SuperBible”:


so something might be very wrong.

I do use GLEW & GLFW, but I got to read Notices & Copyrights and was left with worries that I would have to offer my source-code in the open as a consequence. Having the profound problems of loading myself I’ve been back at the Notices … I think that I’m off the hook as to presenting my sources. I don’t mind about the binary (it’s supposed to be a gift to the world ;o).
Frankly, I don’t think that I survive loading myself …

Right. I think this is because you mistakenly declared wglGetExtensionsStringARB as a pointer to pointer. The type PFNWGLGETEXTENSIONSSTRINGARBPROC is already a pointer type (note the PFN prefix, meaning: pointer to function).

So instead:

the declaration should lose the asterisk and look like:

Try this out for start and see if the thing compiles.

Hi nenad;

Well seen! Yes, it compiles but now complains on “too few arguments” for function wglGetExtensionsStringARB().
I added the device-context, hDC as argument. The compiler warning is that function expected ‘HDC’ but argument is of type ‘struct HDC__
It runs but the output-string contains nothing.
In accordance to this:
I stuffed in the current render context, and an eqvivalent compiler warning appears:
expected ‘HDC’ but argument is of type 'struct HGLRC__

still nothing in the output-string.

If I look back: I just reinstalled the opengl-driver named something like ‘320…’ . It’s an older one from 2008. The version I can querry is 3.3 ok. Still the wglGetExtensionsStringARB may be younger than 2008? As mentioned the wglGetExtensionsStringARB does not appear in the extension-string [glGetString(GL_EXTENSIONS)].
I choose the older version to omit the concomitant mega-install of some ‘windows framework 4.0’. The errors could conform to this …?
The wglext.h and glext.h are newly copy/pasted from the opengl registry.

You’re passing the context handle in (which is of type HGLRC), use the same HDC you used to create the context.

rc = wglCreateContext(dc);
extensions = wglGetExtensionsStringARB(dc);

Here’s the extension specification: http://www.opengl.org/registry/specs/ARB/wgl_extensions_string.txt

Hi Dan,

I tried both the device-context and the render-context. Both gives a compiler warning (as described above), but compile. The output is an empty string.
I added the function
const char *wglGetExtensionsStringARB(HDC hdc);
to the top of my .cpp. It did not change anything.

The link to the specs you provided (thanks) says
“If there are no extensions then the empty string is returned.”
… !?

I’ve tried to follow the instructions on how to ‘do-opengl-yourself’ … that implies starting out with a dummy context, use it for getting the wglChoosePixelFormatARB and then build another proper context.
I just checked that I do get opengl 3.3 and the equivalent shader-version. Doesn’t that mean that I can use all the buffer options and neglect the fixed-function stuff?
I’m new and not sophisticated in my needs … I think that these abilities suffice (for now). After all … there are 242 other extensions to use [or what?].
I’ve got a GLEW/GLFW project running ok (using a core profile), so unless GLEW does magic, I’m supposed to be able to too?

I had a look at the opengl-extensionViewer.
It detects 267 extensions. The discrepency to the 242 I find [one WGL] is 25 … and there are 27 WGL-functions found.
wglGetExtensionsStringARB is not one of them, but another eqvivalent: WGL_EXT_extensions_string.
Is this part of another Microsoft-go-hide-and-seek game?

Could you tell us what precisely is that you want to do? What functionality do you need for your application?

Couldn’t the pixel format be set simply via win32 funcion ChoosePixelFormat()?

Hi nenad,

Ok, I’ve copy/pasted some of my functional code into the program. First task is compiling a shader

vertShader = glCreateShader(GL_VERTEX_SHADER);

GL_VERTEX_SHADER is not recognized.

If I should try to probe for
can I assume that the type would be
PFN_WGLEXTENSIONSSTRING_PROC – without the underscores?

[after programming-excesses my web-tv only shows half a movie in bites, but I get to see those bites twice, so I prefer to ask rather than reinstall driver]

Since you’re going the extension route shouldn’t that be:


You’ll of course need to check if ARB_vertex_shader extension is supported and obtain the pointer to glCreateShaderObjectARB() via wglGetProcAddress()

Thanks nenad,
I think that I’ve got the gist!
Enough to work with for a while.