280 likes | 449 Views
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
E N D
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 HyunChul Cho - KUCG -
Buffers • Buffers • Storage for all the pixels • Framebuffer • Color buffers • Depth buffer • Stencil buffer • Accumulation buffer HyunChul Cho - KUCG -
Color Buffers • Contain either color-index or RGB color and alpha values • Buffers in OpenGL • Left and right color buffer • For stereoscopic viewing • Front and back color buffer • For double-buffered system • Auxiliary color buffers HyunChul Cho - KUCG -
Other Buffers • Depth buffer (z-buffer) • Store a depth value for each pixel • Distance to the eye • Larger value are overwritten by smaller value • Stencil buffer • Restrict drawing to certain portions • Accumulation buffer • Store RGBA color data • Accumulate the color data HyunChul Cho - KUCG -
Clearing Buffers • Hardware! 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); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT ); HyunChul Cho - KUCG -
Selecting Color Buffers • select the buffers to be written • select the buffer as the source void glDrawBuffer (GLenum mode); GL_FRONT GL_FRONT_LEFT GL_AUXi GL_BACK GL_FONT_RIGHT GL_FRONT_AND_BACK GL_LEFT GL_BACK_LFET GL_NONE GL_RIGHT GL_BACK_RIGHT void glReadBuffer (GLenum mode); GL_FRONT GL_FRONT_LEFT GL_AUXi GL_BACK GL_FONT_RIGHT GL_LEFT GL_BACK_LFET GL_RIGHT GL_BACK_RIGHT HyunChul Cho - KUCG -
Masking Buffers • Mask – bit is written • Red~alpha – component is written • Flag – 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 -
Testing And Operation Scissor test Alpha test Stencil test Depth test Blending Dithering Logical operations HyunChul Cho - KUCG -
Scissor Test • Define a rectangular portion of window • Default – match the size of the window glEnable( GL_SCISSOR_TEST ); void glScissor (GLint x, GLint y, GLsizei width, GLsizei height ); HyunChul Cho - KUCG -
Alpha Test • Compare the alpha value with ref • Default • func - GL_ALWAYS • ref - 0 glEnable( GL_ALPAH_TEST ); void glAlphaFunc (GLenum func, GLclampf ref ); GL_NEVER GL_ALWAYS GL_LESS GL_LEQUAL GL_GREATER GL_GEQUAL GL_NOTEQUAL GL_EQUAL HyunChul Cho - KUCG -
Stencil Test glEnable( GL_STENCIL_TEST ); void glStencilFunc (GLenum func, GLint ref, GLuint mask ); 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 -
Stencil 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 -
Depth Test • Compare z-value with a value in the depth buffer • Default – GL_LESS glEnable( GL_DEPTH_TEST ); void glDepthFunc (GLenum func); GL_NEVER GL_ALWAYS GL_LESS GL_LEQUAL GL_GREATER GL_GEQUAL GL_NOTEQUAL GL_EQUAL HyunChul Cho - KUCG -
Blending And Dithering • Blending • Dithering • Improve the color resolution • Ex. in color index mode • the color index 4.4 • 60% of pixel painted with index 4 • 40% of pixel painted with index 5 HyunChul Cho - KUCG -
Logical Operations glEnable( GL_INDEX_LOGIC_OP ); or glEnable( GL_COLOR_LOGIC_OP ); void glLogicOp (GLenum opcode); HyunChul Cho - KUCG -
Accumulation Buffer • Higher precision (more bits per color) • Scene Antialiasing • Motion Blur • Depth of Field • Multi Shadows void glAccum (GLenum op, GLfloat value ); GL_ACCUM GL_LOAD GL_RETURN GL_ADD GL_MULT HyunChul Cho - KUCG -
Now That You Know 2004. 02. 17. Hyun-Chul Cho
Error Handling • Strongly recommended • Call 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 -
Version 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 -
Translucency & Fade Effect • If not blending hardware • Translucency • Use stipple patterns for translucency • Fade Effect • Define a series of polygon stipple patterns HyunChul Cho - KUCG -
Selection • Redraw scene in the back buffer with object identifier • Simply read back the pixel under the cursor HyunChul Cho - KUCG -
Shadow • Directional Light • Point HyunChul Cho - KUCG -
Hidden-Line Removal • Draw the outlines • Fill the background color • Use polygon offset • Use Stencil Buffer HyunChul Cho - KUCG -
Depth-Buffered Images • For complex static background • Draw an image with depth buffer value • Draw image’s depth-buffer value • Set writemask to 0 • Draw Stencil buffer • Draw the image • Masked by the stencil buffer HyunChul Cho - KUCG -
Dirichlet Domains (Voronoi Polygon) • Draw a cone with its apex • Precompute a cone’s depth in an image • Use the image as depth buffer value HyunChul Cho - KUCG -