Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Framebuffer 2004. 02. 17. Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array.

Similar presentations


Presentation on theme: "The Framebuffer 2004. 02. 17. Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array."— Presentation transcript:

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

2 HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array of pixels Pixel (2,1) 2.03.0 1.0 2.0

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

4 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

5 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

6 HyunChul Cho - KUCG -6 Clearing 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 );

7 HyunChul Cho - KUCG -7 Selecting Color Buffers select the buffers to be written select the buffer as the source void glDrawBuffer (GLenum mode); GL_FRONTGL_FRONT_LEFTGL_AUX i GL_BACKGL_FONT_RIGHT GL_FRONT_AND_BACK GL_LEFTGL_BACK_LFETGL_NONE GL_RIGHTGL_BACK_RIGHT void glReadBuffer (GLenum mode); GL_FRONTGL_FRONT_LEFTGL_AUX i GL_BACKGL_FONT_RIGHT GL_LEFTGL_BACK_LFET GL_RIGHTGL_BACK_RIGHT

8 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);

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

10 HyunChul Cho - KUCG -10 Scissor 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 );

11 HyunChul Cho - KUCG -11 Alpha Test Compare the alpha value with ref Default func- GL_ALWAYS ref- 0 void glAlphaFunc (GLenum func, GLclampf ref ); glEnable( GL_ALPAH_TEST ); GL_NEVERGL_ALWAYS GL_LESSGL_LEQUAL GL_GREATERGL_GEQUAL GL_NOTEQUALGL_EQUAL

12 HyunChul Cho - KUCG -12 Stencil Test void glStencilFunc (GLenum func, GLint ref, GLuint mask ); glEnable( GL_STENCIL_TEST ); GL_NEVERGL_ALWAYS GL_LESSGL_LEQUAL GL_GREATERGL_GEQUAL GL_NOTEQUALGL_EQUAL void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass ); GL_KEEPGL_ZERO GL_REPLACEGL_INVERT GL_INCRGL_DECR

13 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();

14 HyunChul Cho - KUCG -14 Depth Test Compare z-value with a value in the depth buffer Default – GL_LESS void glDepthFunc (GLenum func); glEnable( GL_DEPTH_TEST ); GL_NEVERGL_ALWAYS GL_LESSGL_LEQUAL GL_GREATERGL_GEQUAL GL_NOTEQUALGL_EQUAL

15 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

16 HyunChul Cho - KUCG -16 Logical Operations void glLogicOp (GLenum opcode); glEnable( GL_INDEX_LOGIC_OP ); or glEnable( GL_COLOR_LOGIC_OP ); ParameterOperationParameterOperation GL_CLEAR0GL_ANDs & d GL_COPYsGL_ORs | d GL_NOOPdGL_NAND~( s & d ) GL_SET1GL_NOR~( s | d ) GL_COPY_INVERTED~sGL_XORs ^ d GL_INVERT~dGL_EQUIV~( s ^ d ) GL_AND_REVERSEs & ~dGL_AND_INVERTED~s & d GL_OR_REVERSEs | ~dGL_OR_INVERTED~s | d

17 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_ACCUMGL_LOAD GL_RETURN GL_ADDGL_MULT

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

19 HyunChul Cho - KUCG -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); }

20 HyunChul Cho - KUCG -20 Version const GLubyte* glGetString (GLenum name); GL_VENDORGL_RENDERER GL_VERSIONGL_EXTENSIONS const GLubyte* gluGetString (GLenum name); GLU_VERSIONGLU_EXTENSIONS

21 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

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

23 HyunChul Cho - KUCG -23 Shadow Directional Light Point

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

25 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

26 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


Download ppt "The Framebuffer 2004. 02. 17. Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array."

Similar presentations


Ads by Google