Sign in to follow this  
Kincaid

Stencil Test

Recommended Posts

I cant seem to get stencil thing from lesson 26 going for reflections, but that might be because im not drawing the 'floor' or whatever every frame, but i call it using display lists. Does the stencil not work while calling display lists during drawing the colormasked floor ?? really nothing is happening for as far as i can tell. I initialzed the stencil to 0, i clear GL_STECIL_BUFFER_BIT in the drawscene.... but no reflections .... Can anyone tell me what im missing here ?? code looks rufly like ; glColorMask(0,0,0,0); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glDisable(GL_DEPTH_TEST); glPushMatrix(); glTranslatef(x,y,z); glCallList(DL_LIST); glPopMatrix(); glEnable(GL_DEPTH_TEST); glColorMask(1,1,1,1); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glPushMatrix(); glScalef(1.0f, -1.0f, 1.0f); glCallList(DL_LIST); glPopMatrix(); [Edited by - Kincaid on August 3, 2005 7:52:38 AM]

Share this post


Link to post
Share on other sites
Looks like you forgot to set up alpha blending and make the floor transparent. Display lists have nothing to do with it, for sure - they have nothing to do with buffers at all, they are just a way of caching your geometry.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thats not it....tried even without the entire floor. It not some blend function. I just see the 'reflection'like a normal object of quads

Share this post


Link to post
Share on other sites
1. what happens if you draw it without using displaylists?
(displaylists are bad in some/most cases)

2. could you comment your code a little better.

3. if there is an apparent graphical bug visible, please post a screenshot.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
same deal when not using displaylists...
ill post some more code later on when I get the chance.
But its like there isn't any effect triggerd by any of the stencilstatements.

Share this post


Link to post
Share on other sites
You are probobly doing things in the wrong order, comment out some code and make shure that each part render ok.

then make shure you do it in the correct order

1. clear everything
2. render the geometry
3. render the floor to the stencil buffer, not to the color buffer
4. clear the z buffer
5. render the reflected geometry trough the stencil buffer.
6. render the floor with the right transparacy.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
By rendering to the stencil buffer it is sufficient to use colormask(0,0,0,0) ??

Share this post


Link to post
Share on other sites
here's the code I use:
I call glClearStencil(0) in init()
my drawscene contains ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
followed by

glColorMask(0,0,0,0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glDisable(GL_DEPTH_TEST);

glBegin(GL_QUADS); // kept it as easy as possible by just drawing
glVertex3f( 0, 0,0); // one quad. which now should be the area in
glVertex3f(50, 0,0); // which the following drawing should be
glVertex3f(50,50,0); // projected.. right ??
glVertex3f( 0,50,0);
glEnd();

glEnable(GL_DEPTH_TEST);
glColorMask(1,1,1,1);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glCallList(DL_GROUND); // and just call the ground.

So i expected to see the 'ground' only drawn in the 50x50 quad area, but instead it shows up everywhere, as normal...
now i do use keyboard input and other things in the original code, but nothing should interfere i guess, as i tried to load nothing but this.
So what stupid little thing (which it probably is, it mostly is....) am i missing ??

Share this post


Link to post
Share on other sites
don't know whats happening here try changing
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
to
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glEnable(GL_STENCIL_TEST);
but that's probobly not the problem.

or perhaps it might be the quad that is facing the wrong way

Share this post


Link to post
Share on other sites
still nothing,
tried both sides Culling also but still seeing everything as normal.
Could it be that I need to enable the stncilbuffer on my computer or maybe install something??


and immediately I realize that that's also not the case since NeHe lesson runs just fine, ans also some other codes I've dowloaded from the web concerning stencilling

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this