Jump to content
  • Advertisement
Sign in to follow this  
aviel

Rendering Shadows

This topic is 2774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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".

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!