Let's take our rendering code to a higher level. Putting OpenGL code directly into the window
class requires subclassing the window class and makes the window class more and more complex. Let's follow good programming practice and separate rendering code from window code.
Create a new class and call it AbstractGLScene
. It is going to be the base class for definitions of OpenGL scenes. You can derive the class (with protected scope) from QOpenGLFunctions
to make accessing different GL functions easier. Make the scene class accept a pointer to QOpenGLWindow
, either in the constructor or through a dedicated setter method. Make sure the pointer is stored in the class for easier access as we are going to rely on that pointer for accessing physical properties of the window. Add methods for querying the window's OpenGL context. You should end up with code similar to the following:
class AbstractGLScene : protected QOpenGLFunctions { public: AbstractGLScene...