CS312 Lab 4: Shader-based OpenGL
- Copy the directory ex1/ from ~dxu/handouts/cs312/glcode to your own directory. Compile and run. This is a simple program that draws the 2D Sierpinski Gasket with points. Please study carefully. Things to note:
- initshader.c implements the helper functions that read in, compile and link the shaders.
- example1_*.glsl are the vertex and fragment shaders
- Install necessary libraries to get OpenGL 3.2 or above running on your own platform (or use our labs!)
- Write the following programs to start familiarizing yourself with the shader-based OpenGL
- Write a program to display a colored triangle (still in 2D with default projection)
![](1.png)
- Modify the program to display a 3D triangle with all three vertices having different colors. Note that you will need a separate color buffer (or interleave your vertex buffer). Stay with default ortho projection. Add more triangles to your scene. Add an object to give some depth cue (if your triangle is parallel to x-y, then an intersecting triangle parallel to z, for example).
![](3.png)
![](4.png)
- Modify the program further to add keyboard controls to translate, rotate and scale the objects (you will need to write your own equivalent glTranslate, glRotate and glScale).
- If you get this far, then you are ready to convert your hw2 to the new OpenGL. Do.
- Now convert your lab3 (solid cube intersecting tetrahedron) to VAOs and VBOs
- Now add your own camera movement functions. Most people simply implement their own gluLookAt, however, if you always hated gluLookAt and wanted a different way to handle the camera, now it's your chance. Remember that all of this still only affects the modelview matrix, if you are staying with the legacy OpenGL separation of matrices.
- Continue with supplying a projection matrix and get perspective projection to work.
- Now you are ready to convert hw3.