Troubles with Stencil Buffer

Started by
9 comments, last by kburkhart84 18 years, 5 months ago
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]
Advertisement
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.
cool but how would I do it with a regular Windows Window because GLUT was just for testing.
Oh, this is simple, you just need to add this when rendering:

glDisable(GL_STENCIL_GAY);
Quote:Original post by TempHolder
cool 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).
I think the problem is with you. Just accept the Stencil Buffer for what it is.
Quote:Original post by Mattman
Oh, this is simple, you just need to add this when rendering:

glDisable(GL_STENCIL_GAY);


Quote:Original post by Anonymous Poster
I 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.


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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by LessBread
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.


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...


As a practical matter, I think you'll find that more accurately phrased titles get more accurate responses.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement