1 / 60

H331: Computer Graphics

H331: Computer Graphics. Philip Dutré Department of Computer Science Wednesday, February 19. Today. Graphics programming Book: Chapters 3, 4, 10. Announcements. Pre-practicum available http://www.cs.kuleuven.ac.be/~graphics/H331/ SIGGRAPH student volunteers!

vince
Télécharger la présentation

H331: 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. H331: Computer Graphics Philip Dutré Department of Computer Science Wednesday, February 19

  2. Today • Graphics programming • Book: Chapters 3, 4, 10

  3. Announcements • Pre-practicum available • http://www.cs.kuleuven.ac.be/~graphics/H331/ • SIGGRAPH student volunteers! • Deadline: Wednesday February 26

  4. Announcements • SIGGRAPH San Diego July 27 – 31 • http://www.siggraph.org/s2003/ • Student volunteers! (Deadline: February 26)

  5. 3D  2D • How to transform the 3D world to a 2D image? • 3 aspects: • Objects: exist in space, independent of viewer • Viewer: camera, human, …. • Lights: shading, shadows, …

  6. 3D  2D Objects (points, lines, polygons) Described by vertices Lights (e-m spectrum) (350-780 nm) Viewer = camera

  7. Pinhole camera

  8. Synthetic Camera Projection plane in front of center-of-projection:

  9. Synthetic Camera Clipping: looking through a window

  10. 3D APIs • Synthetic camera is basis of 3D API • OpenGL, PHIGS, Direct 3D, VRML,JAVA-3D, GKS, … • We need to functions to specify: • Objects: vertices that describe points, lines, polygons • Camera: position, orientation, width, height • Light sources: position, color • Materials: reflection characteristics

  11. 3D APIs glBegin(GL_POLYGON) glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.1); glEnd(); … gluLookAt(posx, posy, posz, atx, aty, atz, …); glPerspective(view_angle, …);

  12. 3D APIs • 3D API performs modeling + rendering • But … modeling can also be done ‘off-line’ • Write model to file • Read file in 3D API and transform to 3D API modeling commands • RenderMan (Pixar) • Prepares off-line model for rendering • Rendering takes ‘converted’ model

  13. Graphics hardware • 3D ‘world’ coordinates  2D ‘screen’ coordinates

  14. Graphics hardware • 3D vertex  2D pixel Transform to camera coordinate system Clip away things we don’t see in the camera window 3D coordinates  2D coordinates Transform to pixels in the frame buffer

  15. 2D Drawing • Little algorithm: • Pick 3 points V0, V1, V2 • P0 = random point • Pk = midpoint between Pk-1 and random(V0, V1, V2) • Plot all Pk

  16. How to draw things? • Given: window on the screen • Graphics API (e.g. OpenGL) has something of the form: plotPixel(int x, int y)

  17. window How to draw things? • plotPixel(289,190) • plotPixel(320,128) • plotPixel(239,67) • plotPixel(194,101) • plotPixel(129,83) • plotPixel(75,73) • plotPixel(74,74) • plotPixel(20,10)

  18. Y window y X x How to draw things? plotPixel(x,y) screen

  19. Why is this impractical? • Coordinates are expressed in screen space, but objects live in (3D) world space • Resizing window implies we have to change coordinates of objects to be drawn • We want to make a separation between: • values to describe geometrical objects • values needed to draw these objects on the screen

  20. How to draw things? • Specify points to OpenGL glVertex*( … ) glVertex2i( … ) glVertex3i( … ) glVertex2f( … ) glVErtex3f( … ) glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd(); glBegin(GL_POINTS); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd();

  21. How to draw things? For (k=0; k<500; k++) { … // compute point k x = …; y = …; glBegin(GL_POINTS); glVertex2f(x, y); glEnd(); } glFlush();

  22. More about OpenGL… • OpenGl = set of libraries

  23. More about OpenGL… • OpenGl supports geometric primitives and raster primitives

  24. Geometric Primitives in OpenGL • Geometric primitives are defined by vertices • GL_POINTS • GL_LINES • GL_LINE_STRIP, GL_LINE_LOOP

  25. Geometric Primitives in OpenGL • Closed loops = polygons • Polygons: describe surfaces

  26. Geometric Primitives in OpenGL • GL_POLYGON, GL_QUADS, …

  27. Viewing in OpenGL • Scene is independent of camera • gluOrtho2D(left, tight, bottom, top)

  28. 3D primitives void triangle(point3 a, point3 b, point3 c) { glBegin(GL_POLYGON) glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); glEnd(); } void tetrahedron () { glColor3f(1.0,0.0,0.0); triangle(v[0], v[1], v[2]); … }

  29. 3D primitives • Hidden surfaces? • Z-buffer • Keep depth for each pixel • Initialize! • glClear(GL_COLOR_BUFFER_BIT); • glClear(GL_DEPTH_BUFFER_BIT); • … • glFlush();

  30. World window & viewport • World window:specifies what part of the world should be drawn • Viewport:rectangular area in the screen window in which we will draw

  31. window World window & viewport screen window world window viewport

  32. window Mapping: world window to viewport Vt Wt Wb Vb Vl Vr Wl Wr

  33. window Mapping: world window to viewport Maintain proportions! Vt Wt Wb Vb Vl Vr Wl Wr

  34. Mapping: world window to viewport x sx Vl Vr Wl Wr

  35. Mapping: world window to viewport • If x = Wl, then sx = Vl • If x = Wr, then sx = Vr • If x = f*(Wr-Wl), then sx = f*(Vr-Vl) • If x < Wl, then sx < Vl • If x > Wr, then sx > Vr • … also for y and sy

  36. World window • Pick size automatically world window

  37. window Automatic setting to preserve aspect ratio & center H Aspect ratio R W R > W/H

  38. window Automatic setting to preserve aspect ratio & center H Aspect ratio R W R < W/H

  39. Clipping • Lines outside of world window are not to be drawn. • Graphics API clips them automatically. • But clipping is a general tool in graphics!

  40. Clipping

  41. Clipping A B clipSegment(…): • Return 1 if line within window • Return 0 if line outside window • If line partially inside, partially outside: clip and return 1 C E D

  42. Cohen-Sutherland clipping • Trivial accept/reject test! Trivial reject Trivial accept

  43. Cohen-Sutherland region outcodes • 4 bits: TTFF Left of window? Above window? Right of window? Below window?

  44. Cohen-Sutherland region outcodes • Trivial accept: both endpoints are FFFF • Trivial reject: both endpoints have T in the same position TTFF FTFF FTTF TFFF FFFF FFTF TFFT FFFT FFTT

  45. Cohen-Sutherland: chopping • If segment is neither trivial accept or reject: • Clip against edges of window in turn

  46. Cohen-Sutherland: chopping Trivial accept

  47. Cohen-Sutherland line clipper • int clipSegment (point p1, point p2) Do { If (trivial accept) return (1) If (trivial reject) return (0) If (p1 is outside) if (p1 is left) chop left else if (p1 is right) chop right … If (p2 is outside) … } while (1)

  48. Raster Graphics • What is an image? • Array of pixels • How to convert lines and polygons to pixels? • Continuous to discrete • Scan conversion

  49. Displays • Early displays were vector displays • Electron beam traces lines • Image is sequence of endpoints • Wireframes, no solid fills

  50. Displays • Raster displays • Electron beam traces regular pattern • Image is 2D array of pixels • Fast, but discretisation errors • Every pixel has b bits for color • B&W: 1 bit • Basic colors: 8, 15, 16, 24 bits • High-end: 96 bits

More Related