Does QtQuick 2 support glBindBuffer?
-
21-12-2019 - |
Question
it seems i cannot use glBindBuffer, glGenBuffer in the inherited-class of QQuickPaintedItem.
I already try to include , but it doesn't work and I also try to use GLEW in QQuickPaintedItem. It looks like Qt would undefined those functions in QQuickPaintedItem.
My Qt version is 5.1 msvc-opengl and the system operates on win7 desktop.
compiler msg:
fcglpanel.cpp(254): error C3861: 'glBindBuffer': identifier not found
some code
class MyQuickGLPanel :public QQuickPaintedItem
{
Q_OBJECT
//-------------------------------------------------------------------------
public:
FCGLPanel(QQuickItem * parent=0);
~FCGLPanel();
virtual void paint(QPainter * painter);
...
}
main
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
}
}
}
UPDATE
List some way to avoid this issue in Window platform.
Retrieve the entry point of OpenGL via
QOpenGLFunctions* oglEntry = window()->openglContext()->functions();
Use customized context creation in your 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
Solution
Qt tries to wrap a lot of OpenGL functionality into a single class that contains all of the (extended) shared functions between GL and GL ES 2.0, called QGLFunctions
.
Rather than using GLEW, you should consider QGLFunctions::glBindBuffer (...)
. If you call QGLFunctions::initializeGLFunctions (...)
it does a lot of the same things as GLEW.
In fact, you would probably go ahead and inherit this class so that any call to glBindBuffer (...)
is automatically handled through inheritance of QGLFunctions
.
The following description is taken from the Qt SDK documentation for QGLFunctions
:
QGLFunctions provides a guaranteed API that is available on all OpenGL systems and takes care of function resolution on systems that need it. The recommended way to use QGLFunctions is by direct inheritance:
class MyGLWidget : public QGLWidget, protected QGLFunctions
{
Q_OBJECT
public:
MyGLWidget(QWidget *parent = 0) : QGLWidget(parent) {}
protected:
void initializeGL();
void paintGL();
};
void MyGLWidget::initializeGL()
{
initializeGLFunctions();
}