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

Slides:



Advertisements
Similar presentations
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Advertisements

The Buffers and Operations
OpenGL Buffers and Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, February 8, 2002.
Framebuffer in OpenGL MAE152 Computer Graphics for Scientists and Engineers Fall 03.
OpenGL Fragment Operations
Graphics Pipeline.
1 Buffers and Processing Fragments 2011 Autumn Animação e Visualização Tridimensional 2011/2012.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
University of Sulaimani - School of Science - Computer Dept.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Chapter 6. More on Color and Material Presented by Garrett Yeh.
Buffers Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Buffers Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
CH7 Buffers and Blending. Blending Example 1/6 #include #include "glut.h" GLfloat alpha = 0.0; GLfloat pos[4] = {0, 10, 10, 0}; GLfloat dif_l[4] = {1.0,
Introduction to OpenGL (Part 3) Ref: OpenGL Programming Guide (The Red Book)
CS 4731: Computer Graphics Lecture 21: Raster Graphics Part 2 Emmanuel Agu.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
Jittering, Introduction to Stenciling Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, February 6, 2004.
Computer Graphics Mirror and Shadows
 Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.  Applications:
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
2002 by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data:
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
1 10/24/ :01 UML Graphics II Shadows Session 4.
Advanced OpenGL Technique Jian Huang, CS 594, Fall 2002 Redbook: Chapters 6.1, 9.5, 9.6, 10.
Review of OpenGL Basics
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
CH7 Buffers and Blending. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
Buffers Computer Graphics I, Fall 2010.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Buffers, Compositing and Blending Week 8 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004.
Buffers. 2 Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
The Framebuffer Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Buffers Ed Angel Professor Emeritus of Computer Science
Stenciling Effects Glenn G. Chappell
Draw a Simple Object.
Computer Graphics Lecture 33
Multiple-pass Reflection Depth of Field
OpenGL Buffers and Tests
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
Geb Thomas Adapted from the OpenGL Programming Guide
Class 26 more textures environmental textures Color ramps
Introduction to OpenGL
Computer Graphics Buffers
Computer Graphics Practical Lesson 9
Buffers Ed Angel Professor Emeritus of Computer Science
Chapter X Output Merger.
Ref: OpenGL Programming Guide (The Red Book)
The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007.
Class 27 more textures environmental textures Color ramps
Stencil Buffer & Decals
Presentation transcript:

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

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.

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

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.

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…

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.

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.

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

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

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

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

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.

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.

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.

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.

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.

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

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

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.

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.

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.

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.

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.

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

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.

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

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

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

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.

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.

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

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.

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.

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.

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

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