MyFramebuffer

advertisement
MAE152
Computer Graphics for Scientists and Engineers
Fall 03
Framebuffer in OpenGL
Rasterization
What is Rasterization?
•
Is a process by which a primitive is converted to
a 2D imge
 First, it determines which squares of an integer grid in
window coordinates are occupied by the primitive
 Assign a color and a depth value to each square
•
A grid square along with its assigned color and
depth is called a fragment
•
The results of the process are passed to the next
stage of per-fragment operations
Framebuffer
Video Memory
•
Before an image can be sent to a display device, it must
be first represented as a bitmap in an area of video
memory called the frame buffer. The amount of video
memory, therefore, dictates the maximum resolution and
color depth available
•
In a conventional video adapter, the bitmap to be
displayed is first generated by the main processor and
then sent to the frame buffer. Most modern video
adapters use graphics accelerators that have their own
processors capable of manipulating bitmaps and graphics
objects. A separate memory area is reserved for such
operations
Video Memory
•
Graphics systems place heavy demands on video
memory, therefore, video memory needs to be much
faster than main memory
•
Most video memory is dual-ported or bi-directional, and
capable of transferring data between the video memory
and the video processor simultaneously while another set
of data is being transferred to the display device
•
There are many different types of video memory, including:




VRAM: Video RAM - dual-ported memory
WRAM: Windows RAM - dual-ported windowed memory
RDRAM: A type of memory developed by Rambus Inc.
SGRAM: Synchronous Graphic Random Access Memory, singleported, capable of opening two memory pages at once
The Frame Buffer
•
The portion of memory reserved for holding the bitmapped image that is sent to the display device is called
the frame buffer
•
Typically the frame buffer is stored on the video
adapter’s memory chips. In some cases, the video chipset
is integrated into the motherboard, and the frame buffer is
stored in main memory
•
The frame buffer is a bit-map that contains among other
things the color depth or bit depth which defines the
number of distinct colors in the graphics subsystem
•
A 24-bit video adapter, has a color depth of 2^24 (~16.7
million) colors. It follows that its color depth is 24 bits
Buffer
Define a buffer by its spatial resolution (n x m) and its depth
k, the number of bits/pixel
pixel
Framebuffer
Rasterization
Transformation
Pipeline
Application
The OpenGL Pipeline
(The Macroscopic View)
A Closer Look at OpenGL’s Rasterization
Pipeline
Point
Rasterization
Line
Rasterization
Triangle
Rasterization
Texture
Mapping
Engine
Color Sum
(Sep. Specular
Color)
Fog
Engine
Bitmap
Rasterization
Pixel
Rectangle
Rasterization
To
Fragment Tests
A Closer Look at OpenGL’s Rasterization
Pipeline (cont.)
(from previous
stages)
Pixel
Ownership
Test
Depth
Buffer
Test
Scissor
Test
Blending
Alpha
Test
Stencil
Test
Dithering
Logical
Operations
Framebuffer
Fragments
OpenGL Frame Buffer
OpenGL Buffers
• Color buffers can be displayed
Front
Back
Auxiliary
Overlay
• Depth
• Accumulation
High resolution buffer
• Stencil
Holds masks
Writing in Buffers
•
•
Conceptually, we can consider all of memory as a large twodimensional array of pixels
We read and write rectangular block of pixels

•
Bit block transfer (bitblt) operations
The frame buffer is part of this memory
memory
source
writing into frame buffer
frame buffer
(destination)
Writing Model
Read destination pixel before writing source
Writing Modes
•
•
Source and destination bits are combined bitwise
16 possible functions (one per column in table)
replace
XOR
OR
XOR mode
•
•
We can use XOR by enabling logic operations and selecting
the XOR write mode
XOR is especially useful for swapping blocks of memory
such as menus that are stored off screen
If S represents screen and M represents a menu
the sequence
S SM
M SM
S SM
swaps the S and M
Color Buffers
•
Color buffers are the ones to which you draw

They contain RGBA data
•
Stereoscopic viewing needs left and right color buffers
for the left and right stereo images
•
Double-buffered systems have front and back color
buffers
•
Non-displayable auxiliary color buffers can be used
•
Minimum requirement is a front-left color buffer
Other Buffers
•
Depth buffer (z-buffer):



•
Stencil buffer:

•
Stores a depth value for each pixel
Depth is usually measured in terms of distance to the eye
Used for a hidden-surface removal
Stores the information to restrict drawing to certain portions of
the screen
Accumulation buffer:



Holds RGBA color data for accumulating a series of images into
a final, composite image
When accumulation is finished, the result is copied back into the
color buffer for viewing
Used for Scene antialiasing, motion blur, simulating depth of
field, and calculating soft shadows
Clearing Buffers
•
Clearing the screen (or any of the buffers) is expensive

•
Hardware can clear more than one buffer at once
First, specify the current clearing values for each buffer
void glClearColor(GLclampf red, GLclampf green, GLclampf blue,
GLclampf alpha);
void glClearDepth(GLclampf depth);
void glClearStencil(GLuint s);
void glClearAccum(GLclampf red, GLclampf green, GLclampf blue,
GLclampf alpha);
•
Then issue a single clear command
void glClear(GLbitfield mask);
mask is the bitwise logical OR of some combination of
GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT,
GL_STECIL_BUFFER_BIT, and GL_ACCUM_BUFFER_BIT
Color Buffers for Writing and Reading
•
void glDrawBuffer(GLenum mode);
 Selects the color buffers enabled for writing or
clearing
 mode can be GL_FRONT, GL_BACK, GL_LEFT,
GL_RIGHT, GL_FRONT_LEFT, etc
 Defualt mode is GL_FRONT for single-buffered
contexts and GL_BACK for double-buffered contexts
•
void glReadBuffer(GLenum mode);
 Selects the color buffer enabled as the source for
reading pixels
Masking Buffers
•
Sets the masks used to control writing into the indicated
buffers
•
void glColorMask(GLboolean red, GLboolean green,
GLboolean blue, GLboolean alpha);

•
void glDepthMask(Glboolean flag);

•
The red, green, blue and alpha values control whether
corresponding component is written
flag is GL_TRUE for writing
void glStencilMask(Gluint mask);

mask = 1 for writing the bit
Testing and Operating on Fragments
•
After fragments are generated, several processing stages
occur determining how and whether a given fragment is
drawn as pixel into the framebuffer
•
Set of tests:







Scissor test
Alpha test
Depth test
Stencil test
Blending
Dithering
Logical Operation
Scissor Test
Scissor Test
•
void glScissor(Glint x, Glint y, GLsizei width,
GLsizei height);
 Sets the location and size of the scissor rectangle or box
 By default, the rectangle matches the window
 Drawing occurs only inside the rectangle: pixels lying
inside the rectangle pass the scissor test
 Needs enabling
glEnable(GL_SCISSOR_TEST);
Using Alpha
Alpha Test
•
void glAlphaFunc(GLenum func, GLclampf ref);
 Sets the reference value and comparison function for the
alpha test
 In RGBA mode, a fragment is accepted or rejected by
the alpha test on its alpha value
 By default, ref is zero, and func is GL_ALWAYS
 func can be GL_ALWAYS, GL_NEVER, GL_LESS,
GL_EQUAL, GL_LEQUAL, GL_GEQUAL,
GL_GREATER or GL_NOTEQUAL
 Needs enabling
glEnable(GL_ALPHA_TEST);
Using Alpha
• The 4th component of RGBA color is “alpha”.
• Alpha is specified with the glColor… and
glClearColor commands, as well as various lighting
and material-definition commands.
• Alpha is stored in the color buffer, along with R, G, and B.
• Two major applications of alpha:
 Blending
Alpha can determine how a color to be drawn is blended with the
color already present at that pixel.
The most common application of blending is transparent objects.
 The Alpha Test
Alpha can be tested, in ways similar to the stencil buffer
Using Alpha: Blending
• Blending is covered in chapter 6 of the Red Book.
 You may also wish to read about anti-aliasing and depth-cueing
(“fog”) in that chapter.
• To do blending, enable it, and specify a blend function.
 Blending is enabled with
glEnable(GL_BLEND);
 It is not necessary to allocate any additional buffers; alpha is stored
in the color buffer.
 The blending function is specified with glBlendFunc.
Using Alpha: glBlendFunc()
• Blending involve mixing colors based on their respective
alpha values.
• A blending function blends two colors:
 The source color: the color of the fragment be drawn.
 The destination color: the color already present in the color buffer.
• Blending functions are specified using glBlendFunc,
which takes two parameters:
 GLenum: blending factor for the source color.
 GLenum: blending factor for the destination color.
Using Alpha: glBlendFunc()
• Some possible blending factors are:




GL_ZERO: Multiply this color by zero (0,0,0,0).
GL_ONE: Multiply this color by one (1,1,1,1).
GL_SRC_ALPHA: Multiply this color by the source alpha.
GL_ONE_MINUS_SRC_ALPHA: Multiply this color by one minus the
source alpha.
 GL_DST_ALPHA: Multiply this color by the destination alpha.
 GL_SRC_COLOR (for dest. blend factor only): Multiply this color by the
source color, component by component.
• For a complete list of possible blending factors, see p. 223 of the Red
Book.
Using Alpha: The Alpha Test
• glAlphaFunc takes two parameters:
 GLenum: What test to perform.
 GLclampf: Reference value
Type is like GLfloat, but required to be in [0,1], that is, “clamped”.
• The possible tests all compare the alpha value of the pixel to be drawn
with the reference value.
 GL_LESS: Passes if alpha to be drawn is less than the ref value.
 GL_EQUAL: Passes if the two are equal.
 GL_ALWAYS: Always passes.
 Etc…
• Note: The alpha test is backwards from the stencil test.
 Stencil test: REF comparison VALUE_IN_BUFFER.
 Alpha test: VALUE_FOR_NEW_PIXEL comparison REF.
Stencil Test
Stencil Buffer
•
Used to control drawing based on values in the
stencil buffer
 Fragments that fail the stencil test are not drawn
 Example: create a mask in stencil buffer and draw
only objects not in mask area
Poly.
CPU
Per
Vertex
Raster
DL
Texture
Pixel
Frag
FB
Stencil buffer (OpenGL)
•
Controls whether an image fragment continues
toward frame buffer
• Two operations involved
1) Image fragment is passed or not
2) Stencil buffer is updated by result of stencil test
and depth test
Stencil buffer (continued)
•
1)
2)
3)
Image fragment passes only if stencil test and depth test
succeed
Stencil test fails (color and depth of pixel remain
unchanged)
Stencil test passes, depth test fails (color and depth of
pixel remain unchanged)
Both pass (color and depth for pixel are given the new
values)
In all cases stencil buffer is updated according to stencil
operation pre-set for the condition
Stencil Buffer: Functions
• The two major functions used in stenciling are
glStencilFunc and glStencilOp.
 glStencilFunc determines what the stencil test does.
 glStencilOp determines what happens to the stencil
buffer if the stencil test passes or fails.
If the stencil test passes, then you can also have different
outcomes based on the depth test.
Creating a Mask
•
•
•
glInitDisplayMode( …|GLUT_STENCIL|… );
glEnable( GL_STENCIL_TEST );
glClearStencil( 0x0 );
•
•
glStencilFunc( GL_ALWAYS, 0x1, 0x1 );
glStencilOp( GL_REPLACE, GL_REPLACE,
GL_REPLACE );
draw mask: for example
•
glBegin(GL_QUADS);
glVertex2f (-1.0, 0.0);
glVertex2f (0.0, 1.0);
glVertex2f (1.0, 0.0);
glVertex2f (0.0, -1.0);
glEnd();
Using Stencil Mask
•
Draw objects where stencil = 1
•
•
glStencilFunc( GL_EQUAL, 0x1, 0x1 )
Draw objects where stencil != 1
•
•
glStencilFunc( GL_NOTEQUAL, 0x1, 0x1 );
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
Stencil Test
•
The stencil test takes place only if there is a stencil buffer


•
It compares a reference value with the value stored at a pixel in the buffer
Depending on the test result, the value in the stencil buffer is modified
void glStencilFunc(GLenum func, GLint ref, GLuint mask);

Sets the comparison func, reference ref and mask for the test
Comparison applies to those bits for which bits of the mask are 1
 func can be GL_ALWAYS, GL_LESS, etc.
 Needs enabling: glEnable(GL_STENCIL);
•
glStencilOp(GLenum fail, GLenum zfail, GLenum zpass);

Specifies how the data in the stencil buffer is modified when a fragment
passes or fails the stencil test
 fail, zfail, zpass can be GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR,
GL_DECR, GL_INVERT
fail = failed stencil test; zfail = failed z test; zpass = passed z test
Stencil Buffer: glStencilFunc
• glStencilFunc takes three parameters:
 A GLenum: what comparison the stencil test will do.
 A GLint used as a “reference value” in the stencil test.
 A GLuint used as a mask (an “and” mask).
• Think: REF COMPARE (buffer pixel & mask)
• Examples
 Stencil test passes if bit in SB is on:
glStencilFunc(GL_EQUAL, 0x1, 0x1);
 Stencil test passes if bit in SB is off:
glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
 Test passes if 20 < low 8 bits in SB:
glStencilFunc(GL_LESS, 20, 0xff);
Stencil Buffer: glStencilOp
• glStencilOp takes three parameters, all GLenum’s:
 Operation to perform if stencil test fails.
 Op. to perform if stencil test passes and depth test fails.
 Op. to perform if stencil test passes and depth test passes.
• Examples
 Replace the SB value with the reference value (from glStencilFunc):
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
 Do not modify the SB:
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
 Replace SB value with zero, the reference value, or the bitwise inversion
of the current SB value, respectively:
glStencilFunc(GL_ZERO, GL_REPLACE, GL_INVERT);
 Increment or decrement the SB value, as appropriate:
glStencilFunc(GL_DECR, GL_INCR, GL_INCR);
Review: Stencil Buffer [1/2]
• Stenciling involves the stencil buffer and the stencil test.
 Remember: allocate the buffer, enable the test.
 Clear the buffer the same way you clear any buffer.
• The two major functions used in stenciling are
glStencilFunc and glStencilOp.
 glStencilFunc determines what the stencil test does.
 glStencilOp determines what happens to the stencil buffer if
the stencil test passes or fails.
If the stencil test passes, then you can also have different
outcomes based on the depth test.
Review: Stencil Buffer [2/2]
• glStencilFunc takes three parameters:
 GLenum: Which comparison the stencil test will do.
 GLint: “Reference value” in the stencil test.
Also used by operations specified with glStencilOp.
 GLuint: Used as a mask (an “and” mask).
• glStencilOp takes three parameters:
 GLenum: Operation to do if stencil test fails.
 GLenum: Operation if stencil passes and depth fails.
 GLenum: Operation if stencil passes and depth passes.
Stenciling Examples: Ordinary Stenciling
•
To draw a shape in the stencil buffer:

Redo when viewport changes size! Code goes in the reshape function.
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_NEVER, 1, 1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // only 1st param
matters
Draw a shape here.
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
•
To use the above shape:
glStencilFunc(GL_EQUAL, 1, 1);
Draw something; it will appear only inside the above shape.
glStencilFunc(GL_NOTEQUAL, 1, 1);
Draw something; it will appear only outside the above shape.
Stenciling Examples: Odd Things to Do
•
Draw each pixel at most 5 times:
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_GREATER, 5, 0xff);
glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
•
Draw each pixel successfully only on every other attempt:
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_EQUAL, 0, 1);
glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
Stenciling Examples: Capping
•
Here is an implementation of “capping” (see Red p. 446).

You are drawing a number of closed objects. You wish to make sure that the inside of these is
never visible, even if the near clipping plane slices one of them.
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT |
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
Draw scene.
glStencilFunc(GL_EQUAL, 1, 1);
Draw rectangle covering entire viewport, in “capping” color.
Depth Test
Depth Test
•
glDepthFunc(GLenum func);


Sets the comparison function for the depth test
An incoming fragment passes the depth test if its z value has
specified relation to the value already stored in the depth buffer
 By default, func is GL_LESS
Pixels with larger depth-buffer values are overwritten by pixels
with smaller values

func can be GL_ALWAYS, GL_EQUAL, GL_GREATER, etc.

Needs enabling
glEnable(GL_DEPTH_TEST);
Use of Depth Buffer
•
Use of depth buffer (z-buffer) to achieve hidden surface removal
•
Graphical calculations convert each surface (before drawing) to
a set of corresponding pixels on the window and also compute
depth value for each pixel
•
A comparison is done with the depth value already stored at that
pixel to accept the pixel only if it has a smaller depth
•
Color and depth information of the incoming pixel with greater
depth is discarded
How to Specify?
•
In void glDepthFunc(Glenum func);
Defualt value of func is used: GL_LESS used
glEnable(GL_DEPTH_TEST);
•
glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH);
•
Before drawing, each time you need to clear the depth
buffer and draw objects in any order
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear() clears both color and depth buffers
•
Planet hides behind the sun in solar system example
Z-buffer (OpenGL)
•
•
•
•
Requires increased functionality beyond ‘ifstatement’ implementation
Six relational operators
Ability to separate depth testing and Z-value
updating
Z (incoming) op Z (stored)
where op is <, ≤, >, ≥, =, ≠
Accumulation Buffer
Accumulation Buffer:
Overview
• Next we look at OpenGL’s accumulation buffer.
 The accumulation buffer allows you to blend together different 2-D
scenes.
These can be renderings of 3-D scenes.
 The accumulation buffer holds RGBA color data, just like the color
buffers.
 There are special commands that allow you to blend a color buffer
with the accumulation buffer (possibly several times) and then
transfer the contents of the accumulation buffer to a color buffer.
 Allocate the accumulation buffer using GLUT_ACCUM in your
glutInitDisplayMode call.
There is nothing to enable.
Accumulation Buffer:
Operations
•
Five operations can be performed on the accumulation buffer (AB). They are all
performed on the entire buffer at once:





•
AB can be cleared.
Contents of a color buffer can be multiplied by a value and then copied to AB.
Contents of a color buffer can be multiplied by a value and then added to AB.
An arithmetic operation ( or +) can be performed on every pixel in AB.
The contents of AB can be multiplied by a value and copied to a color buffer.
The first operation above, clearing, is done with glClear:
glClearAccum(R, G, B, A);
// like glClearColor
(optional)
glClear(GL_ACCUM_BUFFER_BIT); // Clear AB
•
The other four operations involve the glAccum command.
Accumulation Buffer:
glAccum [1/2]
• glAccum takes two parameters:
 A GLenum telling which operation to perform.
 A GLfloat giving a relevant constant value.
•
To multiply the contents of a color buffer by a value and copy the result to the
AB:
glAccum(GL_LOAD, value);
 This uses the color buffer selected for reading. Use glReadBuffer to change
this. (Generally, you do not need to worry about it.)
•
To multiply the contents of a color buffer by a value and add the result to the
AB:
glAccum(GL_ACCUM, value);
Accumulation Buffer:
glAccum [2/2]
• To multiply the contents of the AB by a value:
glAccum(GL_MULT, value);
 There is also GL_ADD, to add instead of multiplying, but I have never
seen a use for it.
• To multiply the contents of the AB by a value and copy the result to a
color buffer:
glAccum(GL_RETURN, value);
 This uses the color buffer selected for drawing. Use glDrawBuffer to
change this. (Generally, you do not need to worry about it.)
Accumulation Buffer:
Typical Code
void display() // The display function
{
glClear(GL_ACCUM_BUFFER_BIT);
for (int i = 0; i < numscenes; ++i)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Draw scene number i here
glAccum(GL_ACCUM, scenefraction[i]);
}
glAccum(GL_RETURN, 1.0);
glutSwapBuffers();
}
•
The values scenefraction[i] should be in [0,1] and should probably add up to 1.

•
•
Replacing “scenefraction[i]” with “1.0/numscenes” would give equal weight to all scenes being
blended.
Note how the clearing works: AB outside the loop, color & depth inside.
Also note that the above code is not as efficient as it could be. (Why?)
Accumulation Buffer:
Applications
•
The AB can be used for:





•
Fading between scenes.
Motion blur.
Anti-aliasing.
Depth-of-field effects.
Soft shadows (if you know how to do shadows).
The last three applications above are usually done with “jittering”.
 Jittering means making repeated small perturbations to a scene.
 Then we blend the jittered scenes together to form the finished product.
 To do anti-aliasing and depth-of-field effects, we jitter the projection matrix; to do soft
shadows, we do shadows (somehow …) and jitter the light source.
•
What are some problems with using the AB?
 AB operations are generally slow; they may be unsuitable for real-time graphics.
 OpenGL implementations are not required to support accumulation buffers, so it might reduce
the portability of code. (In practice, this does not seem to be a problem.)
Review:
Accumulation Buffer [1/2]
•
•
The AB holds RGBA color data; it is used to blend of 2-D scenes.
Five operations can be performed on the AB:
 AB = 0. (Clear AB; the “0” can be anything you want)
With glClear. Other operations are done with glAccum.
 GL_LOAD: AB = k*CB. (CB = Color Buffer)
 GL_ACCUM: AB += k*CB.
 GL_MULT: AB *= k. (Or “+=” using GL_ADD)
 GL_RETURN: CB = k*AB.
•
Typically:
 Clear AB (unless first operation below is a LOAD).
 Repeat:
Clear color buf. And draw a scene in it.
Color buf.  value → add to AB.
 Copy AB to color buf.
• “Values” above should be in [0,1], and add up to 1. Using a larger value gives
that scene greater weight in the final image.
Review:
Accumulation Buffer [2/2]
•
Here is an implementation of “fade between scenes”:
void display() // The display function
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Draw scene 1 here
glAccum(GL_LOAD, 1.0-fadefraction);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Draw scene 2 here
glAccum(GL_ACCUM, fadefraction);
glAccum(GL_RETURN, 1.0);
glutSwapBuffers();
}
•
The variable fadefraction should be in [0,1]. It should slowly increase from 0 to 1, changing
values each time the display function is called.
Other Operations
•
Blending

•
Dithering

•
Combines the incoming fragment’s R, G, B and A values with
those of the pixel already stored at the location
Dither the values of red, green and blue on neighboring pixels for
the perception of a wide range of colors
Needs enabling with GL_DITHER
Logical Operations

Are applied between the incoming fragment’s color and the color
stored at the corresponding location in the framebuffer
 The result replaces the value in the framebuffer for that fragment
void glLogicOp(GLenum opcode);
opcode can be GL_CLEAR, GL_COPY, GL_AND, etc
Needs enabling with GL_COLOR_LOGIC
Hidden-Surface Removal
Hidden Surface?
•
In a scene composed of 3D objects, some of them might
obscure all or parts of others
•
The obscuring relationship changes with viewpoint and
needs to be properly maintained
•
Hidden-surface removal is elimination of parts of solid
objects that are obscured by others
•
Otherwise, the objects are drawn in the order the drawing
commands appear in the code
•
Hidden-surface removal increases performance
Alpha Test
Poly.
CPU
Per
Vertex
Raster
DL
Frag
FB
Texture
•
Pixel
Reject pixels based on their alpha value
• glAlphaFunc( func, value )
• glEnable( GL_ALPHA_TEST )
 use alpha as a mask in textures
Dithering
•
•
glEnable( GL_DITHER )
Dither colors for better looking results
 Used to simulate more available colors
Review:
Buffers & Tests [1/3]
•
OpenGL has 4 kinds of buffers.


•
OpenGL has 4 tests.


•
Each buffer holds a piece of data about every pixel in the viewport.
The kind of data depends on which buffer and how it is used.
A test gives a Boolean result for each fragment.
True → test passes → fragment is drawn.
Buffers and tests are associated:
Buffer
Corresponding Test
--
Scissor Test
Color Buffers
Alpha Test
Depth Buffer
Depth Test
Stencil Buffer
Stencil Test
Accumulation Buffer
--
Review:
Buffers & Tests [2/3]
• Remember:
 Allocate a buffer.
In your glutInitDisplayMode call.
 Buffers generally need to be cleared.
Use the proper “GL_…_BUFFER_BIT” constant in glClear.
Set the value to clear to using glClearbuffername.
 Enable a test.
Enable with glEnable. Disable with glDisable.
• Most buffers have masks associated with them.
 For example, the color-buffer mask is controlled by the
glColorMask command.
 The mask affects all commands that would change the buffer, even
glClear.
Review:
Buffers & Tests [3/3]
• The scissor test allows you to restrict drawing to a
rectangular portion of the viewport.
 To use: enable the scissor test, and specify a rectangle
with glScissor.
 The scissor test passes if the pixel is within the
rectangle; otherwise, it fails.
 The scissor test is really just a quick, simple version of
stenciling.
We discuss stenciling later.
Review:
Buffers & Tests
•
OpenGL has 4 kinds of buffers.


•
OpenGL has 4 tests.


•
Each buffer holds a piece of data about every pixel in the viewport.
The kind of data depends on which buffer and how it is used.
A test gives a Boolean result for each fragment.
True → test passes → fragment is drawn.
Buffers and tests are associated:
Buffer
Corresponding Test
--
Scissor Test
Color Buffers
Alpha Test
Depth Buffer
Depth Test
Stencil Buffer
Stencil Test
Accumulation Buffer
--
Download
Related flashcards

MSN

28 cards

Software

43 cards

Microsoft software

75 cards

Duke Nukem

15 cards

Create Flashcards