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.
Thanks. I feel like such an idiot for not thinking of that considering that's how I already render window frames

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)?
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)?
draw front to back with a depth test?
OneSadCookie Wrote:draw front to back with a depth test?
In addition to that, I'm guessing you'll probably have to draw the translucent window drop shadows last, and back to front though. Probably with depth test on but the depth mask off.
AnotherJake Wrote:In addition to that, I'm guessing you'll probably have to draw the translucent window drop shadows last, and back to front though. Probably with depth test on but the depth mask off.
Yeah that's the part I wasn't quite sure about, but that sounds about right, thanks.
Okay, I'm having a real difficult time getting the depth buffer to work as I'd like it to, this is also my first time ever using it.
I'm using glortho and my understanding is that both znear and zfar must be positive and that each refers to depth along the negative z axis. So I've specified znear as 1.0 and zfar as 100.0.
I'm trying to draw windows from top to bottom, where the top windows layer is 0, and the second to the top is 1, etc...
Here's my pseudo code.
The effects of this code seem to be that the frontmost window is all the way at the back instead of the front.
I'm using glortho and my understanding is that both znear and zfar must be positive and that each refers to depth along the negative z axis. So I've specified znear as 1.0 and zfar as 100.0.
I'm trying to draw windows from top to bottom, where the top windows layer is 0, and the second to the top is 1, etc...
Here's my pseudo code.
Code:
#define Z_NEAR 1.0 // so this would really be -1 along the z axis, right?
#define Z_FAR 100.0
void DrawWindows()
{
winPtr win;
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(Z_FAR);
glDepthFunc(GL_GEQUAL);
Float minDepth = Z_NEAR + 1.0;
Float depth;
// The greater the window layer the farther back it is
// 0 is the frontmost window
for (i = 0; i < winCount+1; i++)
{
win = GetWindowWithLayer(i);
if (win != NULL)
{
depth = -(minDepth + win->layer)
glBegin(GL_QUADS);
glVertex3f( win->v0.x, win->v0.y, depth);
glVertex3f( win->v1.x, win->v1.y, depth);
glVertex3f( win->v2.x, win->v2.y, depth);
glVertex3f( win->v3.x, win->v3.y, depth);
glEnd();
}
}
}
The effects of this code seem to be that the frontmost window is all the way at the back instead of the front.
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.
Resolved. I was accidently setting the depth variable elsewhere in my program without being aware of it.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Making 2D Stencil Shadows Soft | metacollin | 16 | 22,636 |
Jul 22, 2009 01:59 PM Last Post: NelsonMandella |
|
softening 2d shadows | NelsonMandella | 5 | 6,830 |
May 19, 2009 04:19 AM Last Post: Najdorf |
|
Real-Time Soft Shadows | MarkJ | 6 | 8,588 |
Feb 17, 2007 03:10 PM Last Post: MarkJ |
|
Rendering 2D Shadows for Convex Shapes | Nick | 16 | 13,549 |
Nov 28, 2006 11:50 AM Last Post: memon |
|
Stencil shadows meant to look like this? | ia3n_g | 2 | 5,384 |
Nov 23, 2006 06:57 PM Last Post: akb825 |