COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### help with simple polygon tessellation

• Follow

```I posted a few days ago about a problem I was having with drawing a
simple 2-sided polygon (see
http://esl.eng.ohio-state.edu/~gfp/SWExamples/opengl_polygon.gif), and
it was pointed out to me that the polygon wasn't a simple convex
polygon and would need to be tessellated to be correctly drawn.  Since
then I have researched the tessellation facilities in OpenGL and gotten
the 'Star' example to run correctly in C and C++.  However, I have yet
to get my polygon to draw correctly, so I must still be doing something
wrong.

Here is a code snippet that tessellates and draws the 5-pointed star
correctly, resulting in the figure shown in
http://esl.eng.ohio-state.edu/~gfp/SWExamples/CompleteStar.gif.

GLdouble star[5][6] = {2500., 500., 0.0, 1.0, 0.0, 1.0,
3250., 2000., 0.0, 1.0, 1.0, 0.0,
4000., 500., 0.0, 0.0, 1.0, 1.0,
2500., 1500., 0.0, 1.0, 0.0, 0.0,
4000., 1500., 0.0, 0.0, 1.0, 0.0};

GLUtesselator *tobj;
tobj = gluNewTess();

gluTessCallback(tobj, GLU_TESS_BEGIN, (void (CALLBACK *)
())beginCallback);
gluTessCallback(tobj, GLU_TESS_VERTEX, (void (CALLBACK *) ())
vertexCallback);
gluTessCallback(tobj, GLU_TESS_END, (void (CALLBACK *) ())endCallback);
gluTessCallback(tobj, GLU_TESS_ERROR,(void (CALLBACK *)
())errorCallback);
gluTessCallback(tobj, GLU_TESS_COMBINE, (void (CALLBACK *)
())combineCallback);

gluTessBeginPolygon(tobj, NULL);
gluTessProperty(tobj, GLU_TESS_WINDING_RULE,
GLU_TESS_WINDING_POSITIVE);
gluTessBeginContour(tobj);
for( int cnridx = 0; cnridx < 5; cnridx++ )
{
//   These 3 lines produce a partial star
//   GLdouble glvert[6] = { star[cnridx][0], star[cnridx][1],
star[cnridx][2],
//		star[cnridx][3], star[cnridx][4], star[cnridx][5] } ;
//   gluTessVertex( tobj, glvert, glvert ) ;

//this line produces a complete star
gluTessVertex(tobj, star[cnridx], star[cnridx]);
}
gluTessEndContour(tobj);
gluTessEndPolygon(tobj);

glFlush() ;

However, if I comment out the gluTessVertex(tobj, star[cnridx],
star[cnridx]); line and uncomment the other three lines, I only get the
partial star shown in
http://esl.eng.ohio-state.edu/~gfp/SWExamples/PartialStar.gif.  Putting
TRACE lines in the combine & vertex callback routines shows that the
combine callback sees the same 'new vertex' requests for both versions,
but the vertex callback shows that for the 'partial star' case,
although the same number of points are emitted by the tessellator,
several of them are duplicates.

Can anyone give me a clue as to what I'm doing wrong here?

TIA,

Frank

```
 0
Reply paynter.5 (3) 1/9/2005 5:10:27 PM

```Frank wrote:
> gluTessBeginPolygon(tobj, NULL);
> gluTessProperty(tobj, GLU_TESS_WINDING_RULE,
> GLU_TESS_WINDING_POSITIVE);
> gluTessBeginContour(tobj);
> for( int cnridx = 0; cnridx < 5; cnridx++ )
> {
> //   These 3 lines produce a partial star
> //   GLdouble glvert[6] = { star[cnridx][0], star[cnridx][1],
> star[cnridx][2],
> //		star[cnridx][3], star[cnridx][4], star[cnridx][5] } ;
> //   gluTessVertex( tobj, glvert, glvert ) ;

When you call gluTessVertex, you must give a different object for each
vertex and not change them until after the tesselation is done. GLU
stores the pointers you give and does not copy the object -- it doesn't
know how large the object is anyway.

--
Andy V
```
 0

```Andy,

Thanks thanks thanks thanks!  I've been beating my head against this
one for at least 3 days, pretty much non-stop, and your answer was
exactly what I needed. My 2-sided planar polygons are happily
tessellating away now, thanks to you ;-).

Not that I care a whole lot at this point, but is this behavior
documented anywhere?  I have practically memorized the MSVC
documentation (such as it is) on gluTessVertex/gluTessCallback, and saw
nothing that even hinted at this.  I've only been working with OpenGL
for a couple of years, and don't have much experience with callback
functions, so maybe that's the part I was missing.
Thanks again,

Frank

```
 0

```Frank wrote:
> Andy,
>
> Thanks thanks thanks thanks!  I've been beating my head against this
> one for at least 3 days, pretty much non-stop, and your answer was
> exactly what I needed. My 2-sided planar polygons are happily
> tessellating away now, thanks to you ;-).

Great!

>
> Not that I care a whole lot at this point, but is this behavior
> documented anywhere?  I have practically memorized the MSVC
> documentation (such as it is) on gluTessVertex/gluTessCallback, and saw
> nothing that even hinted at this.  I've only been working with OpenGL
> for a couple of years, and don't have much experience with callback
> functions, so maybe that's the part I was missing.
> Thanks again,

It certainly isn't directly stated. There are some clues in the callback
section:

------------------
It [the begin callback] is followed by any number of vertex callbacks,
which supply the vertices in the same order as expected by the
corresponding glBegin call. vertex data is a copy of the pointer that
the user provided when the vertex was specified (see gluTessVertex).
------------------

and in the combine callback:

------------------
The user must allocate another vertex, interpolate parameters using
vertex data and weights, and return the new vertex pointer in outData.
This handle is supplied during rendering callbacks. For example, if the
polygon lies in an arbitrary plane in 3-space, and we associate a color
with each vertex, the combine callback might look like this:
------------------

You just have to know how to read between the lines :-)

--
Andy V
```
 0

```> It certainly isn't directly stated. There are some clues in the callback
> section:

I'd recommend using the OpenGL Red Book and not Microsoft's documentation
(as they want you to use Direct3D and not OpenGL so their documentation is
poor). This point is emphasised in the Red Book, IIRC.

Cheers,
Jon.

```
 0

4 Replies
335 Views

Similiar Articles:

7/22/2012 11:50:43 AM