Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rendering Shadows

Started by aviel May 11, 2011 at 1:53 AM 3 replies 1.7k views
Original Post
aviel
aviel
So, I've been following nehe's guide to creating shadows, and for whatever reason the shadows just aren't rendering. Not having an excellent understanding of things like the stencil-buffer means I'm sort of learning things as I go along. I hate outsourcing my debugging, but I'm kind of stumped here. does anybody know what's wrong?

glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT );
glDisable( GL_LIGHTING );
glDepthMask( GL_FALSE );
glDepthFunc( GL_LEQUAL );
glEnable( GL_STENCIL_TEST );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFFL );

glFrontFace( GL_CCW );
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );

//shadow volume quad drawing code here
//I've checked to make sure that the code to draw the volume is running
//so I thought I'd spare you that

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glOrtho(0, 1, 1, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(0, 1);
glVertex2i(1, 1);
glVertex2i(1, 0);
glEnd();

glEnable(GL_DEPTH_TEST);
glPopMatrix();
glPopAttrib();

glEnable(GL_LIGHTING);
glDisable(GL_STENCIL_TEST);
glShadeModel(GL_SMOOTH);
glDisable(GL_CULL_FACE);


And I run that every frame. I have a feeling it's a problem in how I arranged the various gl*() commands. Only the large, screen-covering shadow is drawing with no parts being cut out.
owl
owl
This is not the answer to your problem but it might help. You may want to set up two little test programs, one running Nehe's code and the other one running your own. Then spot the parts that are different. It's very likely that it is there where your bug lies in. Once you detect the bug you might even be able to understand the "why".
[size="2"]I like the Walrus best.
aviel
aviel
I appreciate the advice, but I can assure you I've done that. I don't post for advice on fora just because my code didn't compile the first time and I'm too lazy to check what "missing semicolon on line 13" means.

I have actually copied most of his code verbatim, and the parts that aren't his I have tested work. Although I suppose there must be some part of that statement that is false, seeing as shadows don't display
owl
owl
I'm just about to start making my own implementation of this lesson myself. If I get to understand more after I'm done I might come back with some actual help. In the meantime I hope someone can lay you a hand.
[size="2"]I like the Walrus best.
aviel
aviel
Thanks, I appreciate it. Still can't figure out why it isn't working :/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.