45
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TUe

2IV60 6 Primitives

Embed Size (px)

DESCRIPTION

kjkj

Citation preview

  • 2IV60 Computer graphicsGraphics primitives and attributesJack van WijkTU/e

  • OverviewBasic graphics primitives: points, lines, polygons

    Basic attributeslinewidth, color

  • OpenGL output functionsglBegin(GL_LINES); // Specify what to draw, // here lines

    // Geometric info via vertices: glVertex*(); // 1 glVertex*(); // 2 ... // ...glEnd;

    glVertex[234][isfd]

    [234]: 2D, 3D, 4D[isfd]: integer, short, float, doubleFor instance: glVertex2i(100, 25);H&B 4-4:81-82

  • Point and Line primitivesGL_POINTS: sequence of points

    GL_LINES: sequence of line segments

    GL_LINE_STRIP: polyline

    GL_LINE_LOOP: closed polylineH&B 4-4:81-821234123456781234512345

  • Fill-area primitives 1Point, line and curve, fill areaUsually polygons2D shapes and boundary 3D objectsH&B 4-6:83-84

  • Fill-area primitives 2Approximation of curved surface:Surface mesh or Surface tesselationFace or facet (planar), patch (curved)H&B 4-6:83-84

  • PolygonPolygon: Planar shape, defined by a sequence of three or more vertices, connected by line segments (edges or sides)Standard or simple polygon: no crossing edgesbowtie polygonH&B 4-7:84-94

  • Regular polygonVertices uniformly distributed over a circle:

    rH&B 4-7:84-94

  • Convex vs. concave 1Convex: All interior angles < 180 graden, andAll line segments between 2 interior points in polygon, andAll points at the same side of line through edge, andFrom each interior point complete boundary visibleConcave: not convexH&B 4-7:84-94

  • Convex vs. concave 2Puzzle:Given a planar polygon in 3D, with vertices Pi, with i = 1, , N.Give a recipe to determine if the polygon is convex or concave.H&B 4-7:84-94

  • Convex vs. concave 3Puzzle:Given a planar polygon in 3D, with vertices Pi, with i = 1, , N.Give a recipe to determine if the polygon is convex or concave.

    Solution: (multiple solutions possible)H&B 4-7:84-94

  • Splitting concave polygonsH&B 4-7:84-94

  • Convex polygon trianglesPuzzle: Which sequence of points to pick?Repeat Pick three succeeding points; Join the outside ones with a line; Remove the middle pointUntil three points are left over

    H&B 4-7:84-94

  • Inside / outside polygon 1H&B 4-7:84-94

  • Inside / outside polygon 2H&B 4-7:84-94

  • Inside / outside polygon 3General: odd-even ruleDraw a line from C to a point far away. If the number of crossings with the boundary is odd, then C is inside the polygoon.H&B 4-7:84-94

  • Storage polygons 1Mesh:VerticesEdgesFacesOperationsDraw all edgesDraw all facesMove all verticesDetermine orientationH&B 4-7:84-94

  • Storage polygons 2Simple: all polygons apartFaces:F1: V1, V2, V3Per vertex coordinatesF2: V1, V3, V4, V5H&B 4-7:84-94

  • More efficient: polygons and vertices apartFaces:Vertices:F1: 1,2,3V1: x1, y1, z1F2: 1,3,4,5V2: x2, y2, z2V3: x3, y3, z3V4: x4, y4, z4V5: x5, y5, z5V6: x6, y6, z6

    Storage polygons 3H&B 4-7:84-94

  • Storage polygons 4Also: polygons, edges and vertices apartFaces:Edges:Vertices:F1: 1,2,3E1: 1,2V1: x1, y1, z1F2: 3,4,5,6E2: 2,3V2: x2, y2, z2E3: 3,1V3: x3, y3, z3E4: 3,4V4: x4, y4, z4E5: 4,5V5: x5, y5, z5E6: 5,1V6: x6, y6, z6

    H&B 4-7:84-94

  • Or: keep list of neighboring faces per vertexFaces:Vertices:Neighbor faces:F1: 1,2,3V1: x1, y1, z1 1, 2F2: 1,3,4,5V2: x2, y2, z21V3: x3, y3, z31, 2V4: x4, y4, z4 2V5: x5, y5, z5 2V6: x6, y6, z6

    Storage polygons 5H&B 4-7:84-94

  • Storage polygons 6Many other formats possibleSee f.i. winged edge data structureSelect/design storage format based on:Operations on elements;Efficiency (size and operations);SimplicityMaintainabilityConsistency

    H&B 4-7:84-94

  • Polygons in space 13D flat polygon in (infinite) planeEquation plane:Ax + By + Cz + D = 0xyzPlane: z=0H&B 4-7:84-94

  • Polygons in space 2Position point (x, y, z) w.r.t. plane:Ax + By + Cz + D > 0 : point in front of planeAx + By + Cz + D < 0 : point behind plane

    xyzPlane: z=0H&B 4-7:84-94

  • Polygons in space 3Normal: vector N perpendicular to planeUnit normal: |N|=1xyzNormal: (0, 0, 1)Vlak: z=0

    In general:Normal: N=(A, B, C) forPlane: Ax + By + Cz + D = 0 Or N.X+D = 0H&B 4-7:84-94

  • Polygons in space 4xyzH&B 4-7:84-94

  • OpenGL Fill-Area Functions 1glBegin(GL_POLYGON); // Specify what to draw, // a polygon

    // Geometric info via vertices: glVertex*(); // 1 glVertex*(); // 2 ... // ...glEnd;

    glVertex[234][isfd]

    [234]: 2D, 3D, 4D[isfd]: integer, short, float, doubleFor instance: glVertex2i(100, 25);H&B 4-4:81-82

  • OpenGL Fill-Area Functions 2GL_POLYGON: convex polygon

    Concave polygons give unpredictable results.123451345H&B 4-8:94-99

  • OpenGL Fill-Area Functions 3GL_TRIANGLES: sequence of triangles

    GL_TRIANGLE_STRIP:

    GL_TRIANGLE_FAN:

    12345678912345678123456H&B 4-8:94-99

  • OpenGL Fill-Area Functions 4GL_QUADS: sequence of quadrilaterals

    GL_QUAD_STRIP: strip of quadrilaterals12345678910111212345678H&B 4-8:94-99

  • More efficiencyReduce the number of function calls:OpenGL Vertex Arrays: pass arrays of vertices instead of single ones;

    Store information on GPU and do not resend:OpenGL Display lists;Vertex Buffer Objects.

    H&B App. C

  • OpenGL Display lists 1Key idea: Collect a sequence of OpenGL commands in a structure, stored at the GPU, and reference it later on+ Simple to program+ Can give a boost+ Useful for static scenes and hierarchical models Not the most modern

    H&B 4-15 111-113

  • OpenGL Display lists 2// Straightforward

    void drawRobot(); { // lots of glBegin, glVertex, glEnd calls }

    void drawScene(); { drawRobot(); glTranslate3f(1.0, 0.0, 0.0); drawRobot();}

    H&B 4-15 111-113

  • OpenGL Display lists 3void drawRobot();{ // lots of glBegin, glVertex, glEnd calls }

    int rl_id;

    void init(); { rl_id = glGenLists(1); // get id for list glNewList(rl_id, GL_COMPILE); // create new list drawRobot(); // draw your object glEndList(); } // end of list

    void drawScene(); { glCallList(rl_id); // draw list glTranslate3f(1.0, 0.0, 0.0); glCallList(rl_id); // and again}

    H&B 4-15 111-113

  • OpenGL Display lists 4First, get an id. Either some fixed constant, or get a guaranteed unique one:

    rl_id = glGenLists(1); // get id for list

    Next, create a display list with this id:

    glNewList(rl_id, GL_COMPILE); // create new list drawing commands; // draw somethingglEndList(); // end of list

    Finally, replay the list. Change the list only when the scene is changed:

    glCallList(rl_id); // draw listH&B 4-15 111-113

  • Attributes 1Attribute parameter: determines how a graphics primitive is displayedFor instance for line: color, width, styleOpenGL: simple state systemCurrent setting is maintained;Setting can be changed with a function.H&B 5-1:130

  • Attributes 2Example:glLineWidth(width);glEnable(GL_LINE_STIPPLE);glLineStipple(repeatfactor, pattern);// draw stippled lines... glDisable(GL_LINE_STIPPLE);Note: special features often must be enabled explicitly with glEnable().

    H&B 5-7:141-143

  • Color 1RGB mode : color = (red, green, blue)glColor[34][bisf]: set color of vertexFor example:glColor4f(red, green, blue, alpha)alpha: opacity (1transparantie)

    H&B 5-2:130-131

  • Color 2RGB: hardware oriented modelDimensions are not natural(0, 0, 0): black; (1, 0, 0): red; (1, 1, 1) white

    H&B 5-2:130-131

  • Color 3HSV: Hue, Saturation (Chroma), ValueMore natural dimensions

    Hue: red-orange-yellow-green-blue- purple;Saturation: grey-pink-red;Value: dark-lightH&B 19-7:614-617

  • Color 4HSL: Hue, Saturation (Chroma), LightnessMore natural dimensions

    H&B 19-8:618-618

  • Color 5Color: big and complex topicColor: not physical, but perceptual

    AB

  • Color 6Adelson checkerboard illusion

  • Color 6Adelson checkerboard illusion

  • NextWe now know how to draw polygons.How to model geometric objects?