wglMakeCurrent - The handle is invalid

Hello,

[LEFT]I am fairly new to OpenGL, I don’t fully understand everything yet:)
I have a viewer with a context. It is being drawn on the UI which has another separate context. (I am using QT for UI, and trying to draw widgets ontop of viewer.)
wglMakeCurrent() which gets called in the viewer code, fails and says from GetLastError(): wglMakeCurrent() failed. The handle is invalid.
This is how it is called:[/LEFT]

 
...
if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE)
...

I uploaded the project here if anyone wants to take a look Download @ UppIT
What is a likely cause of this?

why don’t you assume the error you get is correct and don’t you check the handles? first find which of the 2 is invalid - try to do something else with them.
for the hdc handle, you can try to call the func GetDeviceCaps. if that fail then tha hdc is the problem. also you can try “WindowFromDC()” - in windows the HDC must belong
to some window to be usable for opengl. you cant use HDC you got from CreateDC (well at least not that easily).
for the hglrc see for example if you call wglDeleteContext instead of wglMakeCurrent, will it fail too. Sorry, I can’t debug your project because my work is more than enough.
Generally learn to debug your own code, especially for elementary problems like this, instead of asking other people to do it for you.

Other things off the top of my head: the hdc must have set pixel format and it must be the same as the one of the hglrc. for the hdc you can use GetPixelFormat().
For the hglrc, i don’t remember a function to ask for this. You may have to check where/how you create it.
I assumed you checked that none of the handles is NULL, did you?

[QUOTE=l_belev;1257395]why don’t you assume the error you get is correct and don’t you check the handles? first find which of the 2 is invalid - try to do something else with them.
for the hdc handle, you can try to call the func GetDeviceCaps. if that fail then tha hdc is the problem. also you can try “WindowFromDC()” - in windows the HDC must belong
to some window to be usable for opengl. you cant use HDC you got from CreateDC (well at least not that easily).
for the hglrc see for example if you call wglDeleteContext instead of wglMakeCurrent, will it fail too. Sorry, I can’t debug your project because my work is more than enough.
Generally learn to debug your own code, especially for elementary problems like this, instead of asking other people to do it for you.

Other things off the top of my head: the hdc must have set pixel format and it must be the same as the one of the hglrc. for the hdc you can use GetPixelFormat().
For the hglrc, i don’t remember a function to ask for this. You may have to check where/how you create it.
I assumed you checked that none of the handles is NULL, did you?[/QUOTE]

Hello I_belev,

Thank you for replying.
I will look into everything you said.

thanks

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.