Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Where is glGenBuffers in Qt5?

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:


Where is it?

like image 738
Mikhail Avatar asked Jan 14 '23 02:01


2 Answers

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:

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

You need to inherit a protected class QGLFunctions:

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

ALSO, just as GLEW required glewInit() to be called once before you call the OpenGL functions, QGLFunctions requires you to call initializeGLFunctions(). So for example, in QGLWidget, initializeGL() is called once before it starts drawing anything:

void MeGlWindow::initializeGL()

    // ...now you can call your OpenGL functions!
    GLuint myBufferID;
    glGenBuffers(1, &myBufferID);

    // ...

Now you should be able to call glGenBuffers, glBindBuffer, glVertexAttribPointer or whatever openGL function without GLEW.

UPDATE: Certain OpenGL functions like glVertexAttribDivisor and glDrawElementsInstanced do not work with QGLFunctions. This is because QGLFunctions 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 with QOpenGLFunctions_4_3_Core, and initializeGLFunctions() with initializeOpenGLFunctions().

like image 73
bruceoutdoors Avatar answered Jan 18 '23 11:01


Looking at the source for the example you cited:


It has:

#include <QGLFunctions>

Which does have glGenBuffers



Hope that helps!

like image 21
phyatt Avatar answered Jan 18 '23 10:01