Hello, I’m using OpenGL with C++ code.
I made a class for the OpenGL context, and all renders correctly when I use it.
However if I try to define a context as a global variable (initialized before main is reached), I get blank window but no error (via glGetError or GetLastError).
This is the constructor:
context::context( HDC hDC ){
m_handle = wglCreateContext( hDC );
//error checking here
wglMakeCurrent( hDC, m_handle )
//more error checking here
//set gl function pointers with wglGetProcAddress here (requires context to be current)
}
Changing the constructor to this solves the problem for using a global context:
context::context( HDC hDC ){
m_handle = wglCreateContext( hDC );
//error checking here
}
This is unsatisfying, as the function pointers need to be initialized later, and if any calls happens in between I would get memory violation.
I checked if the global context was set correctly in the first case, by calling wglGetCurrentContext and wglGetCurrentDC after wglMakeCurrent, and the values I got matched the handles of my context and my DC.
Also disabling the current context, and reenabling it after main has been reached still wouldn’t change the problem. Yet wglMakeCurrent sets the handles correctly still.
I can also use a context that has been created after main locally, even if the global context is not functionning. This suggests me that wglMakeCurrent causes an unreported problem if used in a static initialization.
I would like to know if there is a way to make it function, or report this problem somehow.
Thanks in advance.