Professional Documents
Culture Documents
Pixels and Buffers: CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science
Pixels and Buffers: CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science
Pixels and Buffers: CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science
pixel
Auxiliary color
buffers
} Color
buffers
memory
source frame buffer
(destination)
writing into frame buffer
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 7
Clearing Buffers
• glClear(Glbitfield mask)
• Clears the specified buffer
8
Masking Buffers
• Scissor
- Only draw in a rectangular portion of screen
- glScissor() – Specify rectangle
- Default rectangle matches window
• Depth
- Draw based on depth value and comparison
function
- glDepthFunc()– Specify comparison function
- Default is GL_LESS
13
Pixel Tests
• Stencil
- Draw based on values in stencil buffer, if
available and enabled
- Used for drawing into an irregular region of
color buffer
- glStencilFunc() – Specifies comparison
function, reference value and mask
- glStencilOp() – Specifies how fragments
can modify stencil buffer
- Used for reflections, capping and stippling
14
Opacity and Transparency
using Blending
• Opaque surfaces permit no light to pass through
• Transparent surfaces permit all light to pass
• Translucent surfaces pass some light
translucency = 1 – opacity (α)
opaque surface α =1
1
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 5
Physical Models
1
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 6
Writing Model for Blending
destination blending
factor Color Buffer
1
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 7
Blending Equation
1
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 9
Example
2
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 1
Order Dependency
2
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 2
Opaque and Translucent
Polygons
• Suppose that we have a group of polygons
some of which are opaque and some translucent
• How do we use hidden-surface removal?
• Opaque polygons block all polygons behind
them and affect the depth buffer
• Translucent polygons should not affect depth
buffer
- Render with glDepthMask(GL_FALSE) which makes
depth buffer read-only
• Sort polygons first to remove order dependency!
• Draw back to front
2
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 3
Dithering and Logical
Operations
• Dithering
- On some systems with limited
color resolution dithering may
be enabled (GL_DITHER)
- System/hardware-dependent
2
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 5
Logical Pixel Operations
26
Bit Writing Modes
replace XOR
OR
2
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 7
XOR mode
glReadPixels(x,y,width,height,format,type,myimage)
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 1
Formats & Types
• GL_RGB • GL_UNSIGNED_BYTE
• GL_RGBA • GL_BYTE
• GL_RED • GL_BITMAP
• GL_GREEN • GL_UNSIGNED_SHORT
• GL_BLUE • GL_SHORT
• GL_ALPHA • GL_UNSIGNED_INT
• GL_DEPTH_COMPONENT • GL_INT
• GL_LUMINANCE • GL_FLOAT
• GL_LUMINANCE_ALPHA • GL_UNSIGNED_BYTE_3_3_2
• GL_COLOR_INDEX • GL_UNSIGNED_INT_8_8_8_8
• GL_STENCIL_INDEX
• etc.
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 2
Deprecated Functionality
• glDrawPixels
• glCopyPixels
• glBitMap
• Replace by use of texture functionality,
glBltFrameBuffer, frame buffer objects
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 3
Render to Texture
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 5
Frame Buffer Object
• glGenFramebuffers() – Allocate
unused framebuffer object ids
• glBindFramebuffer() – Allocate
storage for framebuffer and specifies
read/write status
• Frame buffer parameters normally
determined by its attachments
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 6
Renderbuffers
• glFramebufferRenderbuffer() –
Attaches a renderbuffer to a framebuffer.
Specifies buffer type
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 8
Moving Pixels Around
3
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 9
• Go to RenderBuffer.cpp
4
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 0
Buffer Applications
4
1
Anti-aliasing
no overlap overlap
4
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 4
Area Averaging
4
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 5
Area Averaging
4
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 6
OpenGL Antialiasing
http://www.engin.swarthmore.edu/~jshin1
5
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 0
Picking
• Rectangular maps
- Easy to implement for many applications
- Divide screen into rectangular regions
menus
drawing area
• Jitter camera
• Each frustum has
common plane “in
focus”
• Accumulate & blend
images
http://www.cs.stevens.edu/~quynh
reflector
object
6
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 0
Render the Reflected
Geometry
• An important task: clip the reflected
geometry so it is only visible on the
reflector surface
- Beyond the reflector boundaries and in front of
reflector
front
side
http://www.cunny.org.uk
Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 65
Other Applications
• Compositing
• Image Filtering
(convolution)
• Motion effects
6
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 6
HW8 Suggestions
6
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 7
HW8 Suggestions
6
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 8