1 / 11

Blending and Antialiasing

Blending and Antialiasing. Blending. Blending is a combination of color of two or more objects. We need to enable blending by using gl.glEnable (GL2.GL_BLEND) Now we need the Alpha value of color using gl.glColor 4 f( R , G , B , ALPHA )

shlomo
Download Presentation

Blending and Antialiasing

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. Blending and Antialiasing

  2. Blending • Blending is a combination of color of two or more objects. • We need to enable blending by using • gl.glEnable(GL2.GL_BLEND) • Now we need the Alpha value of colorusing • gl.glColor4f( R , G , B , ALPHA ) • when blending is enable, the alpha value use to combined the color.

  3. The Source and Destination Factors • Blending combine the source and destination being processed. • The combination is done using source and destination factors that are multiplied by their corresponding source and destination colors. • Suppose that we have: • source color= (srcR, srcG, srcB, srcA)//pixel drawn • source factor= (sFR, sFG, sFB, sFA)//src factor • destination color= (dstR, dstG, dstB, dstA)//color in the buffer • destination factor = (dFR, dFG, dFB, dFA)//dest factor

  4. The Source and Destination Factors • The color obtained by the combination is the sum of products between the color and its associated factor, this is the Blending Formula: • srcColor*srcFactor+ destColor*destFactor • equivalent to : • (srcR*sFR+ dstR*dFR, srcG*sFG+ dstG*dFG, srcB*sFB+ dstB*dFB, srcA*sFA+ dstA*dFA)

  5. Blending • gl.glEnable(GL2.GL_BLEND) ; • gl.glBlendFunc(srcfactor, destfactor); • Srcfactor and destfactorare one of these constant : Default of DST Default of SRC

  6. Blending Ex. gl.glEnable(GL2.GL_BLEND) ; gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE); gl.glColor4f(0,1f,0,.75f); gl.glBegin(GL2.GL_TRIANGLES); gl.glVertex2i(-100,50); gl.glVertex2i(-100,-50); gl.glVertex2i(50,0); gl.glEnd(); gl.glColor4f(0,0f,1f,.75f); gl.glBegin(GL2.GL_TRIANGLES); gl.glVertex2i(100,50); gl.glVertex2i(100,-50); gl.glVertex2i(-50,0); gl.glEnd(); OUTPUT

  7. Class Activity

  8. Antialiasing • Converting jagged line to smooth line is called Antialiasing. • For antialiasing we need • gl.glEnable(GL.GL_LINE_SMOOTH); • gl.glEnable(GL2.GL_BLEND) ; • gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); • gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_DONT_CARE);

  9. glHint() Parameters • C SpecificationvoidglHint(GLenum target, GLenum mode) • target • Specifies a symbolic constant indicating the behavior to be controlled. • GL_LINE_SMOOTH_HINT, • GL_POLYGON_SMOOTH_HINT, • GL_POINT_HINT,

  10. glHint() Parameters • mode • Specifies a symbolic constant indicating the desired behavior. • GL_FASTEST, The most efficient option should be chosen • GL_NICEST, The most correct , or highest quality , option should be chosen. • GL_DONT_CARE. No preference

  11. Antialiasing Ex. • gl.glEnable(GL.GL_LINE_SMOOTH); • gl.glEnable(GL2.GL_BLEND) ; • gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); • gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_DONT_CARE); • gl.glColor4f(0,1f,0,.9f); • gl.glBegin(GL2.GL_LINES); gl.glVertex2i(-100,-100); • gl.glVertex2i(100,100); gl.glEnd(); OUTPUT

More Related