Where are glGenBuffers in Qt5?

I can not find the glGenBuffer function in Qt5, my inclusion list looks like

 #include <QtOpenGL/qgl.h> #include <QtOpenGL/qglbuffer.h> #include <QtOpenGL/qglcolormap.h> #include <QtOpenGL/qglframebufferobject.h> #include <QtOpenGL/qglfunctions.h> #include <QtOpenGL/qglpixelbuffer.h> #include <QtOpenGL/qglshaderprogram.h> #include <GL/GLU.h> 

I am trying to do something like the following example:

http://qt-project.org/doc/qt-5.0/qtopengl/cube.html

Where is it?

+4
source share
4 answers

I know I'm late, but here's a more elegant solution (you don't need GLEW =))

in addition to the fact that you have QT += opengl in your * .pro file and that your version of Qt has OpenGL and that you have #include <QGLFunctions> (you do not need all the ones you specified below, only this line) in your header file, you need one more.

So, you have a class that calls all these functions:

 class MeGlWindow : public QGLWidget { // bla bla bla... } 

You need to inherit the protected QGLFunctions class:

 class MeGlWindow : public QGLWidget, protected QGLFunctions // add QGLFunctions { // bla bla bla... } 

ALSO, as soon as GLEW requires glewInit() called once before you call OpenGL functions, QGLFunctions requires you to call initializeGLFunctions() . So, for example, in QGLWidget , initializeGL() is called once before it starts to draw something:

 void MeGlWindow::initializeGL() { initializeGLFunctions(); // ...now you can call your OpenGL functions! GLuint myBufferID; glGenBuffers(1, &myBufferID); // ... } 

You should now be able to call glGenBuffers , glBindBuffer , glVertexAttribPointer or any openGL function without GLEW.

UPDATE : Some OpenGL functions, such as glVertexAttribDivisor and glDrawElementsInstanced , do not work with QGLFunctions . This is because QGLFunctions provides only functions specific to the OpenGL / ES 2.0 API that may not have these functions.

To get around this, you can use QOpenGLFunctions_4_3_Core (or the like), available only with Qt 5.1. Replace QGLFunctions with QOpenGLFunctions_4_3_Core and initializeGLFunctions() with initializeOpenGLFunctions() .

+5
source
+1
source

If you add QT += opengl to your project (.pro) file, you will find that you do not need to specify the folder of each imported header, and you can use #include <QGLFunctions> right off.

The advantage of using QGLFunctions over GLEW is that you are sure that your application can be compiled on any platform and will not depend on where your GLEW libraries are hidden on your system: Qt libraries will do it for you. As @phyatt noted, the Qt Cube example is a good example of how to use this library.

+1
source

I found the answer to my question in the examples folder.

In particular, it was necessary to copy a header called glextensions.h , which functions as GLEW.

I ended up using GLEW.

0
source

All Articles