33 posts
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?

498 posts
double check the context is properly set up when grabbing the function pointers.
33 posts
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
1109 posts
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
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
2237 posts / 1 project
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
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
1109 posts
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
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.
Zakary Strange
43 posts / 1 project
A C++ Programmer working on Squad professionally, and Proportion during my free time.
You use GLEW, GLAD, or something like that
33 posts