QtQuick 2是否支持glBindBuffer?

时间:2014-04-11 18:42:21

标签: opengl opengl-es-2.0 qt5 qtquick2

似乎我不能在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平台中避免此问题的方法。

  1. 通过

    检索OpenGL的入口点

    QOpenGLFunctions * oglEntry = window() - &gt; openglContext() - &gt; functions();

  2. 在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();
      ....
    }
    

    REF

    http://www.kdab.com/opengl-in-qt-5-1-part-1/

    Difference in opengl speed between Qt 4/5 and Opengl API

1 个答案:

答案 0 :(得分:2)

Qt尝试将大量OpenGL功能包装到一个类中,该类包含GL和GL ES 2.0之间的所有(扩展)共享函数,称为QGLFunctions

您应该考虑QGLFunctions::glBindBuffer (...),而不是使用GLEW。如果您致电QGLFunctions::initializeGLFunctions (...),则会执行与GLEW相同的 批次

事实上,您可能会继续继承此类,以便通过继承glBindBuffer (...)自动处理对QGLFunctions的任何调用。


以下描述摘自QGLFunctions的Qt SDK文档:

  

QGLFunctions 提供了一个保证 API,可在所有OpenGL系统上使用,并负责在需要它的系统上进行功能解析。使用QGLFunctions的推荐方法是直接继承:

class MyGLWidget : public QGLWidget, protected QGLFunctions
{
  Q_OBJECT
public:
  MyGLWidget(QWidget *parent = 0) : QGLWidget(parent) {}

protected:
  void initializeGL();
  void paintGL();
};

void MyGLWidget::initializeGL()
{
  initializeGLFunctions();
}
相关问题