1 / 15

OpenGL Tutorial CISC 640/440 Computer Graphics

OpenGL Tutorial CISC 640/440 Computer Graphics. TA: Qi Li/Mani Thomas qili@cis.udel.edu / manivt@cis.udel.edu. OpenGL: What is It?. GL ( G raphics L ibrary): Library of 2-D, 3-D drawing primitives and operations API for 3-D hardware acceleration

salena
Download Presentation

OpenGL Tutorial CISC 640/440 Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas qili@cis.udel.edu/manivt@cis.udel.edu CISC640/440 OpenGL Tutorial

  2. OpenGL: What is It? • GL (Graphics Library): Library of 2-D, 3-D drawing primitives and operations • API for 3-D hardware acceleration • GLU (GL Utilities): Miscellaneous functions dealing with camera set-up and higher-level shape descriptions • GLUT (GL Utility Toolkit): Window-system independent toolkit with numerous utility functions, mostly dealing with user interface CISC640/440 OpenGL Tutorial

  3. GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP OpenGL Geometric Primitives CISC640/440 OpenGL Tutorial

  4. Specifying Geometric Primitives • Primitives are specified using glBegin(primType); ... glEnd(); • primType determines how vertices are combined • GLfloat red, green, blue; • GLfloat x, y; • glBegin(primType); • for (i = 0; i < nVerts; i++) { • glColor3f(red, green, blue); • glVertex2f(x, y); • ... // change coord. values • } • glEnd();

  5. OpenGL Vertex/Color Command Formats glVertex3fv( v ) glColor3fv( v ) Data Type Vector Number of components b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double omit “v” for scalar form– e.g., glVertex2f(x, y) glColor3f(r, g, b) 2 - (x,y) 3 - (x,y,z), (r,g,b) 4 - (x,y,z,w), (r,g,b,a)

  6. OpenGL 3-D coordinates • Right-handed system • From point of view of camera looking out into scene: • +X right, -X left • +Y up, -Y down • +Zbehind camera, -Z in front • Positive rotations are counterclockwise around axis of rotation CISC640/440 OpenGL Tutorial

  7. Transformations in OpenGl • Modeling transformation • Viewing transformation • Projection transformation CISC640/440 OpenGL Tutorial

  8. Modeling Transformation • Refer to the transformation of models (i.e., the scenes, or objects) • Generally, • glMultMatrixf(M_i) • Some simple transformations • Translation: glTranslate(x,y,z) • Scale: glScale(sx,sy,sz) • Rotation: glRotate(theta, x,y,z) • x,y,z are components of vector defining axis of rotation • Angle in degrees; direction is counterclockwise CISC640/440 OpenGL Tutorial

  9. Viewing Transformation • Refer to the transformation on the camera • Using glTranslate*() and glRotate*() • Using gluLookAt() • gluLookAt (eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ) • eye= (eyeX, eyeY, eyeZ)T: Desired camera position • center = (centerX, centerY, centerZ)T: Where camera is looking • up = (upX, upY, upZ)T: Camera’s “up” vector CISC640/440 OpenGL Tutorial

  10. Viewing Transformation from Woo et al CISC640/440 OpenGL Tutorial

  11. Projection Transformation • Refer to the transformation from scene to image • Orthographic projection • glOrtho (left, right, bottom, top, near, far) from Hill CISC640/440 OpenGL Tutorial

  12. Projection Transformation • Refer to the transformation from scene to image • Orthographic projection • glOrtho (left, right, bottom, top, near, far) • Perspective projection • glFrustum (left, right, bottom, top, near, far) CISC640/440 OpenGL Tutorial

  13. Projection Transformation • Refer to the transformation from scene to image • Orthographic projection • glOrtho (left, right, bottom, top, near, far) • Perspective projection • glFrustum (left, right, bottom, top, near, far) CISC640/440 OpenGL Tutorial

  14. Notes on openGl transformations • Before applying modeling or viewing transformations, need to set glMatrixMode(GL_MODELVIEW) • Before applying projection transformations, need to set glMatrixMode(GL_Projection) • Replacement by either following commands glLoadIdentity(); glLoadMatrix(M); • Multiple transformations (either in modeling or viewing) are applied in reverse order CISC640/440 OpenGL Tutorial

  15. Notes on openGl transformations • Before applying modeling or viewing transformations, need to set glMatrixMode(GL_MODELVIEW) • Before applying projection transformations, need to set glMatrixMode(GL_Projection) • Replacement by either following commands glLoadIdentity(); glLoadMatrix(M); • Multiple transformations (either in modeling or viewing) are applied in reverse order CISC640/440 OpenGL Tutorial

More Related