WglCreateContext on a Qt5 Widget?



  • I want to use my own event loop to process OpenGL, but I still want to use Qt for buttons and most of my interface. I need this kind of precise control it greatly simplifies my code and helps with multithreading and GPU integration.

    Is this possible? Why am I getting the following errors? My understanding is that I can do this with 'foreign windows' but I can't find any documentation?

    @QApplication::regClass: Registering window class 'Qt5QWindowIcon' failed. (Class
    already exists.)
    ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects ow
    ned by a different thread. Current thread 39ca1cd590. Receiver 'qt5nativehandleC
    lass' (of type 'qt5nativehandle') was created in thread 39ca15a1a0", file kernel
    \qcoreapplication.cpp, line 505
    QObject::setParent: Cannot set parent, new parent is in a different thread
    QObject::setParent: Cannot set parent, new parent is in a different thread
    ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects ow
    ned by a different thread. Current thread 39ca15a1a0. Receiver 'centralWidgetWindow' (of type 'QWidgetWindow') was created in thread 39ca1cd590", file kernel\qc
    oreapplication.cpp, line 505@

    The OpenGL context looks something like

    @void qt5nativehandle::startTheGL()
    {
    //Try to get a handle
    g_hWnd = (HWND)ui.wgdMessWith->winId();
    qDebug() << "g_hWnd : " << g_hWnd;
    g_hDC = GetDC(g_hWnd);
    qDebug() << "g_hDC : " << g_hDC;
    //
    int pf = 0;
    // GL Settings
    PIXELFORMATDESCRIPTOR pfd;
    memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 16;
    pfd.cDepthBits = 8;
    pfd.iLayerType = PFD_MAIN_PLANE;
    OSVERSIONINFO osvi = {0};
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osvi);
    pf = ChoosePixelFormat(g_hDC, &pfd);
    SetPixelFormat(g_hDC, pf, &pfd);
    if (osvi.dwMajorVersion > 6 || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 0))
    {
    pfd.dwFlags |= PFD_SUPPORT_COMPOSITION;
    }
    HGLRC tempContext = wglCreateContext(g_hDC);
    qDebug() << "tempContext : " << tempContext;
    wglMakeCurrent(g_hDC, tempContext);
    auto foo = glewInit();
    if (foo != GLEW_OK)
    {
    qDebug() <<"Oh NO!";
    }
    int attribList[] =
    {
    WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
    WGL_CONTEXT_MINOR_VERSION_ARB, 1,
    WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
    0, 0
    };
    //
    g_hRC = wglCreateContextAttribsARB(g_hDC,0, attribList);
    wglMakeCurrent(NULL,NULL);
    wglDeleteContext(tempContext);
    wglMakeCurrent(g_hDC, g_hRC);
    SetWindowText(g_hWnd, L"SLM");
    }@

    I put a complete build-able version on bitbucket if somebody can take a closer look:

    @git clone https://mkandel@bitbucket.org/mkandel/openglqtmixo.git@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.