[gl2ps] Re: problem with hidden surfaces

Christophe Geuzaine c.geuzaine at ulg.ac.be
Sat Mar 5 18:48:44 CET 2005


Denis Roegel wrote:
> On Fri, Mar 04, 2005 at 11:58:09AM -0800, Christophe Geuzaine wrote:
> 
>>Denis Roegel wrote:
>>
>>>Concerning my previous problem, a complete example is here:
>>>
>>>  http://www.loria.fr/~roegel/tmp/problem.c
>>>
>>>The file is compiled under linux with
>>>
>>>  gcc -o problem problem.c gl2ps.c -lglut -lGLU -lGL
>>>
>>>press `s' to save and wait for the print `scene saved in tmp.ps'
>>>
>>>In certain orientations, the output is incorrect.
>>>
>>>I have tested with and without the OCCLUSION_CULL flag.
>>
>>Denis - Thanks for the code. I will look into it.
> 
> 
> Actually, in the meantime I have been able to test this code
> in another linux environment and I couldn't reproduce
> the problem. So, it may have something to do with my C compiler
> or maybe with the gs version ?


I didn't have much time to analyze your code, but here are a couple of
observations:

- When I use GL2PS_SIMPLE_SORT instead of GL2PS_BSP_SORT, everything
works fine.

- With GL2PS_BSP_SORT, the issue seems to be that GL2PS actually
traverses the tree in reverse compared to the ordering in the z-buffer.
With the following patch (that simply reverses the traversal) the output
is correct:

--- gl2ps.c     Sat Mar  5 09:14:07 2005
+++ gl2ps_test.c        Sat Mar  5 09:15:19 2005
@@ -4361,7 +4361,7 @@
     static GLint gl2psPrintPrimitives(void)
     {
       GL2PSbsptree *root;
-  GL2PSxyz eye = {0.0F, 0.0F, 100000.0F};
+  GL2PSxyz eye = {0.0F, 0.0F, -100000.0F};
       GLint used;
       void (*pprim)(void *data) = NULL;

@@ -4423,11 +4423,11 @@
         gl2psBuildBspTree(root, gl2ps->primitives);
         if(GL_TRUE == gl2ps->boundary) gl2psBuildPolygonBoundary(root);
         if(gl2ps->options & GL2PS_OCCLUSION_CULL){
-      gl2psTraverseBspTree(root, eye, -GL2PS_EPSILON, gl2psLess,
+      gl2psTraverseBspTree(root, eye, GL2PS_EPSILON, gl2psGreater,
                                gl2psAddInImageTree, 1);
           gl2psFreeBspImageTree(&gl2ps->imagetree);
         }
-    gl2psTraverseBspTree(root, eye, GL2PS_EPSILON, gl2psGreater,
+    gl2psTraverseBspTree(root, eye, -GL2PS_EPSILON, gl2psLess,
                              pprim, 0);
         gl2psFreeBspTree(&root);
         /* reallocate the primitive list (it's been deleted by


We should definitely look into this more carefully, though.

If you browse through the mailing list archives, I think someone
reported a similar problem last year. It would be nice to find a general
solution.


> 
> I have also run into other problems and I will write about
> them later. I have both problems of parts sometimes not appearing
> (for instance some faces of a standard icosahedron not colored,
> when the others are), and problems with text. I haven't been
> able to control the position of TeX text, even with the
> GL2PS_TEXT options. Do you have a working example?

I don't see any problems with the text produced by your example except
that you have to set the last argument of gl2psBeginPage to the output
file name ("tmp"), otherwise the \includegraphics command in the LaTeX
file will fail.

(I've attached my test files to this message: tmp.ps and tmp.tex are the
files created by your program; aa.tex is a small LaTeX file that
includes them; and aa.ps is the resulting document).

> 
> One small problem with LaTeX output: gl2ps
> outputs ``\makebox(0,0)'', but it should output
>         ``\makebox(0,0){''

Oops, good catch. This is now fixed in my version.

Thanks,

Christophe

-- 
Christophe Geuzaine
Applied and Computational Mathematics, Caltech
geuzaine at acm.caltech.edu - http://geuz.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: latex.tgz
Type: application/x-gzip
Size: 53497 bytes
Desc: not available
URL: <http://www.geuz.org/pipermail/gl2ps/attachments/20050305/df6e15a0/attachment.tgz>