Rendering 2D shapes
Since we have already learned how to draw our first rectangle on the screen, we will further enhance it in this section. We will take the previous example and continue from there.
How to do it…
- First, go to the
paintGL()
function inmainwindow.cpp
and replace the quad in the previous example with new code. This time, we draw a quad together with a triangle:void MainWindow::paintGL() { // Initialize clear color (cornflower blue) glClearColor(0.39f, 0.58f, 0.93f, 1.f); // Clear color buffer glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_QUADS); glVertex2f(-0.5f, -0.5f); glVertex2f(0.5f, -0.5f); glVertex2f(0.5f, 0.5f); glVertex2f(-0.5f, 0.5f); glEnd(); glBegin(GL_QUADS); glColor3f(1.f, 0.f, 0.f); glVertex2f(-0.8f, -0.8f); glColor3f(1.f, 1.f, 0.f); glVertex2f(0.3f, -0.8f); glColor3f(0.f, 1.f, 0.f); glVertex2f(0.3f, 0.3f); glColor3f(0.f, 0.f, 1.f); glVertex2f(-0.8f, 0.3f); glEnd(); glBegin(GL_TRIANGLES); glColor3f(1.f, 0.f...