Opengl QtQuick 2是否支持glBindBuffer?

Opengl QtQuick 2是否支持glBindBuffer?,opengl,opengl-es-2.0,qt5,qtquick2,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

似乎我不能在继承的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);
    ...
}
主要


更新

列出在Windows平台中避免此问题的一些方法

  • 通过检索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();
      ....
    }
    
    参考号


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

    <>而不是使用GLW,你应该考虑<代码> qgStult::GLBIdBuffel[..…] 。如果调用
    QGLFunctions::initializeGLFunctions(…)
    ,它会做很多与GLEW相同的事情

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


    以下描述摘自Qt SDK文档: QGLFunctions提供了一个可在所有OpenGL系统上使用的有保证的API,并负责在需要它的系统上进行函数解析。使用QGLF函数的推荐方法是直接继承:

    class MyGLWidget:public QGLWidget,受保护的QGLWidget函数
    {
    Q_对象
    公众:
    MyGLWidget(QWidget*parent=0):QGLWidget(parent){}
    受保护的:
    void initializeGL();
    void paintGL();
    };
    void MyGLWidget::initializeGL()
    {
    initializeGLFunctions();
    }
    
    谢谢,等等。这种方法确实适用于QWidget,但我正在使用基于QtQuick的应用程序。在定制的QQuickPaintedItem中继承QGLFunctions将触发断言。我想这是因为整个QQuickWindow共享相同的OGL上下文。@tirth-借用上下文没有什么错。您可以在QtQuick的“下方”和“上方”进行自定义GL绘制,访问youtube并在QML和GL集成上观看此视频:@tirth:这只是文档中的示例,您可以从任何地方初始化此类的实例。您不必通过继承
    QGLWidget
    的类来继承它,另一个用例是从任何OpenGL上下文中初始化
    QGLFunctions
    对象,然后将所有GL调用限定为
    GL\u functions.glBindBuffer(…)
    。在某些平台上,GL扩展函数特定于某个上下文,因此您可能需要在调用线程中激活一个上下文才能执行此操作-GLX有点奇怪,因为您可以在没有上下文的情况下合法地加载函数指针。@tirth:换句话说,在Windows这样的平台上,您的
    QGLFunctions
    实例只能安全地与初始化时处于活动状态的OpenGL上下文一起使用。在Linux上,您可以对其进行初始化,并将其用于任何上下文。因为这是Qt,您的重点应该是可移植性,所以您应该满足Windows(WGL)而不是Linux(GLX)更严格的要求。答案几乎就在这里:您不能只使用glBindBuffer,因为它不是GL 1.1调用(您在Windows上!)。您必须在运行时解析它。1) 不要使用QGLFunctions,而是使用QOpenGLFunctions(通过QOpenGLContext::functions或类似工具),请参阅。在这种情况下,您有一个QQ2应用程序,而不是基于小部件的应用程序,并且您不想使用OpenGL。2)考虑只使用QOpenGLBuffer来包装缓冲对象。QQuestPrimeTeId应该使用QPrice来绘制。您使用
    glBindBuffer
    做什么?我使用的是某种混合OpenGL绘图,可以通过在渲染前和渲染后连接信号来完成。(因此我有另一个3d绘图功能。)其想法是利用QtQuick ui脚本以及支持一些3d渲染需求。
    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::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();
      ....
    }