the framebuffer
DESCRIPTION
The Framebuffer. 2004. 02. 17. Hyun-Chul Cho. 2.0. Pixel (2,1). 1.0. 2.0. 3.0. Buffer. Goal of a graphics program Draw pictures on the screen Screen Rectangular array of pixels. Buffers. Buffers Storage for all the pixels Framebuffer Color buffers Depth buffer Stencil buffer - PowerPoint PPT PresentationTRANSCRIPT
The FramebufferThe Framebuffer
2004. 02. 17.Hyun-Chul Cho
HyunChul Cho - KUCG - 2
BufferBuffer
Goal of a graphics programDraw pictures on the screen
ScreenRectangular array of pixels
Pixel(2,1)
2.0 3.0
1.0
2.0
HyunChul Cho - KUCG - 3
BuffersBuffers
BuffersStorage for all the pixels
FramebufferColor buffersDepth bufferStencil bufferAccumulation buffer
HyunChul Cho - KUCG - 4
Color BuffersColor Buffers
Contain either color-index or RGB color and alpha values
Buffers in OpenGLLeft and right color buffer
For stereoscopic viewing
Front and back color bufferFor double-buffered system
Auxiliary color buffers
HyunChul Cho - KUCG - 5
Other BuffersOther Buffers
Depth buffer (z-buffer)Store a depth value for each pixel
Distance to the eyeLarger value are overwritten by smaller value
Stencil bufferRestrict drawing to certain portions
Accumulation bufferStore RGBA color dataAccumulate the color data
HyunChul Cho - KUCG - 6
Clearing BuffersClearing Buffers
void glClearColor (GLclampf r, GLclampf g, GLclampf b, GLclampf alpha);
void glClearIndex (GLfloat index);void glClearDepth (GLclampd depth);void glClearStencil (GLint s);void glClearAccum (GLclampf r, GLclampf g, GLclampf b,
GLclampf alpha);
void glClear (GLbitfield mask);
Hardware!
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT );
HyunChul Cho - KUCG - 7
Selecting Color BuffersSelecting Color Buffers
select the buffers to be written
select the buffer as the source
void glDrawBuffer (GLenum mode);
GL_FRONT GL_FRONT_LEFT GL_AUXiGL_BACK GL_FONT_RIGHT GL_FRONT_AND_BACKGL_LEFT GL_BACK_LFET GL_NONEGL_RIGHT GL_BACK_RIGHT
void glReadBuffer (GLenum mode);
GL_FRONT GL_FRONT_LEFT GL_AUXiGL_BACK GL_FONT_RIGHTGL_LEFT GL_BACK_LFETGL_RIGHT GL_BACK_RIGHT
HyunChul Cho - KUCG - 8
Masking BuffersMasking Buffers
Mask – bit is writtenRed~alpha – component is writtenFlag – buffer is enabled for writing
void glIndexMask (GLuint mask );
void glColorMask (GLboolean red, GLboolean green, GLboolean blue,
GLboolean alpha);
void glDepthMask (GLboolean flag);
void glStencilMask (GLuint mask);
HyunChul Cho - KUCG - 9
Testing And OperationTesting And Operation
Scissor test
Alpha test
Stencil test
Depth test
Blending
Dithering
Logical operations
HyunChul Cho - KUCG - 10
Scissor TestScissor Test
Define a rectangular portion of window
Default – match the size of the window
void glScissor (GLint x, GLint y, GLsizei width, GLsizei height );
glEnable( GL_SCISSOR_TEST );
HyunChul Cho - KUCG - 11
Alpha TestAlpha Test
Compare the alpha value with refDefault
func - GL_ALWAYSref - 0
void glAlphaFunc (GLenum func, GLclampf ref );
glEnable( GL_ALPAH_TEST );
GL_NEVER GL_ALWAYS
GL_LESS GL_LEQUAL
GL_GREATER GL_GEQUAL
GL_NOTEQUAL GL_EQUAL
HyunChul Cho - KUCG - 12
Stencil TestStencil Test
void glStencilFunc (GLenum func, GLint ref, GLuint mask );
glEnable( GL_STENCIL_TEST );
GL_NEVER GL_ALWAYS
GL_LESS GL_LEQUAL
GL_GREATER GL_GEQUAL
GL_NOTEQUAL GL_EQUAL
void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass );
GL_KEEP GL_ZERO
GL_REPLACE GL_INVERT
GL_INCR GL_DECR
HyunChul Cho - KUCG - 13
Stencil TestStencil Test
glStencilFunc(GL_ALWAYS, 0x1, 0x1);glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);glBegin(GL_QUADS);
glVertex2f( -5.0, 0.0);glVertex2f( 0.0, 5.0);glVertex2f( 5.0, 0.0);glVertex2f( 0.0, -5.0);
glEnd();
glStencilFunc(GL_EQUAL, 0x1, 0x1);glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP);
DrawMesh();
HyunChul Cho - KUCG - 14
Depth TestDepth Test
Compare z-value with a value in the depth bufferDefault – GL_LESS
void glDepthFunc (GLenum func);
glEnable( GL_DEPTH_TEST );
GL_NEVER GL_ALWAYS
GL_LESS GL_LEQUAL
GL_GREATER GL_GEQUAL
GL_NOTEQUAL GL_EQUAL
HyunChul Cho - KUCG - 15
Blending And DitheringBlending And Dithering
Blending
DitheringImprove the color resolutionEx. in color index mode
the color index 4.460% of pixel painted with index 440% of pixel painted with index 5
HyunChul Cho - KUCG - 16
Logical OperationsLogical Operations
void glLogicOp (GLenum opcode);
glEnable( GL_INDEX_LOGIC_OP ); or
glEnable( GL_COLOR_LOGIC_OP );
Parameter Operation Parameter Operation
GL_CLEAR 0 GL_AND s & d
GL_COPY s GL_OR s | d
GL_NOOP d GL_NAND ~( s & d )
GL_SET 1 GL_NOR ~( s | d )
GL_COPY_INVERTED ~s GL_XOR s ^ d
GL_INVERT ~d GL_EQUIV ~( s ^ d )
GL_AND_REVERSE s & ~d GL_AND_INVERTED ~s & d
GL_OR_REVERSE s | ~d GL_OR_INVERTED ~s | d
HyunChul Cho - KUCG - 17
Accumulation BufferAccumulation Buffer
Higher precision (more bits per color)
Scene AntialiasingMotion BlurDepth of FieldMulti Shadows
void glAccum (GLenum op, GLfloat value );
GL_ACCUM GL_LOAD
GL_RETURN
GL_ADD GL_MULT
Now That You KnowNow That You Know
2004. 02. 17.Hyun-Chul Cho
HyunChul Cho - KUCG - 19
Error HandlingError Handling
Strongly recommendedCall glGetError() at least once in each display() routine
GLenum glGetError (void);
const GLubyte* gluErrorString (GLenum errorCode);
GLenum errCode;
const GLubyte *errString;
if( (errCode=glGetError())!=GL_NO_ERROR ) {
errString = gluErrorString( errCode );
fprintf( stderr, “OpenGL Error: %s\n”, errString);
}
HyunChul Cho - KUCG - 20
VersionVersion
const GLubyte* glGetString (GLenum name);
GL_VENDOR GL_RENDERER
GL_VERSION GL_EXTENSIONS
const GLubyte* gluGetString (GLenum name);
GLU_VERSION GLU_EXTENSIONS
HyunChul Cho - KUCG - 21
Translucency & Fade EffectTranslucency & Fade Effect
If not blending hardware
TranslucencyUse stipple patterns for translucency
Fade EffectDefine a series of polygon stipple patterns
HyunChul Cho - KUCG - 22
SelectionSelection
Redraw scene in the back buffer with object identifierSimply read back the pixel under the cursor
HyunChul Cho - KUCG - 23
ShadowShadow
Directional Light Point
zyx
zyxzz
yyzxy
xxxzy
zzyyxx
cdbdad
ddbdadbdad
ddcdcdadad
ddcdbdcdbd
ddscdsbdsa
000
0)()()( DS
),,( zyx dddD
),,( zyx sssS
HyunChul Cho - KUCG - 24
Hidden-Line RemovalHidden-Line Removal
Draw the outlinesFill the background color
Use polygon offsetUse Stencil Buffer
HyunChul Cho - KUCG - 25
Depth-Buffered ImagesDepth-Buffered Images
For complex static backgroundDraw an image with depth buffer value
Draw image’s depth-buffer valueSet writemask to 0Draw Stencil buffer
Draw the imageMasked by the stencil buffer
HyunChul Cho - KUCG - 26
Dirichlet Domains Dirichlet Domains (Voronoi Polygon(Voronoi Polygon))
Draw a cone with its apex
Precompute a cone’s depth in an imageUse the image as depth buffer value