Handmade Network»Forums
33 posts
OpenGL null function address shenanigans.
Edited by Jesse on
The strangest thing. I reformatted a few days ago, and after I brought back my OpenGL renderer, it crashed on launch. Debugging it revealed that some basic OpenGL functions (like glEnable, glTexImage2D, glGetIntegerv) are not returning their addresses from the video driver, but plenty of others are! It worked fine before I reformatted. Any ideas (Yes, everything is updated)? How did it use to work before reformatting?

511 posts
OpenGL null function address shenanigans.
double check the context is properly set up when grabbing the function pointers.
33 posts
OpenGL null function address shenanigans.
Edited by Jesse on
The context seems OK. Do you have specifics I should look at? I usually have the debug callback installed, but one of the initial functions (glEnable) it relies on isn't getting registered so I don't have that sort of visibility.
Simon Anciaux
1337 posts
OpenGL null function address shenanigans.
Did you try getting the pointers manually ?
1
2
3
4
5
HMODULE hOpenGL = LoadLibrary( "opengl32.dll" );
// GetProcAddress, not wglGetProcAddress
PFNGLENABLEPROC glEnable = ( PFNGLENABLEPROC ) GetProcAddress( hOpenGL, "glEnable" );
...
FreeLibrary( hOpenGL );
33 posts
OpenGL null function address shenanigans.
Edited by Jesse on
Yes, I create function prototypes for all gl functions using a macro. Most gl functions work properly. It's just a few really basic ones aren't getting addresses for some reason. Although I use wglGetProcAddress - might that really play a part?.
Mārtiņš Možeiko
2559 posts / 2 projects
OpenGL null function address shenanigans.
Edited by Mārtiņš Možeiko on
On Windows OpenGL 1.1 functions cannot be loaded with wglGetProcAddress. It will return NULL for them. Instead you need to reference them in OpenGL32.dll - either with linker or manually with GetProcAddress.

Basically easiest way to do is to call wglGetProcAddress first and then GetProcAddress if first one returned NULL.
33 posts
OpenGL null function address shenanigans.
mmozeiko
On Windows OpenGL 1.1 functions cannot be loaded with wglGetProcAddress. It will return NULL for them. Instead you need to reference them in OpenGL32.dll - either with linker or manually with GetProcAddress.

Basically easiest way to do is to call wglGetProcAddress first and then GetProcAddress if first one returned NULL.


Huh, so why was it all working before? My context is 4.0 btw.
Simon Anciaux
1337 posts
OpenGL null function address shenanigans.
I believe if you are not using <GL/gl.h> and you are doing your own declarations (or using glcorearb.h), you need __declspec(dllimport) in your declarations and to link with OpenGL32.lib for those functions to be resolved. Otherwise you need to load them manually. You may be missing a define that enables __declspec(dllimport) or linking with OpenGL32.lib (unlikely or wglCreateContext would not be resolved).
33 posts
OpenGL null function address shenanigans.
Edited by Jesse on
It's fixed now, but my real question is how on earth were any of those functions working without having to do all of that before? It seems impossible.
43 posts / 1 project
OpenGL null function address shenanigans.
You use GLEW, GLAD, or something like that
33 posts
OpenGL null function address shenanigans.
Edited by Jesse on
strangezak
You use GLEW, GLAD, or something like that


My GL renderer is in its own DLL separate from the Platform layer (for hot reloading purposes, which works great!), so those don't work as drop in solutions. I have used them in the past though.

Still, getting this to work was easy. I just don't know how it used to work.
43 posts / 1 project
OpenGL null function address shenanigans.
Ah yeah man i do the same thing, i cant use the drop in solutions either