【发布时间】:2014-04-11 18:42:21
【问题描述】:
我好像不能在QQuickPaintedItem的继承类中使用glBindBuffer、glGenBuffer。
我已经尝试包含,但它不起作用,我也尝试在 QQuickPaintedItem 中使用 GLEW。看起来 Qt 会在 QQuickPaintedItem 中取消定义这些函数。
我的Qt版本是5.1 msvc-opengl,系统在win7桌面上运行。
编译器消息:
fcglpanel.cpp(254): error C3861: 'glBindBuffer': identifier not found
一些代码
class MyQuickGLPanel :public QQuickPaintedItem
{
Q_OBJECT
//-------------------------------------------------------------------------
public:
FCGLPanel(QQuickItem * parent=0);
~FCGLPanel();
virtual void paint(QPainter * painter);
...
}
主要
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qmlRegisterType<MyQucikGLPanel>("MyQucikGLPanel", 1, 0, "MyPanel");
QQmlApplicationEngine engine(QUrl::fromLocalFile("../qml/main.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
return qmlMode(argc, argv);
}
main.qml
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
import QtQuick.Window 2.1
import "./MyUI" 1.0 as MyUI
import MyQucikGLPanel 1.0
ApplicationWindow {
id: appwindow
property int zGLPanel : 4;
SplitView {
x: 32
y: 8
anchors.rightMargin: 5
anchors.bottomMargin: 5
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
// [EMBEDDING C++ object]
MyPanel{
id: mylogicPanel
anchors.fill: parent
width: 640
height: 480
z : appwindow.zGLPanel
}
}
}
更新
列出一些在 Window 平台中避免此问题的方法。
-
通过
获取OpenGL的入口点QOpenGLFunctions* oglEntry = window()->openglContext()->functions();
-
在您的 QWindow 中使用自定义上下文创建。
Window::Window( QScreen* screen ) : QWindow( screen ){ // Tell Qt we will use OpenGL for this window setSurfaceType( OpenGLSurface ); // Specify the format and create platform-specific surface QSurfaceFormat format; format.setMajorVersion( 4 ); format.setMinorVersion( 3 ); format.setProfile( QSurfaceFormat::CoreProfile ); setFormat( format ); create(); // Create an OpenGL context m_context = new QOpenGLContext; m_context->setFormat( format ); m_context->create(); .... }参考
【问题讨论】:
-
QQuickPaintedItem 应该使用 QPainter 进行绘制。你用
glBindBuffer做什么? -
我正在使用某种混合的 OpenGL 绘图,可以通过连接信号 beforeRendering 和 afterRendering 来完成。 (所以我有另一个 3d 绘图功能。)这个想法是利用 QtQuick ui 脚本以及支持一些 3d 渲染要求。
标签: opengl opengl-es-2.0 qt5 qtquick2