1 / 18

Computer Graphics (Fall 2003)

Computer Graphics (Fall 2003). COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi. http://www.cs.columbia.edu/~cs4160. Many slides courtesy Greg Humphreys. Introduction to OpenGL. OpenGL is a graphics API Software library Layer between programmer and graphics hardware (and software)

kevinryan
Download Presentation

Computer Graphics (Fall 2003)

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. Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi http://www.cs.columbia.edu/~cs4160 Many slides courtesy Greg Humphreys

  2. Introduction to OpenGL • OpenGL is a graphics API • Software library • Layer between programmer and graphics hardware (and software) • OpenGL can fit in many places • Between application and graphics system • Between higher level API and graphics system

  3. Programmer’s View Application Application Graphics Package OpenGL Application Programming Interface Hardware and software Output Device Input Device Input Device

  4. Why OpenGL? • Fast • Simple • Window system independent • Supports some high-end graphics features • Geometric and pixel processing • Standard, available on many platforms

  5. OpenGL As a Renderer • Renders simple geometric primitives • Points, lines, polygons • Renders images and bitmaps • Separate pipelines for geometry and pixel processing, linked through texture mapping • The output of the renderer depends on state • Current color, light sources, current material, current texture, current normal, etc

  6. OpenGL Buffers • OpenGL supports a variety of buffers that can be used for rendering • Color buffers (front, back, left, right) • Depth buffer (used to store z information) • Accumulation buffer • Stencil buffer • Window system interactions must be handled outside of OpenGL • GLUT • Motif • GLX • Tcl/TK • …

  7. OpenGL Primitives Lines Points Polygon Quad Triangle Quad Strip Triangle Strip Triangle Fan

  8. GLUT 3D Primitives Sphere Cube And others… Teapot

  9. Simple OpenGL Program #include <glut.h> void display(void) { glClearColor( 0, 0, 0, 0 ); glClear( GL_COLOR_BUFFER_BIT ); glColor3f( 1, 1, 1 ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( -1, 1, -1, 1, -1, 1 ); glBegin( GL_POLYGON ); glVertex2f( -.5, -.5 ); glVertex2f( -.5, .5 ); glVertex2f( .5, .5 ); glVertex2f( .5, -.5 ); glEnd(); glFlush();}

  10. Window System Glue int main( int argc, char *argv[] ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize( 250, 250 ); glutCreateWindow( “We love COMS 4160” ); glutDisplayFunc( display ); glutMainLoop();}

  11. OpenGL Rendering Pipeline Geometry Primitive Operations Vertices Scan Conversion Fragment Operations Framebuffer Pixel Operations Texture Memory Images

  12. Viewing in OpenGL • Viewing consists of two parts • Object positioning: model view transformation matrix • View projection: projection transformation matrix • OpenGL supports both perspective and orthographic viewing transformations • OpenGL’s camera is always at the origin, pointing in the –z direction • Transformations move objects relative to the camera

  13. Outline • Introduction (Chapter 1) • Geometry, Drawing (Chapter 2) • Transformations, Viewing (Chapter 3) • Color, Types (Chapter 4) • Lighting (Chapter 5) • Putting it all together… • Textures (Chapter 9) • Display Lists, Vertex Arrays, etc. (Chapter 7) • Advanced Topics, Extensions • Rest of red book should be read…

  14. Introduction (Chapter 1) • Examples (color plates) • Code sample (page 6) • OpenGL as a state machine • OpenGL Rendering pipeline (page 11) • Geometry: Points, lines, polygons, GLUT primitives • Pixels: Images, Bitmaps • Texture Mapping • Depends on state (color, material, texture, etc.) • Animation, Double Buffering • Buffers: Color (front, back); Depth (z); Accumulation; Stencil

  15. Drawing (Chapter 2) • glClearColor(red, green, blue, alpha) [0,0,0,0] • glClear (GL_COLOR_BUFFER_BIT) • Other buffers… • glColor3f (r,g,b) • Draw (assembly line: Transform, clip, shade, …) • Client/Server • glFlush() (forces client to send network packet) • Doesn’t wait for completion; only begins execution • Previous commands execute in finite time • glFinish() (waits for ack that drawing complete) • Synchronization, sparing use

  16. Window System Interaction • Not part of OpenGL • Toolkits (GLUT) available • Callback functions for events • Keyboard, Mouse, etc. • Open, initialize, resize window • Similar to other systems (X, Java, etc.) • Menus, Animation etc. • Typical main function (pp 100)

  17. Geometry • Points (GL_POINTS) • Stored in Homogeneous coordinates • Line segments (GL_LINES) • Polygons • Simple, convex (take your chances with concave) • Tessellate, GLU for complex shapes • Rectangles: glRect • Special cases (strips, loops, triangles, fans, quads) • Pages 44, 45 • More complex primitives (GLUT): Sphere, teapot, cube,…

  18. Specifying Geometry • glBegin(GL_POLYGON) ; // Page 43 • glVertex2f • glVertex2f • glVertex2f • glColor, glIndex, glNormal, glTexCoord, … (pp 47) • glMaterial, glArrayElement, glEvalCoord, … (pp 48) • Other GL commands invalid between begin and end • Can write normal C code… • glEnd() ; • Examples: pp 48,49

More Related