Window drop shadows

I'm writing a gui for opengl and I'm trying to add drop shadows to my windows, similar to those used in os x. I'm using a squarish gradient texture for the shadow, and when I resize the window, the drop shadow's size becomes distorted in relation to that of the window. Is there any way around this?

Instead of taking a single rectangle for the entire window and scaling it, you're going to need to create 3 rectangles: one for the bottom of the shadow, one for the right, and one for the corner to fill in the gap between the other two. Only scale the bottom rectangle along the x axis and only scale the right rectangle along the y axis. The corner rectangle never needs to be scaled. As an optimization, you can use a single 1-D texture for both the bottom and right rectangles, and a 2D texture for the corner rectangle.

Okay, another question on a closely related topic. I'm trying to figure out the best way to optimize my window drawing routine. The current version draws a window, then its content, starting with the bottom window layer going through the top, using a scissor test for each window to keep the drawing within its bounds.

So I'd like to be able to draw only the portions of windows that are visible(not obscured by other windows). Is there some way to do this without performing a stencil test? And would the performance penalty incurred by a stencil test offset the performance gain received by only drawing visible regions(or might this depend on the windows content)?

The Z axis runs from far to near. Your comment on Z_NEAR is correct, though, for gluPerspective at least; it measures distance along the -Z axis. So, near objects should have a greater Z coordinate than far objects.