CS40 Intro

Wednesday | Friday
A couple of minor edits to the qtogl files from last week.
[~]$ cd ~/cs40/examples/w01-intro/qtogl
[qtogl]$ cp ~adanner/public/cs40/examples/w01-intro/qtogl/mypanel* ./
[qtogl]$ cp ~adanner/public/cs40/examples/w01-intro/qtogl/fshader.glsl ./
[qtogl]$ git commit -am "Use QOpenGL classes"
[qtogl]$ git push
[qtogl]$ cd ~/cs40/examples/build/w01-intro/qtogl
[qtogl]$ make -j8
[qtogl]$ ./qtogl
Remember, you could open this in qtcreator too and build the project there. Remember to select qtogl as the target after opening the ~/cs40/examples/CMakeLists.txt project.

QT and OpenGL

The class QGLWidget creates an OpenGL context inside QT. OpenGL functions are called within this context. Additionally, QT has some OpenGL wrapper classes beginning with the prefix QGL.

Creating a QT OpenGL application

We store the vertices of a triangle in a VBO in GPU memory. The next step is to define, create, load, and compile shaders. The vertex shader runs first and takes vertex data from the VBO and outputs geometry in clip coordinates. This geometry is then clipped, rasterized, and fed to the fragment shader which runs on each fragmenet, or potential output pixel. The output of the fragment shader is written to a framebuffer and displayed in the viewport. Once each shader is compiled, we define, create, and link a shader program, which is the combination of a vertex shader and a fragment shader. Finally, we are ready to draw. The main steps are: Once the geometric data are copied to GPU memory, almost everything else happens on the GPU. paintGL is just issuing commands to the GPU. The GPU itself will process those commands.

Shaders, GLSL

Modifying Shaders

Geometry intro
Before we dive into drawing, manipulating, and lighting shapes, we need to know a little bit more about how to represent geometric objects in OpenGL.