Troubles with Stencil Buffer

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

Recommended Posts

Hey Iam trying to add Shadows and reflection to my game, but one huge problem, the Stencil buffer is acting gay, The shadows AND the reflectiosn display outside the quad I want it to be reflected on. I dont know why its doing this I should be constraint to where I set the Stencil Buffer to 1 from what I was reading, This is the code Iam using to Test why it isnt working, and it doesnt work either, Iam using GLUT for the window and Iam starting to think it might be, because of how Iam creating the window or I forgot to Instantiate something. Anyhow this is my code. this is only with the reflection. <code> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // glMatrixMode( GL_MODELVIEW ); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); DrawSurface(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glPushMatrix(); glScalef(1.0, -1.0, 1.0); glLightfv(GL_LIGHT0, GL_POSITION, g_lightPos); DrawCube(); glPopMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, g_lightPos); glEnable(GL_BLEND); DrawSurface(); glDisable(GL_BLEND); DrawCube(); glutSwapBuffers(); </code> I would Really Appreciate the help thanks to anyone who can tell me whats going on. [Edited by - LessBread on October 23, 2005 2:24:21 PM]

Share on other sites
Quote:
 Original post by TempHolder...Iam using GLUT for the window and Iam starting to think it might be, because of how Iam creating the window or I forgot to Instantiate something...
You need to ask for a stencil buffer when you're creating your window so if you're not doing that than that is indeed a problem. It's been a long time since I've used GLUT, but looking at the online spec for it you need to pass GLUT_STENCIL to glutInitDisplayMode.

That should fix it because the code you posted looks alright.

Share on other sites
cool but how would I do it with a regular Windows Window because GLUT was just for testing.

Share on other sites
Oh, this is simple, you just need to add this when rendering:

glDisable(GL_STENCIL_GAY);

Share on other sites
Quote:
 Original post by TempHoldercool but how would I do it with a regular Windows Window because GLUT was just for testing.
Using the Win32 API, you need to set the cStencilBits member of the PIXELFORMATDESCRIPTOR struct you pass to ChoosePixelFormat to the number of bits you want to use for your stencil buffer (usually 8).

Share on other sites
I think the problem is with you. Just accept the Stencil Buffer for what it is.

Share on other sites
Quote:
 Original post by MattmanOh, this is simple, you just need to add this when rendering:glDisable(GL_STENCIL_GAY);

Quote:
 Original post by Anonymous PosterI think the problem is with you. Just accept the Stencil Buffer for what it is.

Hey guys, if you don't have anything constructive to say, refrain from posting. If this were the Lounge or the Humor Portal, I wouldn't care, but it's not. Also, to the OP.

Kalidor has it right, I usually use 24 bit depth and 8 stencil, as this gives 32bits together and most video cards like this alignment.

Share on other sites
kburkhart84, Mattman and the AP actually have a point. The title of TempHolder question isn't accurate. "Being Gay" could mean a lot of things, none of them technical. To that end I'm going to change the title.

Share on other sites
Quote:
 Original post by LessBreadkburkhart84, Mattman and the AP actually have a point. The title of TempHolder question isn't accurate. "Being Gay" could mean a lot of things, none of them technical. To that end I'm going to change the title.

Yeah, they have a point, but I don't think they went about it right. The title and question should have been phrased different, yes. But I don't think sarcasm works as well as just flat out saying it how it is. Either way, good thing you changed the title...

Share on other sites
As a practical matter, I think you'll find that more accurately phrased titles get more accurate responses.

Share on other sites
Quote:
 Original post by LessBreadAs a practical matter, I think you'll find that more accurately phrased titles get more accurate responses.

Exactly why I agree with you. I just don't like the sarcasm of the above posters, though I agree with the point they wanted to make.