Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers.

Similar presentations


Presentation on theme: "Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers."— Presentation transcript:

1 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers

2 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Bitmaps 1/3 –A rectangular array of 0s and 1s. –Serves as a drawing mask for a corresponding rectangular portion of the window (not in the 3D space). –The most common use of bitmaps is for drawing characters on the screen. –OpenGL only support the lowest level of bitmap operations.  glRasterPos*() for setting the current raster position.  glBitmap() for drawing the bitmap.

3 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Bitmaps 2/3 –void glRasterPos{234}{sifd}v(TYPE x, TYPE y, TYPE z, TYPE w) –void glRasterPos{234}{sifd}v(TYPE* coords)  Set the current raster position.  The coordinate is the same as that of glVertex*() (the world coordinate).  You can get the current raster position by glGetFloatv(GL_CURRENT_RASTER_POSITION).

4 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Bitmaps 3/3 –void glBitmap(GLsizei width, GLsizei height, GLfloat x bo, GLfloat y bo, GLfloat x bi, GLfloat y bi, GLubyte *bitmap)  Draw the bitmap on the current raster position.  Bitmap is a pointer to the bitmap image.  width and height is the size, in pixels, of the bitmap.  x bo and y bo to define the origin of the bitmap.  x bi and y bi to define the increments that are added to the raster position.

5 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Images 1/2 –Similar to bitmap but contain more information for each pixel.  R,G,B color, alpha value, … –Image source  From file (no loaders for specific image formats)  From the frame buffer  From memory  Others…

6 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Images 2/2 –OpenGL provide three basic command for manipulating image data  glReadPixel(…) Read pixel data from the framebuffer rectangle.  glDrawPixel(…) Draw a rectangle of pixel data into buffer. The position is defined by glRasterPos*().  glCopyPixel(…) Copy pixel data from the framebuffer rectangle to another position of framebuffer.  See OpenGL Programming Guide for detail parameters.

7 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Remind –glRasterPos() sets the current raster position in world coordinate, but glBitmap(), gl*Pixel() commands draw the bitmap or image on the window coordinate after the transformations.  The detail pipeline procedures can be found in the OpenGL Programming Guide –For better performance, always use textures instead of bitmaps and images.

8 Tan-Chi Ho, CGGM Lab., CSIE of NCTU The Buffers OpenGL can manipulate the following buffers –Color Buffer  Front-left, front-right, back-left, back-right, and any number of auxiliary color buffers.  Left, right, and auxiliary color buffers are optional. –Depth Buffer –Stencil Buffer –Accumulation Buffer

9 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Operation of Buffers 1/4 How to enable buffer –OS dependent. –GLUT  Use glutInitDisplayMode(int modes) GLUT_SINGLE for single color buffer, GLUT_DOUBLE for double buffer. GLUT_DEPTH for depth buffer GLUT_ACCUM for accumulation buffer GLUT_STENCIL for stencil buffer See GLUT manual for more detail.  Ex. glutInitDisplayMode(GL_SINGLE | GL_DEPTH);

10 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Operation of Buffers 2/4 Clearing Buffers –glClearColor(…) –glClearIndex(…) –glClearDepth(…) –glClearStencil(…) –glClearAccum(…)  Specify the clearing values for each buffer.  Parameters of each command is the values.  For depth buffer, the default value is 1.0

11 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Operation of Buffers 3/4 –use glClear() to clear the buffer to the specify values. –glClear(GLbitfield mask)  mask can be combine by logical OR of GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT, GL_ACCUM_BUFFER_BIT. Ex. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

12 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Operation of Buffers 4/4 Masking Buffers –glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) –glDepthMask(GLboolean flag) –glStencilMask(GLuint mask)  Set the masks used to control writing into the indicated buffers.

13 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Color Buffer 1/5 –Store the color value to be seen on screen. –All OpenGL implementations support double- buffering (front and back buffers). –Some OpenGL implementations also support stereoscopic viewing (left and right buffers) and non-displayable auxiliary color buffers.  Use glGetBooleanv() with parameters GL_STEREO or GL_DOUBLEBUFFER to find if your system supports stereo or double-buffering.  Use glGetIntegerv() with GL_AUX_BUFFERS to find how many auxiliary color buffers are supported.

14 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Color Buffer 2/5 Select Color buffer for Writing and Reading –void glDrawBuffer(GLenum mode)  Select the color buffers enabled for writing or clearing.  More than one buffers can be enable at one time.  mode can be GL_FRONT, GL_LEFT, GL_BACK, GL_RIGHT, GL_FRONT_LEFT, GL_AUXi, GL_FRONT_AND_BACK, GL_NONE, … Omit LEFT and RIGHT refer to both left and right buffers. By default, GL_FRONT for single buffer and GL_BACK for double buffer.

15 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Color Buffer 3/5 –void glReadBuffer(GLenum mode)  Select the color buffers enabled as the source for reading pixels.  The same parameters as that of glDrawBuffer() but one buffer can be enabled at one time.

16 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Color Buffer 4/5 Alpha test –Allow you to accept or reject a fragment based on its alpha value. –To use alpha test, enable it using glEnable(GL_ALPHA_TEST). –Use glAlphaFunc() to define the comparison function of the alpha value.

17 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Color Buffer 5/5 –glAlphaTest(GLenum func, GLclampf ref)  Set the reference value and comparison function for the alpha test.  ref is clamped from 0.0 to 1.0. paramMeaning GL_NEVERnever accept the fragment GL_ALWAYSalways accept the fragment GL_LESSaccept fragment if its alpha < reference alpha GL_LEQUALaccept fragment if its alpha <= reference alpha GL_EQUALaccept fragment if its alpha = reference alpha GL_GEQUALaccept fragment if its alpha >= reference alpha GL_GREATERaccept fragment if its alpha > reference alpha GL_NOTEQUALaccept fragment if its alpha != reference alpha

18 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Depth Buffer 1/2 –Store the depth values for each pixel. –The range is from 0.0 to 1.0. –Larger values will be replaced with smaller ones. –See hidden-surface removal for more detail. –Also called Z-Buffer

19 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Depth Buffer 2/2 Depth test –To use the depth buffer, you should enable the depth test first by glEnable(GL_DEPTH_TEST). –For special purpose, you can choose a different comparison function with glDepthFunc(). –void glDepthFunc(GLenum func)  Set the comparison function for the depth test.  func is the same as alpha test.  Default is GL_LESS.

20 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 1/8 –To restrict drawing to certain portions of the screen. –Prevents anything that would not be visible through the windshield from being drawn.

21 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 2/8 The use of Stencil Buffer –To restrict the drawing –To produce shadows –Hidden-line removal –Others…  See OpenGL Programming Guide Chap. 14 for more detail.

22 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 3/8 Scissor test –Define a rectangular portion of the window and restrict drawing to take place within it. –glScissor(GLint x, GLint y, GLint width, GLint height)  Set the location and size of scissor.

23 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 4/8 Stencil test –Enable the stencil test first by glEnable(GL_STENCIL_TEST). –Use glStencilFunc() to choose the comparison function and glStencilOp() for the modification of the buffer.

24 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 5/8 –void glStencilFunc(GLenum func, GLint ref, GLuint mask)  Set the comparison function for the stencil test with reference value (ref) and mask.  ref is compared to the value in the stencil buffer.  Func is the same as glDepthFunc(). GL_LESS means that if ref is less than the value and mask is true, in the stencil buffer, the fragment is passed. Default is GL_ALWAYS (always pass).

25 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 6/8 –void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)  Specify how the data in the stencil buffer is modified when a fragment passes or fails the stencil test.  fail is applied when the fragment fails the stencil test.  zfail is applied when the it passes the stencil test but fails the depth test.  zpass is applied when both passes stencil and depth tests.

26 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 7/8 paramMeaning GL_KEEPkeep the current value GL_ZEROset the value in stencil buffer to zero GL_REPLACEset the value in stencil buffer to ref in glStencilFunc() GL_INCRincrease the current value in stencil buffer GL_DECRdecrease the current value in stencil buffer GL_INVERTbitwise inverse the current value in stencil buffer

27 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Stencil Buffer 8/8 Example –Advanced OpenGL Programming 97  dissolve.c dissolve.c

28 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 1/8 –Store the same values as color buffer, but can accumulate the color value several times. –Can be used as the following  Full scene antialiasing  Motion blur  Depth of field  Soft shadow

29 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 2/8 Operation of accumulation buffer –OpenGL do not write directly into the accumulation buffer. –A series of images is generated in one of the standard color buffers, and are accumulated, one at time, into the accumulation buffer. –When the accumulation is finished, the result ins copied back into a color buffer for viewing.

30 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 3/8 –To control the accumulation buffer, using glAccum(). –glAccum(GLenum op, GLfloat value)  Control the accumulation buffer.  op is used to select the operation.

31 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 4/8 opMeaning GL_ACCUMread each pixel from the buffer currently selected for reading with glReadBuffer(), multiplies the R, G, B, and alpha values by value, then add the result to accumulation buffer. GL_LOADthe same as GL_ACCUM, but replace the value in accumulation rather than add. GL_RETURNread values from the accumulation buffer, multiplies them by value, and places the result in the color buffers. GL_ADD / GL_MULTsimply add / multiply the values of each pixel in the accumulation buffer by value, and return to the accumulation buffer. (GL_MULT will clamp value from –1.0 to 1.0 while GL_ADD will not.)

32 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 5/8 Full scene antialiasing –Clear the accumulation buffer and enable the front buffer for reading and writing. –Loop several times with jitters and draw the images.  Jittering is moving the image to a slightly different position. –Accumulating the data with glAccum(GL_ACCUM, 1.0/n), n is current loop time. –Finally, call glAccum(GL_RETURN, 1.0) to draw back to color buffer.

33 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 6/8 Motion blur –Some stationary and some moving objects in scene, and blurs the moving objects with a small interval of time over the moving direction. –Using glAccum(GL_MULT, decayFactor)  dacayFactor is a number between 0.0 and 1.0.  The smaller number cause the objects to appear to moving faster.

34 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 7/8 Depth of Field –The farther an item is from the focus plane, the more out of focus it is. –Draw the scene repeatedly using calls with different argument values to glFrustum(). –Accumulating the result. Soft shadow –See OpenGL programming guide for more detail.

35 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Accumulation Buffer 8/8 Example –OpenGL Programming Guide  Depth of Field dof.cdof.c  Scene antialiasing accpersp.caccpersp.c –Advanced OpenGL Programming 97  Soft shadow softshadow2.csoftshadow2.c

36 Tan-Chi Ho, CGGM Lab., CSIE of NCTU Any Question? ?


Download ppt "Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers."

Similar presentations


Ads by Google