Attributes of Graphics Primitives - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Attributes of Graphics Primitives

Description:

Store RGB color codes in frame buffer or in a separate table ... With bitmap functions. create images of each character. With GLUT character generating routines ... – PowerPoint PPT presentation

Number of Views:2651
Avg rating:3.0/5.0
Slides: 27
Provided by: isabellebi
Category:

less

Transcript and Presenter's Notes

Title: Attributes of Graphics Primitives


1
Attributes of Graphics Primitives
2
Agenda
  • OpenGL state variables
  • Color and gray scale
  • Color functions
  • Point attributes and functions
  • Line attributes and functions
  • Curve attributes and functions
  • Character attributes
  • Antialiasing

3
Learning Objectives
  • Learn OpenGL state variables
  • Understand what are the main attributes of
    graphic primitives
  • color, antialiasing,
  • point attributes,
  • line attributes,
  • curve attributes,
  • character attributes

4
OpenGL State Variables
  • State parameters are attributes of the output
    primitives.
  • In OpenGL, state parameters include
  • Color
  • Current matrix mode
  • Elements of the Modelview matrix
  • Current position of frame buffer
  • Lighting effects parameters.
  • Changes affect next operations.

5
Color and Gray Scale
  • RGB color buffer
  • Store RGB color codes in frame buffer or in a
    separate table
  • Color code placed at pixel location
  • Minimum number of colors for 3-bits Left bit ?
    Red, Middle bit ? Green, Left bit ? Blue0 ?
    black, 1 ? blue, , 7 ? white
  • More color bits increase the size of the frame
    buffer 24-bits 1024 1024 3MB

6
Color and Gray Scale
  • Color tables
  • Color map (color look-up table)
  • Each pixel in the frame buffer contains a value
    (Ex. 196) corresponding to an entry in the color
    table (Ex. 2081), which has 256 entries.
  • Color table contains a 3-byte color code that
    represents an RGB color 1-byte for the Red,
    1-byte for the Green, 1-byte for the Blue.
  • Pick 256 colors from a total of 17 million, and
    save storage 1024 1024 1MB

7
Color and Gray Scale
(from Donald Hearn and Pauline Baker)
8
Color and Gray Scale
  • Gray scale
  • Shades of gray0 ? dark gray, 1 ? light gray
  • Other color parameters
  • Intensity (amount of light energy)
  • Luminance (perceived brightness)

9
Color Functions
  • Set color display mode to RGBglutInitDisplayMode(
    GLUT_SINGLE GLUT_RGB)
  • GLUT_SINGLE or GLUT_DOUBLE
  • GLUT_RGB, GLUT_RGBA, GLUT_INDEX
  • gl.glEnable(GL.GL_COLOR_RGB) // in JOGL
  • Alpha value (RGBA) for color blending of
    overlapping primitives (transparent or not)
  • Affects the color state from that function call
    on (not retroactive)
  • gl.glColor
  • means b (byte), i (int), s (short), d (double),
    f (float)
  • default (1.0f, 1.0f, 1.0f, 1.0f) for white

10
Color Functions
  • public void triangleColor ()
  • // displays a three-colored triangle
  • gl.glClear (GL.GL_COLOR_BUFFER_BIT) //
    apply clear color to color buffer
  • gl.glBegin(GL.GL_TRIANGLES) // Drawing
    Using Triangles
  • gl.glColor3f(1.0f, 0.0f, 0.0f) // set
    color to red
  • gl.glVertex2i( 100, 150) // top
  • gl.glColor3f(0.0f, 1.0f, 0.0f) // set
    color to green
  • gl.glVertex2i(10,10) // bottom Left
  • gl.glColor3f(0.0f, 0.0f, 1.0f) // set
    color to blue
  • gl.glVertex2i(180,15) // bottom
    right
  • gl.glEnd() // finished
    drawing the triangle

11
Color Functions
12
Color Functions
  • Point center new Point(100, 75)
  • float CLUT 1.0f,0.0f,0.0f,
    1.0f,0.5f,0.0f,
  • 1.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0
    f,
  • 1.0f,0.0f,1.0f, 0.5f,0.0f,0.5f,
    1.0f,0.0f,0.5f
  • Point vertex new Point 8
  • for (k 0 k lt 8 k)
  • theta Math.PI 2 k / 8.0
  • vertexk new Point()
  • vertexk.setLocation(
    (int) (center.getX() 50 Math.cos (theta)),
  • (int) (center.getY() 50
    Math.sin (theta)))
  • gl.glBegin (GL.GL_POLYGON)
  • for (k 0 k lt 8 k)
  • gl.glColor3fv (CLUTk)
  • gl.glVertex2d (vertexk.getX(),
    vertexk.getY())
  • gl.glEnd ( ) // finished drawing The
    Triangle

13
Color Functions
14
Point Attributes and Functions
  • Attributes are any parameters that affect the way
    graphic primitives are displayed.
  • Basic attributes
  • Color
  • Size
  • Point
  • Color
  • Size is a multiple of the pixel size (a square).
  • gl.glPointSize (size) // size is the number of
    pixels

15
Line Attributes and Functions
  • Line attributes
  • Basic attributes color, width, style
  • Widthcan be set in the line drawing algorithm as
    well as the length and point spacing.Raster
    algorithms display line attributes by plotting
    pixel spans, like plotting multiple pixels along
    the line either horizontally (mlt1)of vertically
    (mgt1).Produces lines of slightly different width
    according to the slope, and also abrupt ends
    (horizontal or vertical).Add line caps at the
    end (butt cap, round cap, projecting square cap).

16
Line Attributes and Functions
  • Line attributes
  • Widththick polylines with previous method do not
    connect smoothly
  • miter join extend the outer boundaries of each
    segment until they join
  • round join cap connection with circular boundary
  • bevel join display line segments with butt caps
    and fill-in triangular gap between the two butts.

17
Line Attributes and Functions
  • Line attributes
  • Style
  • Solid lines, dashed lines, dotted lines can be
    generated by modifying the line drawing algorithm
    spacing between drawn pixels
  • Can be also generated from the raster by using a
    pixel mask, for example 11111000 will display a
    dashed line with dash length of 5 and inter-dash
    length of 3.

18
Line Attributes and Functions
  • Line attributes
  • Pen and brush options
  • Select several pen and brush styles
  • Shape, size, pattern
  • Can be implemented in a pixel mask
  • Change the mask to change the pen/brush

19
Line Attributes and Functions
  • Line attribute functions
  • gl.glLineWidth (width) // width is the width
    of the line
  • Default width is 1.0
  • gl.glLineStipple (repeatFactor, pattern)
  • pattern references a 16-bit integer that
    describes how the line should be displayed
    (default 0xFFFF, all bits set to 1, solid line)
  • repeatFactor specifies how many times each bit in
    the pattern is to be repeated before the next bit
    in the pattern in applied (default 1).
  • Example displays 0x00FF -------- --------
    -------- 8 solid line pixels,
    followed by 8 spaces
  • Requires first glEnable (GL_LINE_STIPPLE)
    line-pattern feature can be disabled by
    glDisable (GL_LINE_STIPPLE)
  • gl.glShadeModel (GL.GL_SMOOTH) // linear
    interpolation of colors

20
Line Attributes and Functions
21
Curve Attributes and Functions
  • Same parameters as for lines
  • Width
  • Color
  • Dot-dash patterns
  • Pen/brush options
  • Raster curves produced by horizontal/vertical span

22
Character Attributes
  • Character attributes
  • Font (typeface)Helvetica, Courier, Times Roman,
  • Underlining stylesolid, dotted, double
  • Styleboldface, italics, outline, shadow
  • Size10-point, 12-point,
  • Color.

23
Character Attributes
(from Donald Hearn and Pauline Baker)
24
Character Attributes
  • Character attributes
  • Font (typeface)Helvetica, Courier, Times Roman,
  • Underlining stylesolid, dotted, double
  • Styleboldface, italics, outline, shadow
  • Size10-point, 12-point,
  • Color
  • Direction (up vector)

25
Character Attributes
  • Two methods
  • With bitmap functionscreate images of each
    character
  • With GLUT character generating routinesavailable
    in OpenGL from GLUT classBITMAP_HELVETICA_10BITM
    AP_HELVETICA_12BITMAP_HELVETICA_18BITMAP_TIMES_R
    OMAN_10BITMAP_TIMES_ROMAN_24glutBitmapCharacte
    r, glutBitmapString, glutBitmapLength,
    glutBitmapWidth

26
Antialiasing
  • Used to improve the appearance of lines.
  • gl.glEnable ( primitive_type )primitive_typeGL_
    POINT_SMOOTHGL_LINE_SMOOTHGL_POLYGON_SMOOTH
  • Color-blendinggl.glEnable (GL.GL_BLEND)gl.glBlen
    dFunc ( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA
    )
Write a Comment
User Comments (0)
About PowerShow.com