lecture 12 blending, anti-aliasing, fog, display lists
Post on 31-Dec-2015
223 Views
Preview:
TRANSCRIPT
Lecture 12
Blending, Anti-aliasing, Fog, Display Lists
Blending
• Alpha value: It’s been ignored so far.• We use alpha value for blending.• Fragments: After the rasterization stage (including
texturing and fog), the data are not yet pixels. At this stage, they are called fragments.(These are called source)
• Pixels: Then each fragment undergoes a series of tests and operations after which, it is called a pixel.(These are called destination)
• Blending: Specifies a blending function that combines color values from a source and a destination
Blending Function
• Blending Function: Specifies how source and destination are blended together.
• Final result of combination for each pixel is calculated from the following formula:
(Rs.Sr+Rd.Dr, Gs.Sg+Gd.Dg, Bs.Sb+Bd.Db, As.Sa+Ad.Da)
• glBlendFunc(Glenum sfactor, Glenum dfactor)
Blending Coefficients Table
Samples of Blending
• Draw two images blending together equally:– Source: GL_SRC_ALPHA– Destination: GL_ONE_MINUS_SRC_ALPHA– Draw the source with alpha=0.5
• Draw three images blending together equally:– Set the destination factor to GL_ONE – Set the source factor to GL_SRC_ALPHA– Draw each of the images with an alpha equal to 0.3333333
• Need more? Refer to the RedBook, Chapter 6, “Sample Uses of Blending”
Anti-aliasing
SolutionUse Coverage values and Alpha
Enabling Anti-alias
• glEnable(GL_POINT_SMOOTH)• glEnable(GL_LINE_SMOOTH)• You may want to optimize anti-aliasing:– Use glHint() along with the parameters.– Use blending when two lines cross each other– Use GL_SRC_ALPHA (source) and
GL_ONE_MINUS_SRC_ALPHA (destination). – You can use GL_ONE for the destination factor to make
lines a little brighter where they intersect
Anti-aliasing Polygons
Anti-aliasing Polygons
Anti-aliasing Polygons
• Use glEnable(GL_POLYGON_SMOOTH ): This will cause pixels on the edges of the polygon to be assigned fractional alpha values based on their coverage.
• Turn off the depth buffer• set the blending factors to
GL_SRC_ALPHA_SATURATE (source) and GL_ONE (destination)
• Sort all the polygons in your scene so that they're ordered from front to back before drawing them
Fog
• Makes objects fade into the distance.• Fog is a general term that describes forms of
atmospheric effects.• Fog can be used to simulate haze, mist,
smoke, or pollution.
Using Fog
• glEnable(GL_FOG)• Use Fog equation• Use Fog color• glFog{if}(GLenum pname, TYPE param)
Using Fog
Display Lists
• Advantages of using Display Lists: – Store OpenGL commands for later execution– Using display lists, you can define the geometry
and/or state changes once and execute them multiple times.
– Saves lots of resources when an OpenGL program is running over a network.(Saves lots of back and forth communications)
Using Display Lists
• Use glGenLists(size) to create names.• Use glNewList(name,
GL_COMPILE/GL_EXECUTE/GL_COMPILE_ANDEXECUTE), glEndList() to define a list
• Use glCallList(list_name) to recall a list.
Limitations
• Only the values for expressions are stored in the list Not the expressions.
• Example: GLfloat color_vector[3] = {0.0, 0.0, 0.0};
glNewList(1, GL_COMPILE); glColor3fv(color_vector); glEndList(); color_vector[0] = 1.0;
• The color is not changed in the list after the last line is executed.
Limitations
• The following commands are not stored in a display list:
• Commands that set client state.• Commands that retrieve state values aren't
stored in a display list.
Hierarchical Display Lists
• A hierarchical display list is allowed in OpenGL, which is a display list that executes another display list.
• Example: glNewList(listIndex,GL_COMPILE);
glCallList(handlebars); glCallList(frame); glTranslatef(1.0,0.0,0.0); glCallList(wheel); glTranslatef(3.0,0.0,0.0); glCallList(wheel); glEndList();
END
top related