QT无法找到正确的OpenGL api使用

时间:2017-04-18 09:33:56

标签: c++ qt opengl opengl-es-2.0

我的基于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

1 个答案:

答案 0 :(得分:1)

看这行:

qt.qpa.gl:GPU功能:QSet(“ disable_desktopgl”)

qt.qpa.gl:禁用桌面GL:GpuDescription(vendorId = 0x8086, deviceId = 0x102,subSysId = 0x2abf103c,revision = 9,驱动程序: “ igdumd64.dll”,版本= 9.17.10.4459,“ Intel(R)HD Graphics”)

它表示此图形卡上禁止使用台式机OpenGL,因此创建了Angle上下文。但是您的OpenGL代码不是GLES 2.0代码,因此无法正常工作。 您可以通过设置以下属性来覆盖图形检查:

    result = np.sqrt(
        m ** 2
        + ((reshaped_x - x) / m) ** 2
        + 2 * reshaped_x ** 2
        + 2 * x ** 2
    ) / 2

应在创建QApplication之前进行设置。 https://www.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4