120 likes | 474 Views
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 )
E N D
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.
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
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)
Blending • gl.glEnable(GL2.GL_BLEND) ; • gl.glBlendFunc(srcfactor, destfactor); • Srcfactor and destfactorare one of these constant : Default of DST Default of SRC
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
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);
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,
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
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