Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: wglMakeCurrent - The handle is invalid

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    5

    wglMakeCurrent - The handle is invalid

    Hello,

    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:
    Code :
    ...
    if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE)
    ...
    I uploaded the project here if anyone wants to take a look www.uppit.com/tk1gzrwu0hz5/project.zip
    What is a likely cause of this?
    Last edited by scarecr0w132; 12-29-2013 at 06:56 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2004
    Posts
    251
    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?
    Last edited by l_belev; 01-21-2014 at 03:31 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    5
    Quote Originally Posted by l_belev View Post
    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?
    Hello I_belev,

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

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •