170 likes | 243 Views
Review: OpenGL. Command Syntax. OpenGL commands start with a gl . This is followed by the base command such as Color . Followed by the number of arguments such as 3 . Followed by the type of arguments expected, such as f for floats and i for integers
E N D
Review:OpenGL CIS 681
Command Syntax • OpenGL commands start with a gl. • This is followed by the base command such as Color. • Followed by the number of arguments such as 3. • Followed by the type of arguments expected, • such as ffor floats and i for integers • Followed optionally by a v if the arguments are in a vector. • Examples: • glColor3f(1.0,1.0,1.0) • glColor3i(1,1,1) • glColor3iv(vector3i) CIS 681
OpenGL is a STATE MACHINE • Set state variables by various OpenGL commands. • Issue commands that are modified by those state variables. • As opposed to parametric commands. • Able to get values of the state variables, e.g., • glGetFloatv(), glGetIntegerv(). • glGetPolygonStipple(). • Able to enable or disable some state variables, e.g., • glEnable() and glDisable. CIS 681
OpenGL is Event Driven • auxMainLoop() • Program idles in loop until event occurs • Events • Keystroke • Button depression or release • Mouse movement • Window uncovered or reshaped • Callback routines • Setup to be invoked when specific event occurs CIS 681
Graphics Pipeline Vertex (x,y,z,w) eye coordinates Modelview Matrix object coordinates Projection Matrix clip coordinates Perspective Division normalized device coordinates Viewport Transformation glMatrixMode(GL_PROJECTION) glMatrixMode(GL_MODELVIEW) window coordinates CIS 681
Transformations Viewing transform Modeling transform Projection transform Viewport transform glLoadMatrix[fd](TYPE *n) glMultMatrix[fd](TYPE *n) glLoadIdentity(void) glMatrixMode(mode) glTranslate[fd](x,y,z) glRotate[fd](angle,x,y,z) glScale[fd](x,y,z) CIS 681
Camera gluLookAt(eyex,eyey,eyez,coix,coiy,coiz,upx,upy,upz CIS 681
Projection - perspective Orthogonal glOrtho(left,right,bottom,top,near,far) OR gluOrtho2D(left,right,bottom,top) Perspective glFrustum(left,right,bottom,top,near,far) OR gluPerspective(fovy,aspect,zNear,zFar) CIS 681
Viewport glViewport(x,y,width,height) CIS 681
Matrix Stack glPushMatrix(void) glPopMatrix(void) CIS 681
Data • Data can be specified as 2D or 3D • Vertices • glVertex2f(x,y); • glVertex3i(i,j,k); • Rectangles • glRectf(x1,y1,x2,y2); • Polygons CIS 681
Drawing Primitives glBegin(GLenum mode) Marks the beginning of a vertex list that describes a geometric primitive. The type of primitive is indicated by mode glEnd(void) Marks the ending of a vertex list. CIS 681
Drawing Primitives Valuemeaning GL_POINTS individual points GL_LINES pairs of vertices defining individual lines GL_POLYGON list of vertices forming a polygon GL_QUADS four-tuples of vertices def quadrilateral polygons GL_LINE_STRIP vertices defining a series of line segments (open) GL_LINE_LOOP as above, but defining a closed loop GL_TRIANGLE_STRIP linked strip of triangles GL_TRIANGLE_FAN linked fan of triangles GL_QUAD_STRIP linked strip of quadrilaterals CIS 681
Drawing Polygons glBegin(GL_POLYGON); For (i=0, i<n; i++) { angle = i*2*PI/n; x = cos(angle); y = sin(angle); glVertex3f(x,y,1.0); } glEnd(); • glBegin(GL_POLYGON); • glVertex3f(-1.0,1.0,1.0); • glVertex3f(1.0,1.0,1.0); • glVertex3f(1.0,-1.0,1.0); • glVertex3f(-1.0,-1.0,1.0); • glEnd(); CIS 681
Drawing Modes glPolygonMode(GL_FRONT,GL_FILL) glFrontFace(GL_CW) glCullFace(GL_BACK) glEnable(GL_CULL_FACE) Normal3f(-1.0,1.0,1.0) CIS 681
2D SET UP glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(width, height); glutInitWindowPosition(100,100); glutCreateWindow(windowTitle); // open the screen window glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluOrtho2D (0,width,0,height); glViewport(0,0,width,height); CIS 681
Other Display Topics Clipping planes Display Lists Color State variables Buffers CIS 681