1 / 21

Polygon Details

Polygon Details. What is the Polygon?. a polygon is a plane figure specified by a set of three or more coordinate positions, called vertices, that are connected in sequence by straight-Line segments, called the edges or sides of the polygon. Rectangle. Rectangle is a polygon.

navid
Download Presentation

Polygon Details

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. Polygon Details

  2. What is the Polygon? • a polygon is a plane figure specified by a set of three or more coordinate positions, called vertices, that are connected in sequence by straight-Line segments, called the edges or sides of the polygon.

  3. Rectangle • Rectangle is a polygon. • OpenGL provides a filled-rectangle drawing primitive, glRect • We need 2 points to define one rectangle. • gl. glRect{sifd}( x1, y1, x2, y2); x1,y1 x2,y2

  4. Rectangle ex. • gl.glColor3f(0,1f,0); • gl.glRecti(100,50,-100,-50); OUTPUT

  5. Polygon • A polygon has two sides -front and back. • If vertices of polygons appear in counterclockwise order called front-facing. • Because OpenGL by default use counterclockwise then also we use counterclockwise to draw polygon. • We bracket each set of vertices between a call to glBegin() and a call to glEnd().

  6. Polygon Ex. gl.glBegin(GL2.GL_POLYGON); gl.glVertex2i(-50,75); gl.glVertex2i(-100,0); gl.glVertex2i(-50,-75); gl.glVertex2i(50,-75); gl.glVertex2i(100,0); gl.glVertex2i(50,75); gl.glEnd(); OUTPUT

  7. Class Activity

  8. Geometric Drawing Primitives

  9. Geometric Drawing Primitives

  10. Polygon face Mode • Each polygon shape contains of two faces, Front and Back. • By default both of them are Fill • The PolygonModeuse to control the polygon faces such as (Fill, Line or Point). Fill Mode Line Mode Point Mode

  11. Polygon face Mode gl.glPolygonMode(GL2.GL_FRONT,GL2.GL_FILL); gl.glPolygonMode(GL2.GL_BACK,GL2.GL_LINE); gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_POINT); • To change the face of polygon form Front to Back or Back to Front we use gl.glFrontFace(GL2.GL_CW); (ClockWise) gl.glFrontFace(GL2.GL_CCW); (CounterClockWise)

  12. Polygon face Mode Ex. gl.glPolygonMode(GL2.GL_FRONT,GL2.GL_FILL); gl.glPolygonMode(GL2.GL_BACK,GL2.GL_LINE); gl.glFrontFace(GL2.GL_CW); gl.glBegin(GL2.GL_POLYGON); gl.glVertex2i(0,100); gl.glVertex2i(-75,0); gl.glVertex2i(0,-100); gl.glVertex2i(75,0); gl.glEnd(); OUTPUT

  13. Class Activity

  14. PolygonOffset • If you want to highlight the edges of a solid object, you might draw the object with polygon mode set to GL_FILL, and then draw it again, but in a different color and with the polygon mode set to GL_LINE • The problem: Depth values are not the same • This undesirable effect can be eliminated by using polygon offset, which adds an appropriate offset to force coincident z values apart, separating a polygon edge from its highlighting line

  15. PolygonOffset

  16. PolygonOffset

  17. Culling Polygon Faces • To discard front-or back-facing polygons, use the command glCullFace() and enable culling with glEnable(). • We can discard GL_FRONT,GL_BACK or both faces GL_FRONT_AND_BACK. • Culling enabled using glEnable() with GL_CULL_FACE, and disabled using glDisable()

  18. Culling Polygon Faces Ex. • gl.glPolygonMode(GL2.GL_FRONT,GL2.GL_FILL); • gl.glPolygonMode(GL2.GL_BACK,GL2.GL_LINE); • gl.glFrontFace(GL2.GL_CCW); • gl.glCullFace(GL2.GL_FRONT); • gl.glEnable(GL2.GL_CULL_FACE); • gl.glBegin(GL2.GL_POLYGON); • gl.glVertex2i(0,100); • gl.glVertex2i(-75,-50); • gl.glVertex2i(75,-50); • gl.glEnd(); • gl.glDisable(GL2.GL_CULL_FACE);

  19. Discarding Boundary Edges • gl.glEdgeFlag(boolean flag) use to discard the boundary edges of polygon, this method only use with LINE mode of polygon. • used between glBegin() andglEnd() . • boolean flag can be true or false if flag is false then all edges after the glEdgeFlag() command is discarded . • When we want to disable discarding edges we change the flag to true.

  20. EdgeFlag() Ex. • gl.glPolygonMode(GL2.GL_FRONT,GL2.GL_LINE); • gl.glPolygonMode(GL2.GL_BACK,GL2.GL_FILL); • gl.glFrontFace(GL2.GL_CCW); • gl.glBegin(GL2.GL_POLYGON); gl.glEdgeFlag(false); • gl.glVertex2i(100,50); • gl.glEdgeFlag(true); • gl.glVertex2i(-75,50); • gl.glEdgeFlag(false); • gl.glVertex2i(-100,-50); • gl.glEdgeFlag(true); • gl.glVertex2i(75,-50); gl.glEnd();

  21. HomeWork

More Related