Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QT5混合QML和opengl绘图_Qt_Opengl - Fatal编程技术网

QT5混合QML和opengl绘图

QT5混合QML和opengl绘图,qt,opengl,Qt,Opengl,我想混合使用opengl和QML。我用的是qt5beta2。 我为您制作了一个极简方案,向您展示问题: main.ccp #include <QGuiApplication> #include "back.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Back b; b.setSource(QUrl("ui.qml")); b.show(); return

我想混合使用opengl和QML。我用的是qt5beta2。 我为您制作了一个极简方案,向您展示问题:

main.ccp

#include <QGuiApplication>
#include "back.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Back b;
    b.setSource(QUrl("ui.qml"));
    b.show();

    return a.exec();
}
ui.qml

import QtQuick 2.0

Item {
    width : 150
    height : 150

    Rectangle {
         x : 50
         y : 50
         width: 100
         height: 100
         color: "green"
    }
}
第一张图片是正确的: 我有一个红色的正方形和一个绿色的正方形,带有偏移和黑色背景。

3秒后,第二个不正确: 我只有带背景的绿色正方形


有人知道我做错了什么吗?

将旧的OpenglDirectRendering(GlBegin…GlEnd)与使用vbo的Quick item 2.0混合使用不是一个好主意。现在,我使用VBO进行渲染,这是我的工作。你能分享你的简单工作示例吗?代码是免费的,可以在这里看到
#include "back.h"

Back::Back()
{
    setClearBeforeRendering(false);
    connect(this, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()), Qt::DirectConnection);
    timer->start(3000);
}

Back::~Back()
{
}

void Back::paint()
{
    glViewport(0, 0, 150, 150);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 150, 150,0,0,10);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor3ub(255, 0, 0);
    glBegin(GL_QUADS);
        glVertex2i(0, 0);
        glVertex2i(100, 0);
        glVertex2i(100, 100);
        glVertex2i(0, 100);
    glEnd();
}
import QtQuick 2.0

Item {
    width : 150
    height : 150

    Rectangle {
         x : 50
         y : 50
         width: 100
         height: 100
         color: "green"
    }
}