Silhouette using stencil buffer

Silhouette using stencil buffer

Post by Balaji » Fri, 27 Jun 2003 17:08:11



Hi all,
I was using Silhoutte sample code from opengl.org and it was working
fine, but it gives the outer pixels of the stencil buffer. does anyone
know some simple technique
to get the inner pixels (ie, the sihouette pixels should be lying just
inside the object).

Code snippet:-
---------------------------------------------
  int i;

  glClear(GL_STENCIL_BUFFER_BIT);
  glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
  glEnable(GL_STENCIL_TEST);
  glStencilFunc(GL_ALWAYS, 1, 1);
  glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

  glDepthMask (GL_FALSE);

  for (i = -1; i < 2; i += 2) {  /* set stencil around object */
    glViewport(i, 0, winWidth + i, winHeight);
    curobj();
  }
  for (i = -1; i < 2; i += 2) {
    glViewport(0, i, winWidth, winHeight + i);
    curobj();
  }

 /* cut out stencil where object is */
  glViewport(0, 0, winWidth, winHeight);
  glStencilFunc(GL_ALWAYS, 0, 0);
  curobj();

  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

  glStencilFunc(GL_EQUAL, 1, 1);

  glDisable(GL_LIGHTING);

  glDepthMask (GL_TRUE);

  glColor3f(0.f, 1.f, 0.f);  /* draw silhouette red */
  glRotatef(-viewangle, 0.f, 1.f, 0.f);

  glRecti(-50, -50, 50, 50);

  glRotatef(viewangle, 0.f, 1.f, 0.f);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glDisable(GL_STENCIL_TEST);
---------------------------------------------
Thanks,
Balaji

 
 
 

1. problem using stencil buffer for shadow volume

This may sound like a stupid question, but the problem I have is when I
try to project a dynamic shadow (using stencil buffer) to things like a
wall or roof, I run the risk of having shadows on both sides of
wall/roof, or having the shadow being cast through the wall/roof. The
root cause seems to be the length of the shadow volume that cuts
through polygons that it shouldn't. Is there any quick fix to this? Or
do I just have to make the wall and roof thick enough so that shadow
volume won't penetrate them?

Thanks for your help.

Sent via Deja.com http://www.deja.com/
Before you buy.

2. perso

3. Looking for: Shadow Methods using common Hardware features - An alternative to Stencil Buffer Method

4. MFC/SDK Linking Problem

5. Tutorial on using Stencil Buffer

6. Max 2.5 Problems on new system

7. Looking for: Shadow Methods using common Hardware features - An alternative to Stencil Buffer Method

8. Again about PRINTING !

9. Clipping a Shadow Using the Stencil Buffer

10. Using the Stencil buffer and BSP effiency

11. stencil buffer sample program using GL_INVERT StencilOp

12. Using Stencil buffer ??

13. Showing depth complexity using stencil buffer