1
Computer Graphics
CSE 167 [Win 17], Lecture 8: OpenGL 2 Ravi Ramamoorthi
http://viscomp.ucsd.edu/classes/cse167/wi17
To Do
§ Continue working on HW 2. Can be difficult § Class lectures, programs primary source § Can leverage many sources (GL(SL) book, excellent
- nline documentation, see links class website)
§ It is a good idea to copy (and modify) relevant segments
Methodology for Lecture
§ Make mytest1 more ambitious § Sequence of steps § Demo
Review of Last Demo
§ Changed floor to all white, added global for teapot and teapotloc, moved geometry to new header file § Demo 0 [set DEMO to 4 all features]
#include <GL/glut.h> //also <GL/glew.h>; <GLUT/glut.h> for Mac OS #include “ “shaders.h” ” #include “ “geometry.h” ” int mouseoldx, mouseoldy ; // For mouse motion GLfloat eyeloc = 2.0 ; // Where to look from; initially 0 -2, 2 GLfloat teapotloc = -0.5 ; // ** NEW ** where the teapot is located GLint animate = 0 ; // ** NEW ** whether to animate or not GLuint vertexshader, fragmentshader, shaderprogram ; // shaders const int DEMO = 0 ; // ** NEW ** To turn on and off features
Outline
§ Review of demo from last lecture § Basic geometry setup for cubes (pillars), colors
§ Single geometric object, but multiple colors for pillars
§ Matrix Stacks and Transforms (draw 4 pillars) § Depth testing (Z-buffering) § Animation (moving teapot) § Texture Mapping (wooden floor)
§ Best source for OpenGL is the red book and GLSL book. Of course, this is more a reference manual than a textbook, and you are better off implementing rather reading end to end.
Geometry Basic Setup 1
const int numobjects = 2 ; // number of objects for buffer const int numperobj = 3 ; const int ncolors = 4 ; GLUint VAOs[numobjects+ncolors], teapotVAO; // VAO (Vertex Array Object) for each primitive object GLuint buffers[numperobj*numobjects+ncolors], teapotbuffers[3] ; // ** NEW ** List of buffers for geometric data GLuint objects[numobjects] ; // ** NEW ** For each object GLenum PrimType[numobjects] ; GLsizei NumElems[numobjects] ; // For the geometry of the teapot std::vector <glm::vec3> teapotVertices; std::vector <glm::vec3> teapotNormals; std::vector <unsigned int> teapotIndices; // To be used as a matrix stack for the modelview. std::vector <glm::mat4> modelviewStack;