Create source GL context in Qt?

I am using Qt for a project. It has some QGLWidgets, and they work great.

The problem is that I have some legacy code that I want to use that uses raw OpenGL commands to do some processing of the texture and mesh (rendering grids for images, etc.). I want to call these functions from my Qt code, but of course it requires me to set up a new OpenGL context before I invoke the OpenGL command.

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 that will not work. QGLContext :: create () returns 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?

+4
1

- , , @ratchetfreak . :

QGLWidget tmpwidget;

if(!tmpwidget.isValid())
{
    std::cout << "Cannot create GL context" << std::endl;
    return false;
}

tmpwidget.makeCurrent();
callLegacyOpenGLCode();
+5

Source: https://habr.com/ru/post/1524426/


All Articles