I am using Qt for a project. It has some QGLWidgets and these work beautifully.
The problem is, I have some legacy code I want to use that uses raw OpenGL commands to do some texture and mesh processing (render meshes to images, etc). I want to call these functions from within my Qt code, but of course that requires that I set up a fresh OpenGL context before I call the OpenGL commands.
I tried to do the following:
QGLContext context(QGLFormat::defaultFormat());
std::cout << "context creation: " << context.create() << std::endl;
if(!context.isValid())
{
std::cout << "Cannot create GL context" << std::endl;
return false;
}
context.makeCurrent();
callLegacyOpenGLCode();
but it doesn't work. QGLContext::create() is returning false. This is on Windows 7 using Qt 4.8, compiled with OpenGL support.
Is this the wrong way to ask Qt to create a new OpenGL context for me? What should I do instead?
For anybody else searching about this issue, @ratchetfreak's suggestion is a good one. The following code works correctly:
QGLWidget tmpwidget;
if(!tmpwidget.isValid())
{
std::cout << "Cannot create GL context" << std::endl;
return false;
}
tmpwidget.makeCurrent();
callLegacyOpenGLCode();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With