New version page

Basic Graphics Programming

Upgrade to remove ads

This preview shows page 1-2-3-18-19-36-37-38 out of 38 pages.

Save
View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

January 16, 2003Frank PfenningCarnegie Mellon Universityhttp://www.cs.cmu.edu/~fp/courses/graphics/Graphics PipelineOpenGL APIPrimitives: Lines, PolygonsAttributes: ColorExample[Angel Ch. 2]Graphics PipelineOpenGL APIPrimitives: Lines, PolygonsAttributes: ColorExample[Angel Ch. 2]Basic Graphics ProgrammingBasic Graphics Programming15-462 Computer Graphics ILecture 201/16/2003 15-462 Graphics I 2A Graphics PipelineA Graphics Pipeline• Pipelines and parallelism• Latency vs throughput• Efficiently implementable in hardware• Not so efficiently implementable in software01/16/2003 15-462 Graphics I 3Programming a PipelineProgramming a Pipeline• Specify the operation of each box• Replace or accumulate• State and lack of modularity• Immediate mode graphics– On-line (OpenGL)• Modeling-rendering pipeline– Off-line (Pixar’s Renderman)01/16/2003 15-462 Graphics I 4VerticesVertices• Vertices in world coordinates• void glVertex3f(GLfloat x, GLfloat y, GLfloat z)– Vertex (x, y, z) sent down the pipeline– Function call returns• Use GLtype for portability and consistency• glVertex{234}{sfid}[v](TYPE coords)01/16/2003 15-462 Graphics I 5TransformerTransformer• Transformer in world coordinates• Must be set before object is drawn!• Complex [Angel Ch. 4]glRotatef(45.0, 0.0, 0.0, -1.0);glVertex2f(1.0, 0.0);01/16/2003 15-462 Graphics I 6ClipperClipper• Mostly automatic from viewport01/16/2003 15-462 Graphics I 7ProjectorProjector• Complex transformation [Angel Ch. 5]OrthographicPerspective01/16/2003 15-462 Graphics I 8RasterizerRasterizer• Interesting algorithms [Angel Ch. 7]• To window coordinates01/16/2003 15-462 Graphics I 9OutlineOutline1. A Graphics Pipeline2. The OpenGL API3. Primitives: vertices, lines, polygons4. Attributes: color5. Example: drawing a shaded triangle01/16/2003 15-462 Graphics I 10OpenGL Library OrganizationOpenGL Library Organization• GLU (OpenGL Utility Library), modeling• GLUT (GL Utility Toolkit), window system interface01/16/2003 15-462 Graphics I 11Graphics FunctionsGraphics Functions• Primitive functions• Attribute functions• Transformation functions• Viewing functions• Input functions• Control functions01/16/2003 15-462 Graphics I 12OutlineOutline1. A Graphics Pipeline2. The OpenGL API3. Primitives: vertices, lines, polygons4. Attributes: color5. Example: drawing a shaded triangle01/16/2003 15-462 Graphics I 13PrimitivesPrimitives• Specified via vertices• General schema• type determines interpretation of verticesglBegin(type);glVertex*(...);...glVertex*(...);glEnd();01/16/2003 15-462 Graphics I 14Example: Square OutlineExample: Square Outline• Type GL_LINE_LOOP• z coordinate defaults to 0• Calls to other functions are allowed between glBegin(type) and glEnd();glBegin(GL_LINE_LOOP);glVertex2f(0.0, 0.0);glVertex2f(1.0, 0.0);glVertex2f(1.0, 1.0);glVertex2f(0.0, 1.0);glEnd();01/16/2003 15-462 Graphics I 15Points and Line SegmentsPoints and Line Segments• Make sense in three dimensions01/16/2003 15-462 Graphics I 16PolygonsPolygons• Polygons enclose an area• Rendering of area (fill) depends on attributes• All vertices must be in one plane01/16/2003 15-462 Graphics I 17Polygon RestrictionsPolygon Restrictions• OpenGL Polygons must be simple• OpenGL Polygons must be convex(a) simple, but not convex(b) non-simpleconvex01/16/2003 15-462 Graphics I 18Why Polygon Restrictions?Why Polygon Restrictions?• Non-convex and non-simple polygons are expensive to process and render• Convexity and simplicity is expensive to test• Behavior of OpenGL implementation on disallowed polygons is “undefined”• Some tools in GLU for decomposing complex polygons (tessellation)• Triangles are most efficient01/16/2003 15-462 Graphics I 19Polygon StripsPolygon Strips• Efficiency in space and time• Reduces visual artefacts• Polygons have a front and a back, possibly with different attributes!01/16/2003 15-462 Graphics I 20OutlineOutline1. A Graphics Pipeline2. The OpenGL API3. Primitives: vertices, lines, polygons4. Attributes: color5. Example: drawing a shaded triangle01/16/2003 15-462 Graphics I 21AttributesAttributes• Part of the state of the graphics pipeline• Set before primitives are drawn• Remain in effect!• Examples:– Color, including transparency– Reflection properties– Shading properties01/16/2003 15-462 Graphics I 22Physics of ColorPhysics of Color• Electromagnetic radiation• Can see only tiny piece of the spectrum01/16/2003 15-462 Graphics I 23Color FiltersColor Filters• Eye can perceive only 3 basic colors• Computer screens designed accordinglyBG RAmplitude01/16/2003 15-462 Graphics I 24Color SpacesColor Spaces• RGB (Red, Green, Blue)– Convenient for display– Can be unintuitive (3 floats in OpenGL)• HSV (Hue, Saturation, Value)– Hue: what color– Saturation: how far away from gray– Value: how bright• Others for movies and printing01/16/2003 15-462 Graphics I 25RGB vs HSVRGB vs HSVRRBGGBVSHRGBApple Color Picker01/16/2003 15-462 Graphics I 26OutlineOutline1. A Graphics Pipeline2. The OpenGL API3. Primitives: vertices, lines, polygons4. Attributes: color5. Example: drawing a shaded triangle01/16/2003 15-462 Graphics I 27Example: Drawing a shaded polygonExample: Drawing a shaded polygon• Initialization: the “main” functionint main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100);glutCreateWindow (argv[0]);init ();...01/16/2003 15-462 Graphics I 28GLUT CallbacksGLUT Callbacks• Window system independent interaction• glutMainLoop processes events...glutDisplayFunc(display); glutReshapeFunc(reshape);glutKeyboardFunc (keyboard);glutMainLoop();return 0;}01/16/2003 15-462 Graphics I 29Initializing AttributesInitializing Attributes• Separate in “init” functionvoid init(void) {glClearColor (0.0, 0.0, 0.0, 0.0);/* glShadeModel (GL_FLAT); */glShadeModel (GL_SMOOTH);}01/16/2003 15-462 Graphics I 30The Display CallbackThe Display Callback• Handles exposure events• Install with glutDisplayFunc(display)void display(void){glClear (GL_COLOR_BUFFER_BIT); /* clear buffer */triangle (); /* draw triangle */glFlush (); /* force display */}01/16/2003 15-462 Graphics I 31DrawingDrawing• In world coordinates; remember state!void triangle(void){glBegin (GL_TRIANGLES);glColor3f (1.0, 0.0, 0.0); /* red */glVertex2f (5.0, 5.0);glColor3f (0.0, 1.0, 0.0);


Download Basic Graphics Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Basic Graphics Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Basic Graphics Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?