TUTORIAL 1 - OpenGL Fundamentals

1  2  3  4  5  6  7  8  9  10  11  12  13

Transparent Surfaces

The nice thing about transparent surfaces is that they are very easy to implement. We simply have to enable the blending, define the amount of transparency with the alpha value of the color (alpha=0.0 means totally transparent, 1.0 means no transparency at all) and specify which blending function we want to use:

  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
  glColor4f(0.0,0.0,1.0,transparency);

There are a couple of different modes we could use for the blending function, but for simple transparencies, the most useful is usually the GL_ONE_MINUS_SRC_ALPHA.

In the figure above we see a comparison of GL_ONE_MINUS_SRC_ALPHA with GL_SRC_ALPHA. As we can see, the GL_ONE_MINUS_SRC_ALPHA gives us a behavior as we would expect it from a thin sheet of plastic where we decrease the transparency. With decreasing transparency the color of the plastic sheet becomes more dominant until we see only an opaque plastic sheet. The GL_SRC_ALPHA on the other hand looks pretty counterintuitive however for high alpha values it might come in handy since it allows us to use colors with higher intensity for highly transparent surfaces. When you want to use transparency in more complex scenes, it would be worth to check out the other blending functions and it might also be a good idea, to take a look at some of the books mentioned below to get in depth information on OpenGL.

previous   next