Advertisement

Stencil Test

Started by August 03, 2005 06:44 AM
9 comments, last by Kincaid 19 years, 1 month ago
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]
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.
Advertisement
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
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.
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.
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.

Advertisement
By rendering to the stencil buffer it is sufficient to use colormask(0,0,0,0) ??
yes
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 ??
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

This topic is closed to new replies.

Advertisement