Intro to OpenGL: Vertices and Drawing - University of Iowa

Intro to OpenGL: Vertices and Drawing - University of Iowa

Intro to OpenGL: Vertices and Drawing Geb Thomas ( Adapted from OpenGL Progra mming Guide ) Learning Objectives Learn how to define vertices Learn how to draw polygons, lines, and points

Learn how to define and use surface normals Points and Lines Points One vertex per point You can control the size and color of a point

Lines Lines are line segments (they have a beginning and an end). You can control with width and the stipple Polygons

Polygons can have n vertices All the vertices should be in the same plane. The polygon should be convex Vertices void glVertex{234}{sifd}[v](TYPEcoords); Specifies a vertex for use in describing a geometric object. You can supply up to four coordinates (x, y, z, w) for a particular vertex or as few as two (x, y) by selecting the appropriate

version of the command. If you use a version that doesn't explicitly specify z or w, z is understood to be 0 and w is understood to be 1. Calls to glVertex*() are only effective between a glBegin() and glEnd() pair. Vertex Examples glVertex2s(2, 3); glVertex3d(0.0, 0.0, 3.1415926535898); glVertex4f(2.3, 1.0, -2.2, 2.0); GLdouble dvect[3] = {5.0, 9.0, 1992.0};

glVertex3dv(dvect); Drawing Primitives glBegin(GL_POLYGON); glVertex2f(0.0,

glVertex2f(0.0, glVertex2f(4.0, glVertex2f(6.0, glVertex2f(4.0, glEnd(); 0.0); 3.0); 3.0); 1.5);

0.0); Primitives, Illustrated Drawing Details void glPointSize(GLfloat size); Sets the width in pixels for rendered points; size must be greater than 0.0 and by default is 1.0. void glLineWidth(GLfloat width);

Sets the width in pixels for rendered lines; width must be greater than 0.0 and by default is 1.0. Line Stipple void glLineStipple(GLint factor, GLushort pattern); Sets the current stippling pattern for lines. The pattern argument is a 16-bit series of 0s and 1s, and it's repeated as necessary to stipple a given line. A 1

indicates that drawing occurs, and 0 that it does not, on a pixel-by-pixel basis, beginning with the low-order bit of the pattern. The pattern can be stretched out by using factor, which multiplies each subseries of consecutive 1s and 0s. Thus, if three consecutive 1s appear in the pattern, they're stretched to six if factor is 2. factor is clamped to lie between 1 and 255. Line stippling must be enabled by passing GL_LINE_STIPPLE to glEnable(); it's disabled by passing the same argument to glDisable().

Line Stipple Example glLineStipple(1, 0x3F07); glEnable(GL_LINE_STIPPLE); Polygon Filling void glPolygonMode(GLenum face, GLenum mode); Controls the drawing mode for a polygon's front and back faces. The parameter face can be GL_FRONT_AND_BACK, GL_FRONT, or GL_BACK; mode can be GL_POINT, GL_LINE,

or GL_FILL to indicate whether the polygon should be drawn as points, outlined, or filled. By default, both the front and back faces are drawn filled. Polygon Culling void glFrontFace(GLenum mode); Controls how front-facing polygons are determined. By default, mode is GL_CCW, which corresponds to a counterclockwise orientation of the ordered vertices of a

projected polygon in window coordinates. If mode is GL_CW, faces with a clockwise orientation are considered front-facing. void glCullFace(GLenum mode); Indicates which polygons should be discarded (culled) before they're converted to screen coordinates. The mode is either GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK to indicate front-facing, back-facing, or all polygons. To take effect, culling must be enabled using glEnable() with

GL_CULL_FACE; it can be disabled with glDisable() and the same argument. Polygon Normals A normal vector sets the current normal for the subsequent vertices. glBegin (GL_POLYGON); glNormal3fv(n0); glVertex3fv(v0); glNormal3fv(n1); glVertex3fv(v1); glNormal3fv(n2); glVertex3fv(v2); glNormal3fv(n3); glVertex3fv(v3);

glEnd(); Learning Objectives Learn how to define vertices Learn how to draw polygons, lines, and points Learn how to define and use surface normals

Recently Viewed Presentations

  • Microbiology: Plant Cells - BioEd Online

    Microbiology: Plant Cells - BioEd Online

    Century Gothic MS Pゴシック Arial Wingdings 2 Calibri Austin 1_Austin 2_Austin 3_Austin Think Like a Microbiologist Slide 1 Slide 2 Slide 3 Slide 4 Slide Image Key Plant Cell Structures
  • Chapter 6 Section 4: The building Blocks of life

    Chapter 6 Section 4: The building Blocks of life

    There are 6 major nucleotides, all of which have 3 main units - a phosphate, a nitrogen base, and a ribose sugar. Nucleic Acids. Nucleic acids. There are 2 types of nucleic acids found in living organisms: deoxyribonucleic acid (DNA)...
  • Dark Romanticism and the Gothic Literature movement

    Dark Romanticism and the Gothic Literature movement

    Modern Gothic. There are modern adaptations of the term "gothic" Gothic - literature that combine elements of both Romanticism and Horror; exploration of the surrealism of human nature. Usually these elements combine to form mysteries, ghost stories, spiritual awakenings, delving...
  • TAX RATES FOR TAX YEAR 2017 - Tipu Associates

    TAX RATES FOR TAX YEAR 2017 - Tipu Associates

    1. Sale against cash of any instrument including demand draft, payment order, CDR, STDR, SDR, RTC, or any other instrument of bearer nature or of receipt of cash on cancellation of any of these instruments (except in case of inter-bank...
  • Winning Collors - Bullitt Central JROTC

    Winning Collors - Bullitt Central JROTC

    Winning Colors: Effective Communication. Developing awareness of others can help you become a more effective communicator. By having insight into another's preferences you may be able to adapt your personal communications skills and your behavior in such a way that...
  • Anderson's Business Law 20e - Christian Brothers University

    Anderson's Business Law 20e - Christian Brothers University

    Anderson's Business Law and the Legal Environment, Standard 20e Business Law: Principles for Today's Commercial Environment 2e Chapter 30 Liability of the Parties under Negotiable Instruments Parties to Negotiable Instruments: Rights and Liabilities The party claiming rights to an instrument...
  • Marine Fisheries Symposium USA v Bengis Lessons for

    Marine Fisheries Symposium USA v Bengis Lessons for

    Headline News: USA v Bengis . 14 June 2013 - New York District Court hands down restitution order in an amount of $29 mill. - Defendants ordered to pay South Africa compensation for damage to fish stocks;
  • Global Ocean Monitoring: Recent Evolution, Current Status, and

    Global Ocean Monitoring: Recent Evolution, Current Status, and

    Global Ocean Monitoring: Recent Evolution, Current Status, and Predictions Prepared by Climate Prediction Center, NCEP/NOAA November 12, 2019 http://www.cpc.ncep.noaa ...