UBI 516 Advanced Computer Graphics - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

UBI 516 Advanced Computer Graphics

Description:

Graphics Output Primitives ( Chapter 3 ) ... glDeleteLists( blockNum, 1 ); UBI 516 Advanced omputer Graphics Attributes of Graphics Primitives ( Chapter 4 ) ... – PowerPoint PPT presentation

Number of Views:116
Avg rating:3.0/5.0
Slides: 55
Provided by: DavidB349
Category:

less

Transcript and Presenter's Notes

Title: UBI 516 Advanced Computer Graphics


1
UBI 516 Advanced Computer Graphics
  • Graphics Output Primitives
  • ( Chapter 3 )

2
Screen Window Coordinates
Screen coordinates
  • Setting a pixel
  • glBegin(GL_POINTS) glVertex2f(px,py) glEnd()
  • Setting Orthogonal Camera
  • glMatrixMode(GL_PROJECTION)glLoadIdentity()glu
    Ortho2D(xmin,xmax,ymin,ymax)

(0,0)
x
y
(399,299) xmax,ymax
(px,py)
x
(0,0) xmin,ymin
(799,599)
y
3
CurvePolyline
  • GLU has many polynomials that are defined with
    discrete point sets (like spheres, cylinders)

4
Pixels and Object Geometry
Pixel Line Rectangle
5
Drawing a Circle
Midpoint and modified midpoint algorithm.
6
Polygon Fill
  • Convex Concave

(E1xE2)zgt0
(E2xE3)zgt0
(E3xE4)zlt0
(E4xE5)zgt0
(E5xE6)zgt0
7
Slitting of a Polygon into Triangles
  • OpenGL guarentees correct rendering of polygons
    only if they are convex. A triangle is a convex
    polygon.
  • But a polygon which has gt3 vertices can be
    concave.
  • So, we must tesselate a given polygon into
    triangles.The GLU library has a tesselator.

8
Inside-Outside Testing
We want fill inside of a polygon with constant
color.
  • Flat and convex polygons are guarenteed to be
    rendered correctly by OpenGL.
  • For nonflat polygons
  • We can work with their projections.
  • Or we can use first three vertices to determine a
    flat plane to use for the interrior.
  • For nonsimple flat polygons, we must decide how
    to determine whether a given point is inside or
    outside of the polygon (Jordan theorem).

9
Inside-Outside Testing
  • Odd-even rule (easy implementation)
  • crossing, odd parity rule, even-odd rule
  • Crossed odd edges inside point
  • Crossed even edges outside point
  • Non-zero winding rule
  • Clocwise edges 1
  • Counterclocwise edges 1
  • Dont fill while total 0

10
Polygon Tables
VERTEX TABLE
EDGE TABLE
POLYGON-SURFACE TABLE
V1 x1 y1 z1 V2 x2 y2 z2 V3 x3
y3 z3 V4 x4 y4 z4 V5 x5 y5 z5
E1 V 1, V 2 E2 V 2, V 3 E3 V 3,
V 1 E4 V 3, V 4 E5 V 4, V 5 E6 V
5, V 1
S1 E1, E 2, E3 S2 E 3, E4, E5, E6
V1
E6
E1
E3
S1
S2
V5
V3
E2
E2
E5
E4
V2
V4
11
Vertex Arrays
  • typedef GLint vertex33 vertex3 pt8
    (0,0,0), (0,1,0), (1,0,0), (1,1,0), (0,0,1),
    (0,1,1), (1,0,1), (1,1,1)
  • void quad(GLint n1, GLint n2, GLint n3, GLint n4)
    glBegin(GL_QUADS) glVertx3iv( pt n1 )
    glVertx3iv( pt n2 ) glVertx3iv( pt n3 )
    glVertx3iv( pt n4 )
  • void cube( ) quad( 6,2,3,7 ) quad( 5,1,0,4
    ) quad( 7,3,1,5 ) quad( 4,0,2,6 ) quad(
    2,0,1,3 ) quad( 7,5,4,6 )

4
5
6
7
0
1
2
3
12
Plane Equations
(x,y,z)
13
Surface Normal
  • Surface (plane) equation AxByCzD0
  • N (V1-V2)x(V1-V3) A B CT
  • If P is any point on the plane
  • NPD 0 NP -D

y
V1
V2
V3
x
z
14
OpenGL Front/Back Rendering
  • Each polygon has two sides, front and back
    (Example) glFrontFace(GL_CCW) glCullFace(GL_BAC
    K) glEnable(GL_CULL_FACE)
  • OpenGL can render the two differently
  • The ordering of vertices in the list determines
    which is the front side
  • When looking at the front side, the vertices go
    counterclockwise
  • This is basically the right-hand rule

15
Culling
  • For convex objects, such as the cube, we could
    simply remove all the faces pointing away from
    viewer.
  • glEnable(GL_CULL)
  • Normally, if we use only the z-buffer algorithm,
    we pass 6n polygons through the pipeline.
  • If we enable culling, only 3n polygons can pass
    throughthe pipeline.

16
OpenGL Bitmap Functions
17
OpenGL Pixel Operations
  • glReadPixels( xmin, ymin, width, height,
    dataFormat, dataType, array)glEnable(
    GL_COLOR_LOGIC_OP )glLogicOp( LogicOp
    )glDrawPixels( width, height, dataFormat,
    dataType, array )
  • dataFormat GL_RGB, GL_LUMINANCE, ...dataType
    GL_UNSIGNED_BYTE, LogicOp GL_COPY,
    GL_AND, GL_XOR, ...

with GL_COPY_INVERTED
18
Bitmap Fonts
  • Text in computer graphics is problematic.
  • OpenGL no text primitive (use window
    primitives)
  • GLUT minimal support
  • glRasterPosition2i(x1, y1) // First Character
    PositionglutBitmapCharacter(font,
    character)glRasterPosition2i(x2, y2) // Second
    Character PositionglutBitmapCharacter(font,
    character)
  • Font GLUT_BITMAP_TIMES_ROMAN_10, GLUT_STROKE_RO
    MAN, ...

19
Text
  • Stroke Text
  • Use vertices to define line segments or curves
    that outline each character.
  • Advantages
  • It is defined in the same way as other objects.
  • It can be manipulated as other objects (rotate,
    make bigger, smaller, etc.)
  • Disadvantages
  • Take up too much memory and processing time
  • Slow

20
Text
  • Raster Text
  • Characters are defined as rectangles of bits
    called bit blocks.
  • Each bit block defines a single character by the
    pattern of 0 and 1 bits in the block.

21
Text
  • Advantages
  • Simple and fast
  • A raster character can be placed in the frame
    buffer rapidly by a bit-block-transfer operation
    (butblt)
  • Does not take up too much memory and processing
    time
  • Disadvantages
  • It can not be defined in the same way as other
    objects.
  • It can not be manipulated as other objects.

22
Display Lists
  • Command block for often used objects.
  • Creation GLuint blockNum blockNum
    glGenLists( 1 ) glNewList( blockNum,
    GL_COMPILE ) ... // OpenGL
    commands glEndList( )
  • Execution glCallList( blockNum )
  • Deletion glDeleteLists( blockNum, 1 )

23
UBI 516 Advanced omputer Graphics
  • Attributes of Graphics Primitives
  • ( Chapter 4 )

24
OpenGL is a State Machine
  • Use current attribute, change it, use new
    attribute.

time1 glBegin( ... ) ... // Present color
? glEnd( )
time2 glColor3fv( Red ) // New color is
red
time3 glBegin( ... ) ... glEnd( )
25
Light
  • Visible Light in Electromagnetic Spectrum

red
green
yellow
blue
violet
ultraviolet
FM
infrared
AM
microwave
visible
X-ray
frequency (Hz)
104
106
108
1010
1012
1014
1016
1018
1020
26
Color
  • C(?) Strenght of wavelength ? in the color
    (energy distribution)
  • Additive color model
  • C(?) Sum of 3 colors energy
  • Three-color theory
  • C T1 R T2 G T3 B Desired color
  • T1, T2, T3 (Tristimulus Values) The numbers
    that specify the values of R, G, B

27
Human Visual System
28
Human Visual System
  • cones red, green, blue receptors
  • sensitivy curve of a cone Si(?)
  • brain perception values
  • three-color theory works for human eye
  • (Ared, Agreen, Ablue) three parameter of color

29
Color Model
  • Color model
  • Colors are different on a CRT, a film or a
    printer.
  • Color models RGB, CMY, YIQ, CIE,
  • Color gamut
  • The ranges of color produced by given system.
  • Color solid ( color cube) (Example)
  • Color model based on three primary colors.
  • Three primary color are three axis of a cube.
  • Color gamut is set of all points on the cube.

30
RGB color model
  • Red, Green, Blue
  • Tri-stimulus theory.
  • Additive system Adding ligths to blank points.
  • RGB cube has 3 axis (0 to 1).

31
CMY, CMYK color model
  • Hard copy systems printing, paiting ...
  • Subtractive system Addingcolors to white
    surface (expaper)
  • Convertion CMY to RGB, and RGB to CMY.
  • CMYK color model K (black) for cartridge
    saving.
  • Normally, cyan magenta yellow black
  • CMY can be used for dark gray.
  • But, (K) ink will be used for black.

32
RGB vs. CMY
  • RGB color system
  • Additive primaries
  • Adding ligths
  • For monitor, datashows
  • R, G, B lights.
  • Graphics system generally use RGB color system
  • CMY color system
  • Subtractive primiaries
  • Adding color pigments
  • For printer, plotter ...
  • C, M, Y inks.

33
Direct color system
  • Video card characteristics
  • Each pixel stored with RGB values on frame
    buffer
  • If frame buffer stores n bit for every values
  • 2n 2n 2n colors 23n colors
  • 3n 24 true color system
  • 8 bit for every RGB values (0255).
  • Frame buffer wold have over 3MB of memory that
    would have to be redisplay at video rates.

34
Direct color system
  • OpenGL functions
  • Video card has 3n system
  • OpenGL always use 0.0 1.0 values for red,
    green, blue.
  • It means, OpenGL is independent of hardware.
  • glColor()
  • For setting colors.

35
Direct color system
  • RGBA color model
  • RGB A (alpha channel opacity value)
  • A 1.0 is for invisible objects.
  • glColor4f(red, green, blue, alpha)
  • Clearing system to color (i.e. pure white with
    alpha value of 0.0)
  • glClearColor(1.0, 1.0, 1.0, 0.0)glClear(GL_COLO
    R_BUFFER_BIT).

36
Indexed color system
  • If the frame buffer is limited in depth (i.e.
    each pixel is only 8-bits deep), then we can
    select colors by interpreting our limited depth
    pixels as indices, rather than as color values.
  • The indices point to a color-lookup table.
  • Example
  • For a frame buffer that has k-bits per pixel,
    each pixel index is a value from 0 to 2k-1.
  • Assume that the display can display colors with
    an accuracy of m (2m reds, 2m greens, 2m blues).

color-lookup table
37
Indexed color system
  • Why indexed color system ?
  • Image and frame buffer size is reduced.
  • Image file format GIF, BMP use this system.
  • OpenGL functions
  • Sets current color to LUTindex.glIndexi(index)
  • Change color at LUTindex.glutSetColor(index,
    red, green, blue)

38
OpenGL Blending
  • // destination
  • Draw the rectangle (dr, dg, db, da)
    glEnable(GL_BLEND)glBlendFunc(GL_ONE_MINUS_SRC_A
    LPHA, GL_SRC_ALPHA)
  • // source
  • Draw the triangle (sr, sg, sb, sa)
  • Dont forget disabling !glDisable(GL_BLEND)

39
Point Attributes
  • Point color size

Pixel size 1
40
Line Attributes
  • Line color, width style
  • glLineWidth ( width )
  • glLineStipple ( repeatFactor, pattern )
  • // 0x1c47 for dash-dot pattern
  • // binary 1110001000111
  • glEnable ( GL_LINE_STIPPLE )
  • ...
  • glDisable ( GL_LINE_STIPPLE )
  • See page 192 for example code.

41
Line Attributes
  • Implementation of line width

42
Smooth Lines ?
43
Fill-Area Attributes
  • Hollow, solid or patterned. GLubyte fillPattern
    0xff,0,0xff,0,...
  • glPolygonStipple ( fillPattern )
  • glEnable ( GL_POLYGON_STIPPLE ) ...
  • glDisable ( GL_POLYGON_STIPPLE )

44
Smoothed Fill Patterns
45
OpenGL Polygon Modes
  • glPolygonMode( face, displayMode ) (Example)
  • Face GL_FRONT, GL_BACK, GL_FRON_AND_BACK
  • Display Modes GL_POINT (Only edge
    points) GL_LINE (Wireframe) GL_FILL (Default)
  • glFrontFace( faceOrder ) // GL_CW or GL_CCW
    glEdgeFlag( flag ) // GL_TRUE or GL_FALSE for
    line mode

46
General Scan-Line Polygon-Fill Algorithm
  • Consider the following polygon
  • How do we know whether a given pixel on the
    scanline is inside or outside the polygon?

D
B
C
A
E
F
47
Polygon Rasterization
  • Inside-Outside PointsPoint a, c 1Point b, d
    -1if zero then fill
  • For edge E ?
  • For edges A and C?

Do not changes
48
Flood-Fill Algorithm
  • Set pixel to fill color value until bounds.
  • An interior point (x, y)
  • A boundary color
  • A fill color

Fill color
Boundary color
Interior point (x, y)
49
4-connected vs. 8-connected
  • 8-connected
  • 4-connected

50
Flood-Fill Algorithm
  • Rough algorithm for 4-connected case
  • void flood_fill4(int x, int y, Color fill, Color
    boundary) Color current getPixel(x, y)
  • if (current ? boundary current ? fill)
    setPixel(x, y, fill) flood_fill4(x1, y,
    fill, boundary) // recursion ! flood_fill4(x1,
    y, fill, boundary) flood_fill4(x, y1,
    fill, boundary) flood_fill4(x, y1, fill,
    boundary)

51
Character Attributes
52
Anti-aliasing
  • Aliasing Information loss due to low-frequency
    sampling Jagged or stair-step appearance
  • Anti-aliasing Modified Bresenhams line
    algorithm We put a pixels to yk, and lightened
    pixel yk-1 and yk1.

53
OpenGL Anti-aliasing
  • In RGB display mode
  • glEnable(mode) GL_POINT_SMOOTH GL_LINE_SMOOTH
    GL_POLYGON_SMOOTHAlso type these
    glEnable(GL_BLEND)glBlendFunc(GL_SRC_ALPHA, GL
    _ONE_MINUS_SRC_ALPHA)

54
Push/Pop Attributes
  • glPushAttrib( mode )
  • Modes GL_ALL_ATTRIB_BITS GL_POINT_BIT GL_LINE
    _BIT GL_POLYGON_BIT
  • glPopAttrib( )

Current Style glPushAttrib() // Change
attribute glPopAttrib()
Write a Comment
User Comments (0)
About PowerShow.com