Pixel Operations and Buffers - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Pixel Operations and Buffers

Description:

Specify the clearing values for each buffer. Parameters of each command is the values. ... Select the color buffers enabled for writing or clearing. ... – PowerPoint PPT presentation

Number of Views:166
Avg rating:3.0/5.0
Slides: 37
Provided by: dan113
Category:

less

Transcript and Presenter's Notes

Title: Pixel Operations and Buffers


1
Pixel Operations and Buffers
2
Bitmaps1/3
  • A rectangular array of 0s and 1s.
  • Serves as a drawing mask for a corresponding
    rectangular portion of the window (not in the 3D
    space).
  • The most common use of bitmaps is for drawing
    characters on the screen.
  • OpenGL only support the lowest level of bitmap
    operations.
  • glRasterPos() for setting the current raster
    position.
  • glBitmap() for drawing the bitmap.

3
Bitmaps2/3
  • void glRasterPos234sifdv(TYPE x, TYPE y, TYPE
    z, TYPE w)
  • void glRasterPos234sifdv(TYPE coords)
  • Set the current raster position.
  • The coordinate is the same as that of glVertex()
    (the world coordinate).
  • You can get the current raster position by
    glGetFloatv(GL_CURRENT_RASTER_POSITION).

4
Bitmaps3/3
  • void glBitmap(GLsizei width, GLsizei height,
    GLfloat xbo, GLfloat ybo, GLfloat xbi, GLfloat
    ybi, GLubyte bitmap)
  • Draw the bitmap on the current raster position.
  • Bitmap is a pointer to the bitmap image.
  • width and height is the size,
  • in pixels, of the bitmap.
  • xbo and ybo to define the
  • origin of the bitmap.
  • xbi and ybi to define the
  • increments that are added
  • to the raster position.

5
Images1/2
  • Similar to bitmap but contain more information
    for each pixel.
  • R,G,B color, alpha value,
  • Image source
  • From file (no loaders for specific image formats)
  • From the frame buffer
  • From memory
  • Others

6
Images2/2
  • OpenGL provide three basic command for
    manipulating image data
  • glReadPixel()
  • Read pixel data from the framebuffer rectangle.
  • glDrawPixel()
  • Draw a rectangle of pixel data into buffer.
  • The position is defined by glRasterPos().
  • glCopyPixel()
  • Copy pixel data from the framebuffer rectangle to
    another position of framebuffer.
  • See OpenGL Programming Guide for detail
    parameters.

7
Remind
  • glRasterPos() sets the current raster position in
    world coordinate, but glBitmap(), glPixel()
    commands draw the bitmap or image on the window
    coordinate after the transformations.
  • The detail pipeline procedures can be found in
    the OpenGL Programming Guide
  • For better performance, always use textures
    instead of bitmaps and images.

8
The Buffers
  • OpenGL can manipulate the following buffers
  • Color Buffer
  • Front-left, front-right, back-left, back-right,
    and any number of auxiliary color buffers.
  • Left, right, and auxiliary color buffers are
    optional.
  • Depth Buffer
  • Stencil Buffer
  • Accumulation Buffer

9
Operation of Buffers1/4
  • How to enable buffer
  • OS dependent.
  • GLUT
  • Use glutInitDisplayMode(int modes)
  • GLUT_SINGLE for single color buffer, GLUT_DOUBLE
    for double buffer.
  • GLUT_DEPTH for depth buffer
  • GLUT_ACCUM for accumulation buffer
  • GLUT_STENCIL for stencil buffer
  • See GLUT manual for more detail.
  • Ex. glutInitDisplayMode(GL_SINGLE GL_DEPTH)

10
Operation of Buffers2/4
  • Clearing Buffers
  • glClearColor()
  • glClearIndex()
  • glClearDepth()
  • glClearStencil()
  • glClearAccum()
  • Specify the clearing values for each buffer.
  • Parameters of each command is the values.
  • For depth buffer, the default value is 1.0

11
Operation of Buffers3/4
  • use glClear() to clear the buffer to the specify
    values.
  • glClear(GLbitfield mask)
  • mask can be combine by logical OR of
    GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT,
    GL_STENCIL_BUFFER_BIT, GL_ACCUM_BUFFER_BIT.
  • Ex. glClear(GL_COLOR_BUFFER_BIT
    GL_DEPTH_BUFFER_BIT)

12
Operation of Buffers4/4
  • Masking Buffers
  • glColorMask(GLboolean red, GLboolean green,
    GLboolean blue, GLboolean alpha)
  • glDepthMask(GLboolean flag)
  • glStencilMask(GLuint mask)
  • Set the masks used to control writing into the
    indicated buffers.

13
Color Buffer1/5
  • Store the color value to be seen on screen.
  • All OpenGL implementations support
    double-buffering (front and back buffers).
  • Some OpenGL implementations also support
    stereoscopic viewing (left and right buffers) and
    non-displayable auxiliary color buffers.
  • Use glGetBooleanv() with parameters GL_STEREO or
    GL_DOUBLEBUFFER to find if your system supports
    stereo or double-buffering.
  • Use glGetIntegerv() with GL_AUX_BUFFERS to find
    how many auxiliary color buffers are supported.

14
Color Buffer2/5
  • Select Color buffer for Writing and Reading
  • void glDrawBuffer(GLenum mode)
  • Select the color buffers enabled for writing or
    clearing.
  • More than one buffers can be enable at one time.
  • mode can be GL_FRONT, GL_LEFT, GL_BACK, GL_RIGHT,
    GL_FRONT_LEFT, GL_AUXi, GL_FRONT_AND_BACK,
    GL_NONE,
  • Omit LEFT and RIGHT refer to both left and right
    buffers.
  • By default, GL_FRONT for single buffer and
    GL_BACK for double buffer.

15
Color Buffer3/5
  • void glReadBuffer(GLenum mode)
  • Select the color buffers enabled as the source
    for reading pixels.
  • The same parameters as that of glDrawBuffer() but
    one buffer can be enabled at one time.

16
Color Buffer4/5
  • Alpha test
  • Allow you to accept or reject a fragment based on
    its alpha value.
  • To use alpha test, enable it using
    glEnable(GL_ALPHA_TEST).
  • Use glAlphaFunc() to define the comparison
    function of the alpha value.

17
Color Buffer5/5
  • glAlphaTest(GLenum func, GLclampf ref)
  • Set the reference value and comparison function
    for the alpha test.
  • ref is clamped from 0.0 to 1.0.

18
Depth Buffer1/2
  • Store the depth values for each pixel.
  • The range is from 0.0 to 1.0.
  • Larger values will be replaced with smaller ones.
  • See hidden-surface removal for more detail.
  • Also called Z-Buffer

19
Depth Buffer2/2
  • Depth test
  • To use the depth buffer, you should enable the
    depth test first by glEnable(GL_DEPTH_TEST).
  • For special purpose, you can choose a different
    comparison function with glDepthFunc().
  • void glDepthFunc(GLenum func)
  • Set the comparison function for the depth test.
  • func is the same as alpha test.
  • Default is GL_LESS.

20
Stencil Buffer1/8
  • To restrict drawing to certain portions of the
    screen.
  • Prevents anything that would not be visible
    through the windshield from being drawn.

21
Stencil Buffer2/8
  • The use of Stencil Buffer
  • To restrict the drawing
  • To produce shadows
  • Hidden-line removal
  • Others
  • See OpenGL Programming Guide Chap. 14 for more
    detail.

22
Stencil Buffer3/8
  • Scissor test
  • Define a rectangular portion of the window and
    restrict drawing to take place within it.
  • glScissor(GLint x, GLint y, GLint width, GLint
    height)
  • Set the location and size of scissor.

23
Stencil Buffer4/8
  • Stencil test
  • Enable the stencil test first by
    glEnable(GL_STENCIL_TEST).
  • Use glStencilFunc() to choose the comparison
    function and glStencilOp() for the modification
    of the buffer.

24
Stencil Buffer5/8
  • void glStencilFunc(GLenum func, GLint ref, GLuint
    mask)
  • Set the comparison function for the stencil test
    with reference value (ref) and mask.
  • ref is compared to the value in the stencil
    buffer.
  • Func is the same as glDepthFunc().
  • GL_LESS means that if ref is less than the value
    and mask is true, in the stencil buffer, the
    fragment is passed.
  • Default is GL_ALWAYS (always pass).

25
Stencil Buffer6/8
  • void glStencilOp(GLenum fail, GLenum zfail,
    GLenum zpass)
  • Specify how the data in the stencil buffer is
    modified when a fragment passes or fails the
    stencil test.
  • fail is applied when the fragment fails the
    stencil test.
  • zfail is applied when the it passes the stencil
    test but fails the depth test.
  • zpass is applied when both passes stencil and
    depth tests.

26
Stencil Buffer7/8
27
Stencil Buffer8/8
  • Example
  • Advanced OpenGL Programming 97
  • dissolve.c

28
Accumulation Buffer1/8
  • Store the same values as color buffer, but can
    accumulate the color value several times.
  • Can be used as the following
  • Full scene antialiasing
  • Motion blur
  • Depth of field
  • Soft shadow

29
Accumulation Buffer2/8
  • Operation of accumulation buffer
  • OpenGL do not write directly into the
    accumulation buffer.
  • A series of images is generated in one of the
    standard color buffers, and are accumulated, one
    at time, into the accumulation buffer.
  • When the accumulation is finished, the result ins
    copied back into a color buffer for viewing.

30
Accumulation Buffer3/8
  • To control the accumulation buffer, using
    glAccum().
  • glAccum(GLenum op, GLfloat value)
  • Control the accumulation buffer.
  • op is used to select the operation.

31
Accumulation Buffer4/8
32
Accumulation Buffer5/8
  • Full scene antialiasing
  • Clear the accumulation buffer and enable the
    front buffer for reading and writing.
  • Loop several times with jitters and draw the
    images.
  • Jittering is moving the image to a slightly
    different position.
  • Accumulating the data with glAccum(GL_ACCUM,
    1.0/n), n is current loop time.
  • Finally, call glAccum(GL_RETURN, 1.0) to draw
    back to color buffer.

33
Accumulation Buffer6/8
  • Motion blur
  • Some stationary and some moving objects in scene,
    and blurs the moving objects with a small
    interval of time over the moving direction.
  • Using glAccum(GL_MULT, decayFactor)
  • dacayFactor is a number between 0.0 and 1.0.
  • The smaller number cause the objects to appear to
    moving faster.

34
Accumulation Buffer7/8
  • Depth of Field
  • The farther an item is from the focus plane, the
    more out of focus it is.
  • Draw the scene repeatedly using calls with
    different argument values to glFrustum().
  • Accumulating the result.
  • Soft shadow
  • See OpenGL programming guide for more detail.

35
Accumulation Buffer8/8
  • Example
  • OpenGL Programming Guide
  • Depth of Field dof.c
  • Scene antialiasing accpersp.c
  • Advanced OpenGL Programming 97
  • Soft shadow softshadow2.c

36
Any Question?
  • ?
Write a Comment
User Comments (0)
About PowerShow.com