Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenGL Blending Akbar Ali

Similar presentations


Presentation on theme: "OpenGL Blending Akbar Ali"— Presentation transcript:

1 OpenGL Blending Akbar Ali (syedali011@earthlink.net

2 Blending Adds realistic effects to your scenes Gives you the ability to promote volume fog. Permits you to blend many textures on top of others using certain state calls and variables.

3 Blending? Usually this occurs when the alpha value is combined with the color value of the fragment that is already on the screen(framebuffer). When this occurs this is what we call blending. Usually it is preferred to use the alpha channel when enabling blending. So say bye-bye to your a lot of your old textures.

4 Enabling Blending & Disabling Blending glEnable(GL_BLEND) & glDisable(GL_BLEND)

5 How the Blending is processed With glBlendFunc(GLEnum sfactor, GLEnum dfactor) sfactor is the source factor dfactor is the destination factor

6 What this means to OpenGL Gives it the needed data so it knows how to process the pixels accordingly. Virtual machine then applies these changes and then makes all future computations accordingly according to the mode which you are in.

7 sfactor glBlendFunc sfactor glBlendFunc(Glenum sfactor, Glenum dfactor) This is your source factor, OpenGL will look at these and the mode you set them in apply them to the function and Walla you have your blending. Below is the settings you can put them in and what they do accordingly. Ps-> the destination is the pixels that are already on the screen(frame buffer). The source are the ones on there way to the framebuffer. Blending factors are clamped to the range [0,1].These are the most common ones used, if you would like to see more please consult the ‘what’s next section’ When the ^d, ^s, ^c, comes up that just means that it is inherit those colors which are already present. Destination; Source; Constant. sfactor ConstantsBlend Factor GL_DST_COLORR^d, G^d, B^d, A^d GL_ONE_MINUS_DST_COLOR(1,1,1,1)-(R^d,G^d,B^d,A^d) GL_ONE_MINUE_SRC_ALPHA(1,1,1,1)-(A^s,A^s,A^s,A^s)

8 dfactor glBlendFunc dfactor glBlendFunc(Glenum sfactor, Glenum dfactor) dfactor ConstantsBlend Factor GL_ONE_MINUS_DST_ALPHA(1,1,1,1)-(A^d,A^d,A^d,A^d) GL_ONE_MINUS_SRC_ALPHA(1,1,1,1)-(R^s,G^s,B^s,A^s)

9 Practice, Practice,Practice. When learning these blending modes you are going to have to practice these and check out there effects. The only advice is to just try all the different constants and experiment. In no time you will be achieving some nice translucent glass effects etc. Here is an insert of some code glEnable(GL_BLEND); /* don’t forget to enable the mode*/ glEnable(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUE_SRC_ALPHA); draw_texture_polygon ();/* this should be something like a cube which is textured it is really easy to see the effects then*/ glDisable(GL_BLEND); /*disable this or then all your textures planes etc. Will be effected by this */

10 OpenGL Blending This in it self could have a whole book dedicated to it. Many amazing effects can be achieved by using this effectively. A few are Weapon effects Portals (real portals like the ones you use when warping. Distortion Particle Effects

11 Check this out www.OpenGL.org Look through the manual at OpenGL.org over OpenGL and it should contain a write- up of all the constants that you can specify when using blending. If time permits I will copy it and post it on the white paper.


Download ppt "OpenGL Blending Akbar Ali"

Similar presentations


Ads by Google