260 likes | 413 Views
Lecture 2. Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure. Lecture 2. OpenGL Libraries and Compilation GLUT Window initialization commands Color Drawing 2-D Primitives. OpenGL Libraries.
E N D
Lecture 2 • Review • OpenGL Libraries • Graphics Overview • Rendering Pipeline • OpenGL command structure
Lecture 2 • OpenGL Libraries and Compilation • GLUT Window initialization commands • Color • Drawing 2-D Primitives
OpenGL Libraries • GLUT(OpenGL Utility Toolkit): Implements a simple windowing API for OpenGL. • GLU(OpenGL Utility Library): Set of functions to create textures from base images, drawing quadratic surfaces, etc. • More Details about libraries: • http://www.opengl.org/resources/libraries/
Compilation • Overview: • Compiling • Linking • Running • In Microsoft Visual Studio C++ • http://csf11.acs.uwosh.edu/cs371/visualstudio/ • In MinGW C • http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/
GLUT Window Initialization • What is Buffer? • Clearing the Window • glClearColor(R, G, B, A) • glClearColor(GL_COLOR_BUFFER_BIT) • glClearDepth() • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
GLUT Window Initialization glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Vs. glClear(GL_COLOR_BUFFER_BIT) glClear(GL_DEPTH_BUFFER_BIT)
Color • glColor3f(R, G, B) • glColor3f(0.0, 0.0, 0.0) : Black • glColor3f(1.0, 0.0, 0.0) : Red • glColor3f(0.0, 1.0, 0.0) : Green • glColor3f(0.0, 0.0, 1.0) : Blue
Forcing Completion of Drawing • void glFlush(void) • void glFinish(void)
Structure of an OpenGL code • Sample Code • Reshape Function void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h); }
Point (Vertex) • Mathematical Representation • OpenGL representation • Homogeneous Coordinate System (Optional)
Line • Mathematical Line • Line Segment: Used in OpenGL
Polygon • Mathematical Definitions. • Convex Polygon (Used in OpenGL) • What is the simplest Polygon?
Polygon • Invalid Polygons in OpenGL
Specifying Vertices • OpenGL command: void glVertex{234}{sifd}[v](TYPEcoords); • Example: glVertex2s(2, 3); glVertex3d(0.0, 0.0, 3.1415926535898); glVertex4f(2.3, 1.0, -2.2, 2.0); GLdouble dvect[3] = {5.0, 9.0, 1992.0}; glVertex3dv(dvect);
Specifying Lines, Polygons • Specifying a set of vertices glBegin(GLenum_mode); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(6.0, 1.5); glVertex2f(4.0, 0.0); glEnd();
Stippled Lines • Definition • Command: • glLineStipple(GLint factor, GLushort pattern) • glEnable(GL_LINE_STIPPLE)
Next Session • Interactive Programming with GLUT • Callback Registration • Keyboard, Mouse Callbacks • Animation • Double Buffering