1 / 26

The Framebuffer

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

elana
Download Presentation

The Framebuffer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Framebuffer 2004. 02. 17. Hyun-Chul Cho

  2. 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 -

  3. Buffers • Buffers • Storage for all the pixels • Framebuffer • Color buffers • Depth buffer • Stencil buffer • Accumulation buffer HyunChul Cho - KUCG -

  4. 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 -

  5. 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 -

  6. 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 -

  7. 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 -

  8. 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 -

  9. Testing And Operation Scissor test Alpha test Stencil test Depth test Blending Dithering Logical operations HyunChul Cho - KUCG -

  10. 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 -

  11. 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 -

  12. 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 -

  13. 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 -

  14. 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 -

  15. 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 -

  16. Logical Operations glEnable( GL_INDEX_LOGIC_OP ); or glEnable( GL_COLOR_LOGIC_OP ); void glLogicOp (GLenum opcode); HyunChul Cho - KUCG -

  17. 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 -

  18. Now That You Know 2004. 02. 17. Hyun-Chul Cho

  19. 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 -

  20. 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 -

  21. 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 -

  22. Selection • Redraw scene in the back buffer with object identifier • Simply read back the pixel under the cursor HyunChul Cho - KUCG -

  23. Shadow • Directional Light • Point HyunChul Cho - KUCG -

  24. Hidden-Line Removal • Draw the outlines • Fill the background color • Use polygon offset • Use Stencil Buffer HyunChul Cho - KUCG -

  25. 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 -

  26. 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 -

More Related