Blending Tutorial



This brief tutorial explains the basics of blending in OpenGL. You can find more information online.

To start, download the zip file here. Unzip the folder, open the visual studio solution, and run the program. You should see a cube. If you look at the display command you'll see that there are actually two cubes in the scene but one is inside of the other. We don't see it because we are using depth buffering.

We can use blending in order to see through the bigger cube. Add the following code just before the second cube is drawn.
	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
	glEnable(GL_BLEND);
Add the following after it is drawn.
	glDisable(GL_BLEND);
Now you should be able to see the red cube inside the blue. You also may notice some strange inconsistencies in the transparencies. To further illustrate the issue, move the code for the first cube after that for the second (be sure to include the material properties). Recompile and run. Now you won't see the red cube, though the blue one should still seem semi-transparent (still with some inconsistencies). As we discussed in lecture, order matters. If you move the camera around the inconsistencies will become more apparent. Consider the cube from different perspectives and try to infer the ordering of the sides of the in glutSolidSphere.