A recap of the process for creating an OpenGL application in QT.
Next, fetch upstream changes. If you have committed local changes, merge conflicts should be minimal
[~]$ cd ~/cs40/examples [examples]$ git fetch upstream [examples]$ git merge upstream/master [examples]$ git push
Open up a terminal and navigate to sphere directory in w04-3D. You will be creating a symlink to a folder containing texture map images for this code. You need to do this step before running make in your build directory.
[~]$ cd ~/cs40/examples/w04-3D/sphere [sphere]$ ln -s /usr/local/doc/textures data
In a second terminal, navigate to the build folder and run make -j8 to get the w04-3D folder.
[~]$ cd ~/cs40/examples/build/ [build]$ make -j8 [build]$ cd w04-3D/cube [cube]$ ./cube
vColor as attribute
GL_DEPTH_TEST, GL_DEPTH_BUFFER_BIT
shaders and rotation matrices
In the cube example, we pack the vertex geometry and the vertex colors into a single VBO. See the changes to allocate, and the new write calls to the VBO in createVBO. Note there are some changes in setupVAO to describe the new layout of the VBO. The call
m_shaderProgram->setAttributeBuffer("vColor", GL_FLOAT, m_numVertices*sizeof(point4),4,0);specifies that color information from the VBO should be passed to the vColor input variable in the vertex shader and that the color information appears after the vertex information in the VBO, starting at offset m_numVertices*sizeof(point4).
Note the order of the rotation matrices. When running the demo, is the rotation axis for $\hat{x}$ always fixed with respect to the screen? What about the rotation axis for $\hat{z}$? What is going on?
Enable the depth buffer with
glEnable(GL_DEPTH_TEST);and clear the depth buffer and color buffer with
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);OpenGL computes the depth of a potential fragment and compares it to the value currently in the depth buffer. If the new fragment is in front, we keep the fragment and write this new depth to the depth buffer. Otherwise, the fragment is occluded and discarded.
You can visualize the content of the depth buffer by modifying the fragment shader
void main() { //fragColor = color; float d = 1-gl_FragCoord.z; fragColor = vec4(d,d,d,1); }
Examine the method updatePolyMode and see where it is called. Find out how to change the mode and toggle the various features.
Find out how to toggle the sphere