polygon tessellation problem (solved)

I’m writing a program with a big blob that can be deformed in a variety of ways, so I’m using the tessellation features available in GLU. I’m new to this, so I’m really just trying to get the code from this tutorial to work.

Simply looping through the vertices of the blob and calling gluTessVertex on each one seems to work fine in most cases, but there seem to be two situations where it doesn’t. The first is if the edges of the blob ever intersect each other (similarly, the second example from the code linked, the star with intersecting edges, isn’t working for me).

The second, which is stranger to me because it doesn’t strike me as though anything particularly “weird” is going on, is when I pull out one vertex of the blob too far. If I remove the “System.exit(0)” call in the error callback linked above, the program keeps running (although it of course won’t render the tessellation), but I’m also drawing an outline of the blob with lines, so I can tell that the only thing that appears to trigger this error is if the angle between the two vertices is too small. Like, for three vertices in the outside of the blob, aligned like this: V . If the “lines” there get too close together (not even so close that the empty space appears to disappear), an error gets triggered and the tessellation doesn’t draw.

In both cases, it returns an “out of memory” error. I don’t know much about different kinds of errors in OpenGL, but it seems unlikely that it’s actually running out of memory (given that even the 5-vertex self-intersecting star in the example won’t render for me). I’ve been looking through the documentation trying to figure out what’s going wrong, but nothing obvious is standing out to me and I don’t understand OpenGL or tessellation on a deep enough level to figure it out any other way.

To give an example, here are two screenshots of my program side-by-side:

http://img139.imageshack.us/img139/9948/tessellationerrorpn1.gif

The one on the left is fine, but with one on the right the angle at the tip is too small, or it’s too “sharp,” or however that might be described because it’s the only difference (these screenshots were taken a few seconds apart), and it throws an error so no tessellation renders (of course, the outline drawn with lines still renders perfectly, so I know what it should look like).

And then of course any self-intersections in the blob at all, or even the 5-vertex star from the tutorial, also throw the same error and won’t render.

I doubt that the acuteness of the angle will matter, but what is significant is that the shape on the left is convex, while the shape on the right is not.
I’ve never used GLU tesselation stuff - can it handle concave shapes? If not, you might have to at least some tesselation manually.

Concavity doesn’t seem to be a problem. Here’s an extreme example:

http://img249.imageshack.us/img249/2168/concavezu2.gif

However, while deforming the big blob to make that shape, the tessellation broke and threw an error numerous times, whenever there was an extremely acute angle (each of those “arms” had to be pulled out away from the rest of the blob by pulling on a single vertex, but the program naturally rounds out shapes over time because there are “springs” between connected vertices).

From what I’ve read, GLU tessellation is primarily used for polygons that are: concave, self-intersecting, or have holes. It should be capable of generating a working triangle mesh for any shape I give it, especially for ones that don’t have holes or intersections (which is why it breaking for no other reason than what appears to be an acute angle is really weird).

A convex, solid polygon that doesn’t intersect itself can be made easily enough with GL_POLYGON (which is what I initially tried using, but didn’t work properly because the shape is rarely entirely convex except for at the very beginning, when it’s a circle).

EDIT: I should also note that, with the acute angle thing, it breaks regardless of which direction the acute angle is in. Up in my first post, the acute angle is a result of a vertex being pulled outward, but I can also pull a vertex inward, and the tessellation breaks if the angle generated there is acute too. And of course it still breaks for any intersecting edges, which it shouldn’t

Another EDIT: Given the nature of the simulation, the shape also gets slightly unstable if it’s pulled too far without giving the rest of the vertices a chance to get “caught up,” so to speak, and it’s possible (although I think it’s unlikely, because it would mean some vertices were bundled together, whereas the instability comes from them being too far apart) that there may be tiny intersections that just aren’t visible here. If I can get it to stop breaking when there’s an intersection, then, that might also fix it breaking for acute angles

Hmm, there goes my theory…
How about a degenerate edge, where the vertices are coincident?

Well, according to JOGL’s documentation for gluTessProperty (specifically the property GLU_TESS_TOLERANCE), coincident vertices are merged (as are coincident edges), but something weird just happened, so it may not even matter.

When I put the tutorial code in a project all by itself (which I admit really should have been my first step when it didn’t work, although it didn’t cross my mind at the time), it rendered the self-intersecting star. Now, I cannot for the life of me imagine why it should be any different in my other project, considering in that case I still just directly copied the code and there weren’t any shared variable names or anything, but something weird is clearly going on here. I’m going to experiment for a while, and then I’ll post back if it I still can’t get it to work (or if I can, just to let you know it’s been solved).

Holy…

Okay, it’s working. There is nothing wrong with the tutorial (nor is there a bug with JOGL or anything weird like that). The problem is that I am a stupid programmer.

  1. The star does render in my main program, just outside the viewing area (why it was crashing the first time I put it in, I have no idea - I probably messed something up then)

  2. The actual error was an index out of bounds exception, not an out of memory error (at least, not the way I was interpreting the words “out of memory”). Simply put, the tessellation callback implementations from the tutorial (and maybe GLU tessellation itself, although I haven’t checked yet) assumes that, when you pass it the float[] representing the vertex, that the array has 6 floats. The particular callback concerning this is only called when there are intersecting edges.

Because the last 3 floats represent color, I had been omitting them in the creation of the float array, as glColor3f also changes the color a tessellation if no additional color information is provided. Meaning, I was passing it an array of 3 floats; naturally, when it went in for the last 3, the tessellation broke and it threw an error. Which only happened when the edges intersected. Meaning the tessellation function is working perfectly, and my previous conjecture that maybe there were tiny intersections I just couldn’t see when I pulled it out too quickly (which I dismissed as “unlikely”) was also wrong, and there is something wrong elsewhere in my program.

Sorry for wasting your time; wish I had figured this out sooner.

Glad you got it sorted. It does always seem to be the case that posting ones problems for all to see is a crucial step in solving them yourself :slight_smile: