opengl blending akbar ali ([email protected]

11
OpenGL Blending Akbar Ali ([email protected]

Upload: scott-lewis

Post on 02-Jan-2016

221 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: OpenGL Blending Akbar Ali (syedali011@earthlink.net

OpenGL Blending

Akbar Ali ([email protected]

Page 2: OpenGL Blending Akbar Ali (syedali011@earthlink.net

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.

Page 3: OpenGL Blending Akbar Ali (syedali011@earthlink.net

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.

Page 4: OpenGL Blending Akbar Ali (syedali011@earthlink.net

Enabling Blending&

Disabling Blending

glEnable(GL_BLEND)

&

glDisable(GL_BLEND)

Page 5: OpenGL Blending Akbar Ali (syedali011@earthlink.net

How the Blending is processed

• With glBlendFunc(GLEnum sfactor, GLEnum dfactor)

• sfactor is the source factor

• dfactor is the destination factor

Page 6: OpenGL Blending Akbar Ali (syedali011@earthlink.net

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.

Page 7: OpenGL Blending Akbar Ali (syedali011@earthlink.net

glBlendFunc sfactorsfactorglBlendFunc(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 Constants Blend Factor

• GL_DST_COLOR R^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)

Page 8: OpenGL Blending Akbar Ali (syedali011@earthlink.net

glBlendFunc dfactordfactorglBlendFunc(Glenum sfactor, Glenum dfactor)

dfactor Constants Blend 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)

Page 9: OpenGL Blending Akbar Ali (syedali011@earthlink.net

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 */

Page 10: OpenGL Blending Akbar Ali (syedali011@earthlink.net

OpenGL BlendingThis 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

Page 11: OpenGL Blending Akbar Ali (syedali011@earthlink.net

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.