Hello Johannes,

Johannes Brunen wrote:
> Hi,
> 
> I have a problem of translating some native OpenGL code into OpenSG
> jargon.
> 
> Can anyone give me some hints how I should represent the following
> OpenGL code into OpenSG primitves? Additionally, am I going to have
> problems, if I later on try to do some shadowing of my scene, because of
> using the stencil buffer?

I think the ShadowViewport uses FBOs to store the shadow maps and does 
the shadow test in a shader.

> Can I save the current stencil buffer for the
> duration of my special task and restore it later after I have finished
> with it?

I don't think so, at the very least not easily.

> To shed some light on the code below. It adds some caps to the clipped
> geometry in order to visualize solid geometry.
> 
> drawClipPlaneGeom(int idx)
> {
>     // draw quad with clip plane number 'idx' its orientation ...
> }
> 
> drawGeometry()
> {
>     // some solid geometry
> }
> 
> unsigned int cpId[] = {GL_CLIP_PLANE0, GL_CLIP_PLANE1, ...,
> GL_CLIP_PLANE5};
> 
> void redraw()
> {
>     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
> 
>     glEnable(GL_STENCIL_TEST);
>     
>     for (int i = 0; i < 6; ++i) {
>         glClear(GL_STENCIL_BUFFER_BIT);
>         
>         glStencilFunc(GL_NEVER, 1, 1);
>         glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
> 
>         glEnable( cpId[i] );
>         drawGeometry();
>         glDisable( cpId[i] );
>         
>         glStencilFunc(GL_EQUAL, 1, 1);
>         glStencilOp(GL_KEEP, GL_ZERO, GL_ZERO);
> 
>         for (int j = 0; j < 6; ++j)
>             if (i != j) glEnable( cpId[j] );
>         drawClipPlaneGeom( i );
>         for (int j = 0; j < 6; ++j)
>             if (i != j) glDisable( cpId[j] );
>     }
>     
>     glDisable(GL_STENCIL_TEST);
> 
>     for (int i = 0; i < 6; ++i)
>         glEnable( cpId[i] );
>     drawGeometry();
>     for (int i = 0; i < 6; ++i)
>         glDisable( cpId[i] );
>     
>     glutSwapBuffers(); 
> }
> 
> Sorry, for bothering with these beginner questions, but I need some
> activation impetus.

hm, this is not exactly a beginner question, playing renderer tricks 
like this in general does not work to well with a scenegraph system, but 
I (well, it's Dirk's idea to be honest) think this particular case 
should be possible:

you need to build a scene like this:

     +----------------------------+-----------------------+
     |                            |                       |
MaterialGroup (mat1)      MaterialGroup (mat2)    MaterialGroup(mat3)
     |                            |                       |
Geometry (geo1)           Geometry (geo2)         Geometry (geo1)

geo1 is the object you want to draw, geo2 is a plane that coincides with 
  your clip plane.
mat1 has a StencilChunk that clears the stencil buffer first then does 
the inversion and a ClipPlaneChunk that enables one clip plane.
mat2 has a StencilChunk that has the settings you use for drawing the 
clip planes in you GL code and a ClipPlaneChunk that enables all clip 
planes you want to use.
mat 3 is the material you want your actual object to appear in.
Since these operations have to happen in the described order, you need 
to set the sort key on the materials to force that order.
To support more than one clip plane you'd have to add more copies of the 
left two branches.
I hope this description is not too terse, if you have questions please 
feel free to ask for more details.

        Hope it helps,
                Carsten

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to