I can't seem to find the glGenBuffer
function in Qt5, my include 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?
I know I'm late, but here's a more elegant solution (you don't need GLEW =))
in addition to making sure you have
QT += opengl
in your *.pro file, and that your version of Qt has OpenGL, and that you have#include <QGLFunctions>
(you don't need all of those includes that you listed down above; just this one line) in your header file, you need one more thing.So given you have a class that calls all these functions:
You need to inherit a protected class QGLFunctions:
ALSO, just as GLEW required
glewInit()
to be called once before you call the OpenGL functions,QGLFunctions
requires you to callinitializeGLFunctions()
. So for example, inQGLWidget
,initializeGL()
is called once before it starts drawing anything:Now you should be able to call
glGenBuffers
,glBindBuffer
,glVertexAttribPointer
or whatever openGL function without GLEW.UPDATE: Certain OpenGL functions like
glVertexAttribDivisor
andglDrawElementsInstanced
do not work withQGLFunctions
. This is becauseQGLFunctions
only provides functions specific to OpenGL/ES 2.0 API, which may not have these features.To work around this you could use QOpenGLFunctions_4_3_Core(or similar) which is only available since Qt 5.1. Replace
QGLFunctions
withQOpenGLFunctions_4_3_Core
, andinitializeGLFunctions()
withinitializeOpenGLFunctions()
.I found an answer to my question in the examples folder.
Specifically, it was necessary to copy a header called
glextensions.h
which functions like GLEW.I ended up using GLEW.
If you add
QT += opengl
to your project (.pro) file, you will find that you don't need to specify the folder of each header you're importing, and you will be able to use#include <QGLFunctions>
right away.The advantage of using
QGLFunctions
over GLEW is that you are sure your application can be compiled on any platform and will not depend on where on your system your GLEW libraries are hidden: the Qt libraries will do this for you. As @phyatt pointed out, Qt's Cube example is a good example to see how to use this library.Looking at the source for the example you cited:
http://qt-project.org/doc/qt-5.0/qtopengl/cube-geometryengine-h.html
It has:
Which does have
glGenBuffers
http://qt-project.org/doc/qt-5.0/qtopengl/qglfunctions.html
http://qt-project.org/doc/qt-5.0/qtopengl/qglfunctions.html#glGenBuffers
Hope that helps!