CS 491 Lecture 21 – OpenGL
Before class
A
Before we meet:
- Watch http://youtu.be/LUf2EqaFr5U.
- Read http://developer.android.com/training/graphics/opengl/index.html.
- Read http://www.learnopengles.com/android-lesson-two-ambient-and-diffuse-lighting/. This example is a bit more complicated than the one used in the video.
B
Before we meet:
- Watch http://youtu.be/9zCwq05YDBo.
- Read http://www.learnopengles.com/android-lesson-one-getting-started/.
- Read http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html.
In class
With your partner, build off the base renderer we constructed in class to load in a torus, light it, and shade it. Given the complexity and newness of OpenGL to most of you, I’ve sprinkled TODOs in places where changes need to be made. I suggest you follow these steps:
- Create and start an AVD with GPU emulation on.
- Import the base project, which is very similar to what we wrote in class. It’s zipped up as labgl.zip in the class directory on the W drive.
- The geometry file is in res/raw/torus2.w3d. Look at the file. The vertices start with v. The faces with f. New is a section for normals right after the vertices, each starting with vn. There is a normal defined for each vertex. Read these into a FloatBuffer. The project won’t run until you do this. After reading these in, test.
- Add a projection and look matrix as discussed. Transform the vertices in the vertex shader. Test.
- Add shading using the vertices’ normals. Uploading them will be quite similar to uploading the position attribute. Test.
- Support rotation. Test.