O'Reilly logo

Game Programming Using Qt by Lorenz Haas, Witold Wysota

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – shaded objects

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required