Have a look at Part 1 if you are new to OpenGL or Qt. In Part 1 I introduced the two technologies and gave some important tips for getting started correctly. If you want to build this project with CMake and Qt Creator, here is a CMakeLists.txt file with instructions on how to do it.
Let’s get started!
This tutorial will show you how to draw a colored triangle similar to the QOpenGLWindow example that ships with Qt but using modern OpenGL. I don’t want to just explain the code, but instead plan on gathering all the little tips and gotchas I have found in order to really help you understand where to go from here. I chose to develop for OpenGL version 3.1 because that is the max my laptop has and for anyone with money and interest to buy a 3D program they probably have that supported by their graphics card in their computer. 3.1 was released on March 24, 2009. Most graphics cards purchased after that will support 3.1. I will try and keep things as close to the existing examples as possible so that you can see exactly what changes when going from straight OpenGL to using Qt. This example will be broken down as follows. Continue reading