glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ZERO);
// Test alpha blending.
render_plane(-3, 0,2, 0, 0,0, 1, 10);
// Render transparent sphere.
glPushMatrix();
glScalef(2.0, 2.0, 2.0);
glTranslatef(0.0, 0.0, 1.5);
render_sphere();
glPopMatrix();
//--- Disable GL blending
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
Alpha blending with Cg shaders
I am trying to use alpha blending in my Cg shaders. This is my code in the application:
I would like the sphere to be transparent so I can see the plane thats behind it.
In the fragment program for the plane I set the color.a = 1.0 and in the fragment program for the sphere I set the color.a = 0.5.
But the sphere is not transparent, what am I doing wrong?
It works because of the equation from (Chapter 7 Blending, Antialiasing, and Fog):
http://fly.cc.fer.hr/~unreal/theredbook/chapter07.html
when you use:
glBlendFunc(GL_ONE,GL_ZERO);
You use 100% of the source color, and 0% of the dstination color - and then the sphere - in your sample code - was wisible with the full color and the background was invisible.
If you dont want to bother we can assume that glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); is most common for blending :)
http://fly.cc.fer.hr/~unreal/theredbook/chapter07.html
when you use:
glBlendFunc(GL_ONE,GL_ZERO);
You use 100% of the source color, and 0% of the dstination color - and then the sphere - in your sample code - was wisible with the full color and the background was invisible.
If you dont want to bother we can assume that glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); is most common for blending :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement