Don't use a global window's handle to initialize your window DC like shown below. The problem is, WM_CREATE
will be sent before your global variable will be initialized ‒ i.e. before returning from CreateWindowW()
. Thus, the global variable will be NULL
at the moment when window DC is created.
Note that both GetDC()
and wglCreateContext()
will return non-NULL handles. The problem will become apparent on calling wglMakeCurrent()
‒ it will fail with 0xc0070006
, where 6 means "invalid handle".
To deal with this, note that the window procedure has a window handle which you can use. Instead of the global window handle variable, pass the window procedure's hWnd
argument to your OpenGL initialization function.
Code demonstrating the problem:
No comments:
Post a Comment