CSC461%20Lecture%206:%202D%20Programming%20in%20OpenGL - PowerPoint PPT Presentation

About This Presentation
Title:

CSC461%20Lecture%206:%202D%20Programming%20in%20OpenGL

Description:

OpenGL will only display polygons correctly that are. Simple: edges cannot cross. Convex: All points on line segment between two points in a polygon are also in ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 14
Provided by: jhan6
Learn more at: https://csc.csudh.edu
Category:

less

Transcript and Presenter's Notes

Title: CSC461%20Lecture%206:%202D%20Programming%20in%20OpenGL


1
CSC461 Lecture 62D Programming in OpenGL
  • Objectives
  • Fundamental OpenGL primitives
  • Attributes
  • Viewport

2
OpenGL Primitives
3
Polygon Issues
  • OpenGL will only display polygons correctly that
    are
  • Simple edges cannot cross
  • Convex All points on line segment between two
    points in a polygon are also in the polygon
  • Flat all vertices are in the same plane
  • User program must check if above true
  • Triangles satisfy all conditions

nonconvex polygon
nonsimple polygon
4
Drawing a Sphere
  • Sphere description
  • X(?,?)sin?cos?
  • y(?,?)cos?cos?
  • z(?,?)sin?
  • Approximation
  • A set of polygons
  • Efficiently using
  • Quad strips
  • Triangle strips

5
Drawing a Sphere (Cont.)
  • Fix ? and change ? ? get circles of constant
    longitude
  • Fix ? and change ? ? get circles of constant
    latitude
  • Generate points at fixed increments of ? and ? ?
    quadrilaterals
  • Color corresponds to increments of 20 degrees in
    ? and 20 degrees in ?

6
Source code Drawing quadrilaterals
  • cM_PI/180
  • for (phi-80.0 philt80.0 phi20.0)
  • glBegin(GL_QUAD_STRIP)
  • for (theta-180.0 thetalt180.0 theta20.0)
  • x sin(ctheta)cos(c.phi)
  • y cos(ctheta)cos(cphi)
  • z sin(ctheta)
  • glVertex3d(x,y,x)
  • x sin(ctheta)cos(c(phi20.0))
  • y cos(ctheta)cos(c(phi20.0))
  • z sin(c(phi20.0))
  • glVertex3d(x,y,z)
  • glEnd()

7
Drawing poles
  • cM_PI/180.0
  • glBegin(GL_TRANGLE_FAN)
  • glVertex3d(x,y,z)
  • zsin(c80.0)
  • for (theta-180.0 thetalt180.0 theta20)
  • x sin(ctheta)cos(c.80.0)
  • y cos(ctheta)cos(c80.0)
  • glVertex3d(x,y,z)
  • glEnd()
  • Xy0
  • z-1
  • glBegin(GL_TRIANGLE_FAN)
  • glVertex3d(x,y,z)
  • z-sin(c80.0)
  • for (theta-180.0 thetalt180.0 theta20)
  • x sin(ctheta)cos(c.80.0)
  • y cos(ctheta)cos(c80.0)
  • glVertex3d(x,y,z)

8
Attributes
  • Attributes are part of the OpenGL and determine
    the appearance of objects
  • Color (points, lines, polygons)
  • Size and width (points, lines)
  • Stipple pattern (lines, polygons)
  • Polygon mode
  • Display as filled solid color or stipple pattern
  • Display edges

9
RGB color
  • Each color component stored separately in the
    frame buffer
  • Usually 8 bits per component in buffer
  • Note in glColor3f the color values range from 0.0
    (none) to 1.0 (all), while in glColor3ub the
    values range from 0 to 255

10
Indexed Color
  • Colors are indices into tables of RGB values
  • Selecting color from table
  • glIndexi(element)
  • Setting color into table
  • glutSetColor(int color, GLfloat r, GLfloat b,
    GLfloat g)
  • Requires less memory
  • indices usually 8 bits
  • not as important now
  • Memory inexpensive
  • Need more colors for shading

11
Color and State
  • The color as set by glColor becomes part of the
    state and will be used until changed
  • Colors and other attributes are not part of the
    object but are assigned when the object is
    rendered
  • We can create conceptual vertex colors by code
    such as
  • glColor()
  • glVertex()
  • glColor()
  • glVertex()

12
Smooth Color
  • Default is smooth shading
  • OpenGL interpolates vertex colors across visible
    polygons
  • Alternative is flat shading
  • Color of first vertex
  • determines fill color
  • Code
  • glShadeModel(GL_SMOOTH)
  • glShadeModel(GL_FLAT)

13
Viewports
  • Do not have use the entire window for the image
    glViewport(x,y,w,h)
  • Values in pixels (screen coordinates)
Write a Comment
User Comments (0)
About PowerShow.com