簡體   English   中英

QT 找不到要使用的正確 OpenGL api

[英]QT can't find right OpenGL api to use

我的基於 QT 5.8 的代碼無法在某些 Windows 機器上運行任何 OpenGl 命令。 似乎找不到正確的渲染 API。
這是終端日志的相關部分。

qt.qpa.gl: QWindowsIntegration::createPlatformOpenGLContext QSurfaceFormat(version 2.0, options QFlagsQSurfaceFormat::FormatOption(), depthBufferSize -1, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile QSurfaceFormat::OpenGLContextProfile(NoProfile))
qt.qpa.gl: Basic wglCreateContext gives version 3.1
qt.qpa.gl: OpenGL 2.0 entry points available
qt.qpa.gl: GPU features: QSet("disable_desktopgl")
qt.qpa.gl: Disabling Desktop GL: GpuDescription(vendorId=0x8086, deviceId=0x102, subSysId=0x2abf103c, revision=9, driver: "igdumd64.dll", version=9.17.10.4459, "Intel(R) HD Graphics")
qt.qpa.gl: QWindowsOpenGLTester::supportedRenderers GpuDescription(vendorId=0x8086, deviceId=0x102, subSysId=0x2abf103c, revision=9, driver: "igdumd64.dll", version=9.17.10.4459, "Intel(R) HD Graphics") renderer: QFlags(0x2|0x4|0x8|0x20)
qt.qpa.gl: Qt: Using EGL from libEGL
qt.qpa.gl: Qt: Using OpenGL ES 2.0 from libGLESv2
qt.qpa.gl: QWindowsEGLStaticContext::create Created EGL display 0x231e2bdc450 v 1 . 4
qt.qpa.gl: QWindowsIntegration::createPlatformOpenGLContext QSurfaceFormat(version 2.0, options QFlagsQSurfaceFormat::FormatOption(), depthBufferSize -1, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize -1, samples 0, swapBehavior QSurfaceFormat::SwapBehavior(DefaultSwapBehavior), swapInterval 1, profile QSurfaceFormat::OpenGLContextProfile(NoProfile))
qt.qpa.windows: QWindowsContext::registerWindowClass "Qt5QWindowOwnDCIcon" style=0x28 brush=0x1100060 icon=true atom=49819
qt.qpa.windows: QWindowsGeometryHint::frame style=0x86cf0000 exStyle=0x0 RECT: left/top=-8,-31 right/bottom=8,8 QMargins(8, 31, 8, 8)
qt.qpa.windows: QWindowCreationContext::QWindowCreationContext QWindow(0x231e53f99d0, name="QOffscreenSurface") QRect(0,0 1x1) pos incl. frame=false frame=17x40+0+0 min=QSize(0, 0) max=QSize(16777215, 16777215) custom margins=QMargins(0, 0, 0, 0)
qt.qpa.windows: CreateWindowEx: QWindow(0x231e53f99d0, name="QOffscreenSurface") class="Qt5QWindowOwnDCIcon" title="MVM_UserInterface"
WindowCreationData: QFlagsQt::WindowType(Window|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowCloseButtonHint)
topLevel=true popup=false dialog=false embedded=false tool=false
style=0x86cf0000 WS_POPUP WS_CLIPSIBLINGS WS_CLIPCHILDREN WS_THICKFRAME WS_DLGFRAME WS_SYSMENU WS_MINIMIZEBOX WS_MAXIMIZEBOX
requested: QRect(0,0 1x1): 17x40+0+0 custom margins: QMargins(0, 0, 0, 0)
qt.qpa.windows: >QWindowsGeometryHint::applyToMinMaxInfo< min=0,0 max=16777215,16777215 in MINMAXINFO maxSize=1696,1066 maxpos=-8,-8 mintrack=136,39 maxtrack=1700,1070
qt.qpa.windows: QWindowsGeometryHint::frame style=0x86cf0000 exStyle=0x0 RECT: left/top=-8,-31 right/bottom=8,8 QMargins(8, 31, 8, 8)
qt.qpa.windows: <QWindowsGeometryHint::applyToMinMaxInfo frame=QMargins(8, 31, 8, 8) 16,39 out MINMAXINFO maxSize=1696,1066 maxpos=-8,-8 mintrack=136,39 maxtrack=1700,1070
qt.qpa.windows: CreateWindowEx: returns QWindow(0x231e53f99d0, name="QOffscreenSurface") 0x40c28 obtained geometry: QRect(8,31 120x1) QMargins(8, 31, 8, 8)
qt.qpa.windows: QWindowsIntegration::createPlatformWindow QWindow(0x231e53f99d0, name="QOffscreenSurface")
Requested: QRect(0,0 1x1) frame incl.=false QFlagsQt::WindowType(Window)
Obtained : QRect(8,31 120x1) margins=QMargins(8, 31, 8, 8) handle=0x40c28 QFlagsQt::WindowType(Window|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowCloseButtonHint)

qt.qpa.mime: QWindowsWindow::setDropSiteEnabled QWindow(0x231e53f99d0, name="QOffscreenSurface") true
qt.qpa.mime: QWindowsOleDropTarget::QWindowsOleDropTarget 0x231e8043430 QWindow(0x231e53f99d0, name="QOffscreenSurface")
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:88 - for glEnable(GL_DEPTH_TEST)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:89 - for glEnable(GL_CULL_FACE)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:93 - for glShadeModel(GL_SMOOTH)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:94 - for glEnable(GL_LIGHTING)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:95 - for glEnable(GL_LIGHT0)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:96 - for glClearColor(0.4, 0.4, 0.4, 1)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:97 - for glEnable(GL_BLEND)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:98 - for glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
OpenGL error 00000502 - GL_INVALID_OPERATION, at C:\Projects\CodeFactory\Src\Apps\MVM_UserInterface\QtGui\MainGlWidget.cpp:99 - for glDepthMask(GL_TRUE)
failed to compile shader: Phong/Phong.frag
ERROR: 0:2: '' : No precision specified for (float)

另外我添加了 mainglwidget.cpp 文件以進行澄清

// MainGlWidget.cpp


#include <QtWidgets>
#include <QtOpenGL>
#include "MainGlWidget.h"
#include "iostream"
#include "Common.h"
#ifdef __APPLE__
#include <unistd.h>
#endif // 


/*#include "Common.h"
#include "UltimateDesign.h"*/

MainGlWidget::MainGlWidget(QWidget *parent)
: QOpenGLWidget(parent)
{
    xRot = 0;
    yRot = 0;
    zRot = 0;

}

MainGlWidget::~MainGlWidget()
{
}

QSize MainGlWidget::minimumSizeHint() const
{
    return QSize(50, 50);
}

QSize MainGlWidget::sizeHint() const
{
    return QSize(400, 400);
}

static void qNormalizeAngle(int &angle)
{
    while (angle < 0)
        angle += 360 * 16;
    while (angle > 360)
        angle -= 360 * 16;
}

void MainGlWidget::setXRotation(int angle)
{
    qNormalizeAngle(angle);
    if (angle != xRot) {
        xRot = angle;
        emit xRotationChanged(angle);

    }
}

void MainGlWidget::setYRotation(int angle)
{
    qNormalizeAngle(angle);
    if (angle != yRot) {
        yRot = angle;
        emit yRotationChanged(angle);
    }
}

void MainGlWidget::setZRotation(int angle)
{
    qNormalizeAngle(angle);
    if (angle != zRot) {
        zRot = angle;
        emit zRotationChanged(angle);
    }
}
void MainGlWidget::importFile(std::string file)
{

    makeCurrent();
    application->importFile(file);
    doneCurrent();

}

void MainGlWidget::initializeGL()
{

    CHECK_GL(glEnable(GL_DEPTH_TEST));
    CHECK_GL(glEnable(GL_CULL_FACE));

   //CHECK_GL(glCullFace(GL_CULL_FACE));
    //glCullFace(GL_BACK);
    CHECK_GL(glShadeModel(GL_SMOOTH));
    CHECK_GL(glEnable(GL_LIGHTING));
    CHECK_GL(glEnable(GL_LIGHT0));
    CHECK_GL(glClearColor(0.4, 0.4, 0.4, 1));
    CHECK_GL(glEnable(GL_BLEND));
    CHECK_GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
    CHECK_GL(glDepthMask(GL_TRUE));
#ifdef WIN32
    //glViewport(0, 0, 1280, 960);
#endif
    application->init((QOpenGLWidget*)this);
    application->setScreenDimentions(width(),height());

#ifdef WIN32
    CreateThread(
        NULL,                   // default security attributes
        0,                      // use default stack size
        timer,       // thread function name
        (void*) this,          // argument to thread function
        0,                      // use default creation flags
        NULL);  // returns the thread identifier
#elif __linux__ || __APPLE__
    pthread_t thread;
    pthread_create(&thread, NULL, timer,    (void*) this);
#endif

}

void MainGlWidget::paintGL()
{
    GLint m_viewport[4];

    glGetIntegerv( GL_VIEWPORT, m_viewport );

    CHECK_GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));



    //std::cout<<"paint "<<pthread_self();


    application->render("cam1");
    //((Geo::Cube*)scene->get("cube2"))->draw();    
}

void MainGlWidget::resizeGL(int width, int height)
{
    std::cout << "width" << width << std::endl;
    std::cout << "height" << height << std::endl;
     size[0] = width;
     size[1] = height;
#ifndef DRONE
    int side = qMin(size[0], size[1]);
    glViewport((size[0]-side)/2,(size[1]-side)/2, side, side);
#endif
    update();
}

void MainGlWidget::mousePressEvent(QMouseEvent *event)
{
    lastPos = event->pos();
    if (event->buttons() & Qt::LeftButton) {
    application->mouseClickWithLeft(lastPos.x(),lastPos.y());
    }else if (event->buttons() & Qt::RightButton) {
        application->mouseClickWithRight(lastPos.x(),lastPos.y());
    }
    //std::cout<<"clicked point 2D x,y"<<lastPos.x()<<","<<lastPos.y()<<std::endl;

}

void MainGlWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();
    lastPos = event->pos();
    if (event->buttons() & Qt::LeftButton) {
        setXRotation(xRot + dy);
        setYRotation(yRot + dx);
        application->mouseDragWithLeft(dx,dy);
    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(xRot + 8 * dy);
        setZRotation(zRot + 8 * dx);
        application->mouseDragWithRight(dx,dy);
    }else if (event->buttons() &Qt::MiddleButton) {
        setXRotation(xRot + 8 * dy);
        setZRotation(zRot + 8 * dx);
        application->mouseDragWithMiddle(dx,dy);
    }





//  float rot[] = { xRot, 0, 0 };
//  float transc[] = { 0, 0, 1 }; 
//  scene->getCamera("cam1")->setTransformation(transc, rot);
//  scene->updated=true;
//    scene->callViews();
}

void MainGlWidget::draw()
{

}
#ifdef WIN32

DWORD WINAPI timer(LPVOID lpParam)
{
    MainGlWidget* glwidget = (MainGlWidget*)lpParam;

    while (true)
    {

        glwidget->update();

        Sleep(10);
    }


}
#elif __linux__ || __APPLE__

void *timer(void *lpParam)
{
    MainGlWidget* glwidget = (MainGlWidget*)lpParam;

    while (true)
    {

        glwidget->update();
        usleep(16000);

    }

}
#endif

看看這幾行:

qt.qpa.gl:GPU 特性:QSet("disable_desktopgl")

qt.qpa.gl: 禁用桌面 GL: GpuDescription(vendorId=0x8086, deviceId=0x102, subSysId=0x2abf103c, revision=9, driver: "igdumd64.dll", version=9.17.10.4459, "Intel(R) HDs" )

它說在此顯卡上禁止桌面 OpenGL,因此創建了 Angle 上下文。 但是你的 OpenGL 代碼不是 GLES 2.0 代碼,所以它不起作用。 您可以通過設置此屬性來覆蓋圖形檢查:

QApplication::setAttribute( Qt::AA_UseDesktopOpenGL );

它應該在創建 QApplication 之前設置。 https://www.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM