How to produce a shadow of 3D object(such as cube) with respect to light?
Is there any algorithm to deal with that problem? or does there exist a set of function in opengl to solve that problem?
no nothing is built in, but if you do a search here I think you will find an anser
Search www.nvidia.com in the developer section. Mark Kilgard wrote a white paper on stencil buffering (VGIMO), and it has a rather large section dealing with shadow generation using stencil. Granted, the shadows using this technique aren't near what you would get with raytracing/casting or some other algorithm, but it will be realtime (assuming you have a card that supports 1/8/16 stencil bits).
Have a look and pull down some of the Nvidia demos/source as well.
I haven't tested it yet but i think you can create a shadow with the glScale function.
A scale value of zero collapses all object coordinates along that axis to zero.