Read over Chapters 2. Don't worry about programming details or the actual Sierpinski Gasket in Chapter 2. Read for concepts and ideas, not code fragments. While the book uses glut
as the windowing environment, we will be using QT
which has similar functionality but completely different syntax.
- Log in
- cd ~/cs40/code
- git branch #(verify you are on a working branch)
verify that any recent changes have been committed to your working branch
git add <file>
switch to the master branch and get changes
git checkout master
git checkout working
git merge master
You should have a Friday.txt
file. This file is silly. You can remove it from version control
git rm Friday.txt
Use git rm
or git mv
to remove/move files under version control.
If you would like to work with a partner, please email me your partner's name.
- open top level CMakeLists.txt project in qtcreator
- set executable to w02-opengl/qtogl
- navigate to w02-opengl/qtogl folder
- open mypanelopengl.cpp
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
- Create a new class, e.g., MyPanelOpenGL which inherits from QGLWidget
- Add a widget in the UI Designer and a promote it to MyPanelOpenGL
- Implement the methods initializeGL(), paintGL() and resizeGL ( int width, int height ) in your MyPanelOpenGL class.
- Add additional methods, slots, signals, widgets as needed.
- MyPanelOpenGL inherits from QGLWidget; provides OpenGL context in QT
- clip coordinates 2x2x2 box
- geomety -> vertex shader -> clip -> rasterize -> fragment shader -> framebuffer
- framebuffer squished into viewport
- Copying CPU data to GPU memory using Vertex Buffer Objects (VBOs)
As of Wednesday, we has three vertices of a triangle sitting 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, and 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:
- clear the display
- bind buffers, programs
- connect shader parameters to data
- repeat as needed using updateGL()
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.
- keywords: in, out, uniform (attribute is deprecated)
- types: vec3, mat4
- variables: gl_Position, gl_FragColor;
- Making gl_FragColor a uniform value
- modifying geometry
- uniform time variable
- updateGL -> Animation!