Rendering 2D shapes
Since we have already learned how to draw our first rectangle on screen, we will further enhance it in this section. We will take the previous example and continue from there.
How to do it…
Let’s get started by following this example:
- Open up
renderwindow.h
and add two more VBOs, one calledvbo_vertices2
and another calledvbo_colors
, as highlighted in the following code:private: QOpenGLContext* openGLContext; QOpenGLFunctions* openGLFunctions; QOpenGLShaderProgram* shaderProgram; QOpenGLVertexArrayObject* vao; QOpenGLBuffer* vbo_vertices; QOpenGLBuffer* vbo_vertices2; QOpenGLBuffer* vbo_colors;
- Open up
renderwindow.cpp
and add the following code to the shader code, as highlighted in the following snippet:static const char *vertexShaderSource...