January 2019
Intermediate to advanced
384 pages
11h 50m
English
This class implements a widget for rendering OpenGL graphics. It is very simple to use as it has an interface similar to that of QWidget. We can choose between the familiar QPainter class or standard OpenGL rendering commands for drawing, as seen in the following example:
class TestOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions{public: TestOpenGLWidget(QWidget* parent = nullptr); void initializeGL() override; void resizeGL(int w, int h) override; void paintGL() override; { // use OpenGL 1.0 functions to draw a triangle: // - doesn't use GLSL shaders! glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex3f(-0.5, -0.5, 0); ... } ...};
We implement our painting ...
Read now
Unlock full access