learn opengl with Qt, and it's directory structure is mostly like the origin one.
- download Qt
- install assimp and make sure that the lib path is correct in
learnopengl-qt.pro
bottom lineLIBS += -L$$PWD/thirdparty/assimp_x64-windows/lib/ -lassimp-vc141-mt
- this project is build in
Qt 5.9.9 MSVC2017 64bit
, the compiled library is in./thirdparty/
, make sure*.dll
is in the same path with*.exe
-
open the file
learnopengl-qt.pro
with QtCreator -
run it in debug/release mode
-
select a widget to show
-
create a new class like this
class MultipleLights : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core { Q_OBJECT public: //Q_INVOKABLE is needed Q_INVOKABLE MultipleLights(QWidget *parent = nullptr); ~MultipleLights(); protected: virtual void initializeGL() override; virtual void resizeGL(int w, int h) override; virtual void paintGL() override; private: };
-
inclue it in
MainWindow.h
#include "2.lighting/6.1multiple_lights/MultipleLights.h"
-
add the class name and staticMetaObject to a hashMap in
MainWindow.cpp
void MainWindow::registerMetaObject() { //add staticMetaObject of the new class you have created to a list m_metaObjectList << &MultipleLights::staticMetaObject; //then easily traverse the list and add QMetaObject to map and combox for(const QMetaObject* mo : m_metaObjectList){ m_metaObjectMap.insert(mo->className(), mo); m_combox->addItem(mo->className()); } }
-
glBindFramebuffer(GL_FRAMEBUFFER, 0)
may not work in QOpenGLWidget, because 0 is not QOpenGLWidget's default framebuffer, useglBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject())
instead. Here is my blog -
It seems that Qt does not have UBO(uniform buffer object), thus I made a class called
OpenGLUniformbufferObject
. And, you must pay attention:// wrong class OpenGLUniformbufferObject : public QOpenGLFunctions_3_3_Core { //... glGetActiveUniformBlockiv(m_shaderId, m_uniformBlockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &m_uboSize); } // right class OpenGLUniformbufferObject { //... // get current opengl function QOpenGLFunctions_3_3_Core* m_glFunc = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>(); m_glFunc->glGetActiveUniformBlockiv(m_shaderId, m_uniformBlockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &m_uboSize); }