OpenGL null function address shenanigans.

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?


Edited by Jesse on
double check the context is properly set up when grabbing the function pointers.
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.

Edited by Jesse on
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 );
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?.

Edited by Jesse 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.

Edited by Mārtiņš Možeiko on
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.
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).
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.

Edited by Jesse on
You use GLEW, GLAD, or something like that
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.

Edited by Jesse on
Ah yeah man i do the same thing, i cant use the drop in solutions either