raghu
raghu

Reputation: 11

QGLWidget::makecurrent(): GetDC() failed. Invalid Window handle

I have a requirement to get pictures saved off screen. I have used QGLwidget::grabframebuffer to get this done. While it works fine on MAC, it fails with an error "QGLWidget::makecurrent(): GetDC() failed. Invalid Window handle " on Windows 7. Only one opengl context gets created in the process. But i have observed that if I add QGLWidget to the Mainwindow, i am able to get the pictures saved. I need not do this on MAC to get the pictures. I am not sure what could have gone wrong.

thanks!!

Upvotes: 1

Views: 1609

Answers (1)

Lightness1024
Lightness1024

Reputation: 76

This is because on MacOS an OpenGL context is always attached to the root window of a multi window application. (this is not seeable with Cocoa, but it was with Agl/Cgl) On windows you can create the context with any window (that has the flag popup, child and one other i forgot) then bind it to any window with MakeCurrent. to expect it to work fine you only need to be sure you have only one thread and one context in your whole app. the spec says otherwise, but in practice it never works. (though you may not see it in a small app, and just see rares random crash)

also, I don't know in QT how the capture of the framebuffer works, with readpixels or with the horrible GDI copy hack, if it is the latest then it is normal that it doesn't work, it can only be done on screen surfaces.

Upvotes: 1

Related Questions