Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.

Similar presentations


Presentation on theme: "Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys."— 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 Graphics PackageApplication OpenGL Application Programming Interface Hardware and software Output 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 Points Lines Polygon Triangle Quad Quad Strip Triangle StripTriangle Fan

8 GLUT 3D Primitives Cube Sphere Teapot And others…

9 Simple OpenGL Program #include 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 Pixel Operations Scan Conversion Texture Memory Fragment Operations Framebuffer Vertices Images

12 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 Viewing in OpenGL

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 –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


Download ppt "Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys."

Similar presentations


Ads by Google