سؤال

يبدو أنه لا يمكنني استخدام glBindBuffer وglGenBuffer في فئة QQuickPaintedItem الموروثة.

لقد حاولت بالفعل تضمينه، لكنه لا يعمل وأحاول أيضًا استخدام GLEW في QQuickPaintedItem.يبدو أن 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()->openglContext()->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();
      ....
    }
    

    المرجع

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

    الفرق في سرعة opengl بين Qt 4/5 وOpengl API

هل كانت مفيدة؟

المحلول

تحاول Qt تجميع الكثير من وظائف OpenGL في فئة واحدة تحتوي على كافة الوظائف المشتركة (الموسعة) بين GL وGL ES 2.0، والتي تسمى QGLFunctions.

بدلاً من استخدام GLEW، يجب أن تفكر في ذلك QGLFunctions::glBindBuffer (...).إذا اتصلت QGLFunctions::initializeGLFunctions (...) يفعل أ كثير من نفس الأشياء مثل GLEW.

في الواقع، من المحتمل أن تمضي قدمًا وترث هذه الفئة حتى لا يتم الاتصال بها glBindBuffer (...) يتم التعامل معها تلقائيا من خلال الميراث QGLFunctions.


الوصف التالي مأخوذ من وثائق Qt SDK لـ QGLFunctions:

وظائف QGL يوفر أ مضمون واجهة برمجة التطبيقات (API) المتوفرة على جميع أنظمة OpenGL وتهتم بدقة الوظائف على الأنظمة التي تحتاج إليها.الطريقة الموصى بها لاستخدام وظائف QGLF هي الوراثة المباشرة:

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

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

void MyGLWidget::initializeGL()
{
  initializeGLFunctions();
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top