1 / 20

Lecture 12

Lecture 12. Blending, Anti-aliasing, Fog, Display Lists. Blending. Alpha value: It’s been ignored so far. We use alpha value for blending.

gloria-todd
Download Presentation

Lecture 12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

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

  3. 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(Glenumsfactor, Glenumdfactor)

  4. Blending Coefficients Table

  5. 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”

  6. Anti-aliasing

  7. SolutionUse Coverage values and Alpha

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

  9. Anti-aliasing Polygons

  10. Anti-aliasing Polygons

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

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

  13. Using Fog • glEnable(GL_FOG) • Use Fog equation • Use Fog color • glFog{if}(GLenumpname, TYPE param)

  14. Using Fog

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

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

  17. Limitations • Only the values for expressions are stored in the list Not the expressions. • Example: GLfloatcolor_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.

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

  19. 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();

  20. END

More Related