Download presentation
Presentation is loading. Please wait.
Published byErnest Patrick Wade Modified over 9 years ago
1
CIS 681 Review: OpenGL
2
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 f for 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)
3
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.
4
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
5
CIS 681 Graphics Pipeline Vertex (x,y,z,w) Modelview Matrix Projection Matrix Perspective Division Viewport Transformation eye coordinates object coordinates clip coordinates normalized device coordinates window coordinates glMatrixMode(GL_PROJECTION) glMatrixMode(GL_MODELVIEW)
6
CIS 681 Transformations glTranslate[fd](x,y,z) glRotate[fd](angle,x,y,z) glScale[fd](x,y,z) glLoadMatrix[fd](TYPE *n) glMultMatrix[fd](TYPE *n) glLoadIdentity(void) glMatrixMode(mode) Viewing transform Modeling transform Projection transform Viewport transform
7
CIS 681 Camera gluLookAt(eyex,eyey,eyez,coix,coiy,coiz,upx,upy,upz
8
CIS 681 Projection - perspective Perspective glFrustum(left,right,bottom,top,near,far) OR gluPerspective(fovy,aspect,zNear,zFar) Orthogonal glOrtho(left,right,bottom,top,near,far) OR gluOrtho2D(left,right,bottom,top)
9
CIS 681 Viewport glViewport(x,y,width,height)
10
CIS 681 Matrix Stack glPushMatrix(void) glPopMatrix(void)
11
CIS 681 Data Vertices glVertex2f(x,y); glVertex3i(i,j,k); Rectangles glRectf(x1,y1,x2,y2); Polygons Data can be specified as 2D or 3D
12
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.
13
CIS 681 Drawing Primitives Value meaning 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
14
CIS 681 Drawing Polygons 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(); 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();
15
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)
16
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);
17
CIS 681 Other Display Topics Display Lists Clipping planes Color Buffers State variables
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.