Let's convert our last program so that it uses shaders. To make the cube better, we will implement a smooth lighting model using the Phong algorithm. At the same time, we will learn to use some helper classes that Qt offers for use with OpenGL.
The basic goals for this mini-project are as follows:
Use vertex and fragment shaders for rendering a complex object
Handle model, view, and projection matrices
Use attribute arrays for faster drawing
Start by creating a new subclass of AbstractGLScene
. Let's give it the following interface:
class ShaderGLScene : public QObject, public AbstractGLScene { Q_OBJECT public: ShaderGLScene(SceneGLWindow *wnd); void initialize(); void paint(); protected: void initializeObjectData(); private: struct ScenePoint { QVector3D coords; QVector3D normal; ScenePoint(const QVector3D &c, const QVector3D &n); }; QOpenGLShaderProgram m_shader; QMatrix4x4 m_modelMatrix; QMatrix4x4 m_viewMatrix; QMatrix4x4...