Computer Graphics - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Computer Graphics

Description:

Defining a bitmap pattern (or mask) glBitmap(width, height, x0, y0, xOffset, yOffset, bitShape) ... Bitmap font. glutBitmapCharacter (font, character) ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 23
Provided by: whu
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics


1
Computer Graphics
  • Week -4, Chapter three, Section 3-14-----3-24

2
Goals
  • Fill-area primitives
  • Pixel-array primitives and OpenGL pixel-array
    functions
  • Character primitives
  • OpenGL character functions
  • OpenGL display lists
  • OpenGL display-window reshape function

3
Fill-area primitives
  • A fill-area is an area that is considered as
    having interior.
  • Triangle plate is a fill-area
  • Triangle made of three ropes is not
  • Fill-are primitives are those geometric drawings
    to form triangles, polygons, etc.
  • Primitive fill areas are in general considered as
    planar surfaces.
  • Other fill areas or surface can be approximated
    by polygon surfaces. It is called surface
    tessellation, or fitting the surface with
    polygon mesh. Display of a surface in polygon
    mesh is called wire-frame.

4
Surface tessellation
Surface tessellation
Wire-frame of the surface
The whole collection of Polygons is called
polygon mesh
5
OpenGL fill-area functions (3-16)
  • Triangles
  • Independent traingles
  • glBegin(GL_TRIANGLES)
  • //requires 3, 6, 9, etc. many
    vertices.
  • glEnd()
  • Triangle strip
  • glBegin(GL_TRIANGLE_STRIP)
  • //requires 3, or more vertices.
  • glEnd()
  • Triangle fan
  • glBegin(GL_TRIANGLE_FAN)
  • //requires 3, or more vertices.
  • glEnd()
  • Polygons
  • glBegin(GL_POLYGON)
  • // requires three or more
    vertices
  • glEnd()
  • Quads
  • glBegin(GL_QUADS)

6
Examples
glBegin(GL_TRIANGLES) glVertex(p0)
glVertex(p1) glVertex(p2) glVertex(p3)
glVertex(p4) glVertex(p5) glEnd()
glBegin(GL_TRIANGLE_STRIP) glVertex(p0)
glVertex(p1) glVertex(p2) glVertex(p3)
glVertex(p4) glVertex(p5) glEnd()
7
Example
p1
glBegin(GL_TRIANGLE_FAN) glVertex(p0)
glVertex(p1) glVertex(p2) glVertex(p3)
glVertex(p4) glVertex(p5) glEnd()
p2
p0
p3
p4
p1
glBegin(GL_POLYGON) glVertex(p0)
glVertex(p1) glVertex(p2) glVertex(p3)
glVertex(p4) glVertex(p5) glEnd()
p0
p2
p3
p4
p5
8
Example
glBegin(GL_QUADS) glVertex(p0)
glVertex(p1) glVertex(p2) glVertex(p3)
glVertex(p4) glVertex(p5)
glVertex(p6) glVertex(p7) glEnd()
glBegin(GL_QUAD_STRIP) glVertex(p0)
glVertex(p1) glVertex(p2) glVertex(p3)
glVertex(p4) glVertex(p5)
glVertex(p6) glVertex(p7) glEnd()
9
Draw in opengl
  • Try codes

10
Polygon faces
  • Polygon representation
  • Front face and back face
  • Each can have different color
  • The order can be reset

11
OpenGL vertex arrays
  • Using glVertex3iv (GLint )
  • Using glVertex3fv(GLfloat )
  • Example Draw a cube
  • Glint pt83 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)
  • glVertex3iv(ptn1)
  • glVertex3iv(ptn2)
  • glVertex3iv(ptn3)
  • glVertex3iv(ptn4)
  • glEnd()
  • 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)

12
Using Vertex Array in OpenGL
  • Purpose to reduce function calls in server side.
  • Steps
  • Activate the vertex-array feature
  • Point to the location and data format
  • Display the routine
  • Example
  • glEnableClientState(GL_VERTEX_ARRAY)
  • glVertexPointer(3, GL_INT, 0, pt)
  • GLubyte vertIndex 6,2,3,7,5,1,0,
  • 4,7,3,1,5,4,0,2,6,2,0,1,3,7,5,4,6)
  • glDrawElements (GL_QUADS, 24,
  • GL_UNSIGNED_BYTE, vertIndex)

13
Pixel-array primitives
  • Display a shape defined by a rectangle array of
    color values, equivalently, display a pixmap.
  • The simplest case of it is the so-called mask
    whether or not a pixel is to be assigned a preset
    color.

14
Defining pixel-array patterns
  • Defining a bitmap pattern (or mask)
  • glBitmap(width, height, x0, y0, xOffset, yOffset,
    bitShape)
  • Example
  • GLubytes bitshape20 0x1c, 0x00, 0x1c, 0x00,
    0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0xff, 0x80,
    0x7f, 0x00, 0x3e, 0x00, 0x1x, 0x00, 0x08, 0x00)
  • glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
  • glRasterPos2i(3,4)
  • glBitmap(9, 10, 0.0, 0.0, 20.0, 15.0, bitshape)

0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
1
1
0
0
0
0
1
1
1
0
0
0
1
1
0
1
1
1
1
1
0
0
1
1
0
1
1
1
1
1
1
1
1
1
0
0
1
0
0
1
1
0
0
0
1
1
1
0
0
0
1
1
1
0
0
1
1
0
1
0
0
1
1
0
1
A bit pattern, defined in an array with 10 rows
and 9 columns, Is stored in 8-bit blocks of 10
rows With 16 bit values per row. It is displayed
on the monitor At (3,3).
15
Buffers
  • Storing colors (or color buffers)
  • When supporting stereoscopic view Left, right
  • When supporting double buffer animation Front,
    back pair for both left and right.
  • When none is supported, the default is front-left
    color buffer.
  • Symbolic constants GL_FRONT_LEFT,
    GL_FRONT_RIGHT, GL_BACK_LEFT, GL_BACK_RIGHT,
    GL_FRONT, GL_BACK, GL_LEFT, GL_RIGHT,
    GL_FRONT_AND_BACK.
  • Storing other pixel information
  • Depth buffer----object distances from the viewing
    position
  • Stencil buffer----boundary patterns for a scene.
  • Symbolic constants GL_DEPTH_COMPONENT,
    GL_STENCIL_INDEX.

16
Defining pixel-array patterns
  • Using glDrawPixels and glDrawBuffer function
  • glDrawPixels(width,height, dataFormat, dataType,
    pixMap)
  • glDrawPixels(128,128,GL_RGB, GL_UNSIGNED_BYTE,colo
    rShape)
  • glDrawBuffer(buffer)
  • Using glReadPixels and glReadBuffer function
  • glReadPixels(xmin,ymin,width,height,dataFormat,dat
    aType,array)
  • glReadBuffer(buffer)

17
Logic operator
  • glEnable(GL_COLOR_LOGIC_OP)
  • glLogicOp(logicOp)
  • Check out this example

18
Character primitives
  • Bitmap font
  • glutBitmapCharacter (font, character)
  • Fast to render, directly put into the frame
    buffer.
  • Example
  • glRasterPosition2i(x,y)
  • Char text H, e, l, l, o, ,,a,
    s, u, r, a, m, s
  • For(k0 klt12 k)
  • glutBitmapCharacter(GLUT_BITMAP_9_BY_15,textk
    )
  • Stroke font
  • glutStrokeCharacter(font, character)
  • The size and position is adjusted by the
    transfomration.
  • slower to render, draw it into the frame buffer.
  • Example
  • char str Hello, Golden Rams!
  • for(i0 iltstrlen(str) i)
  • glutStrokeCharacter(GLUT_STROKE_ROMAN,
    stri)

19
OpenGL display lists
  • To save an object description of fixed shape and
    size (We can still transform it later).
  • The commends are stored in the server-side, which
    reduces the transmit of those commands when the
    object is needed.
  • In a display list, no uncertain information can
    be included. Hence no variables and no commands
    that may change during execution.

20
Example for using display list
  • Refer to the example on Page 153
  • Const double TWO_PI 6.2831853
  • GLuint regHex
  • GLdouble theta
  • GLint x,y,k
  • regHex glGenLists(1)
  • glNewList(regHex, GL_COMPILE)
  • glBegin(GL_POLYGON)
  • for(k0 klt6 k)
  • theta TWO_PIk/6.0
  • x 200150cos(theta)
  • y 200150sin(theta)
  • glVertex2i(x,y)
  • glEnd()
  • glEndList()
  • glCallList(regHex)

21
Other features of Display lists
  • List base
  • Execute several lists
  • Delete lists

22
OpenGL reshape function
  • Adjust the display-window when it is reshaped.
  • Using function glutReshapeFunc(functionName) to
    define the callback.
  • Put it in main function.
  • Using the example in Page 156.
Write a Comment
User Comments (0)
About PowerShow.com