How do you make shadows in OpenGL. I have been using the NeHe tutorials, but I do not understand their shadow lesson. Can anybody help?

Making shadows in OpenGL (or DirectX) is not a trivial task. I'm not surprised that you would have trouble with the NeHe tutorial on the subject. The important thing to understand is that, in order to determine the shadows that the objects will cast, you need to render the scene from the perspective of the light point. If you look at a scene from the point of view of the light, everything that makes it to the "screen" is a surface that is lit by the light, everything that doesn't is covered by a shadow (at least with respect to that light source). So, the basic idea to create a shadow in OpenGL is to first render the scene from the point of view of the light source, and generating masking textures from that rendering pass. Once you have the masks, you blend them (by multiplication) with the surface textures of your objects and render the scene in the final point of view (camera).

Obviously, the technical details of how to do this can be complicated, it traditionally involves using the stencil buffer to record the masking texture. I'm not sure what the state-of-the-art is on this subject. Many modern multi-pass rendering and scene graph rendering employ render-to-texture capacities of most modern GPUs.

Thank you, your description helped a bit. I will try to read the tutorial again and see if I can get it working. Ill post back if I need more help.

After reading it again I guess I don't fully understand the stencil buffer. Is it some kind of storage space on the GPU? How exactly does it work? Could I also implement shadows as a 2D image that I overlay on top of my scene before drawing it? Could I do some math and create a set of triangles that represent the triangle and are placed just above the surfaces on which they are set?

The stencil buffer is just a part of the framebuffer (which is the image that is rendered to the screen). The framebuffer is basically an image whose pixels are defined by different values, like red, green, blue, alpha, depth, stencil, and others. Obviously, RGB stores the color, Alpha stores the transparency, Depth stores the "distance" to the screen, and the stencil is just an additional value that is available to the programmer to store anything else he might want to store on a per-screen-pixel basis.

I don't know much about making shadows, and my knowledge of it goes back many years ago, so I really don't have much more to say about it.

Maybe this tutorial will be more helpful and current than NeHe's tutorial.

This article has been dead for over six months. Start a new discussion instead.