Anonymous's picture

OpenGL tessellator

Hello Everybody,

I'm quite new to OpenGL, but I need to use its tessellation algorithm to retrieve the resulting triangles.
I've seen that OpenTK contains the tessellation class but being completely new to the toolkit I'm having problems to understand what to do and I couldn't find any sample.
Yesterday i spent some time trying to do the same with the TaoFramework only to discover that their implementation is bugged.

Forgive me if the problem sounds silly.
What I'm now trying to achieve is really simple (to describe).

Eventually I'll need to tessellate a polygon with a hole inside but for the moment a simple rectangle tessellation would be ok.

Apparently i should use something like

Dim rect As Double()() = New Double(4)() {New Double() {50, 50, 0}, New Double() {200, 50, 0}, New Double() {200, 200, 0}, New Double() {50, 200, 0}, New Double() {0, 125, 0}}
Dim mydata As IntPtr = IntPtr.Zero
Dim mycallback As IntPtr
Dim t As Integer = OpenTK.OpenGL.Glu.NewTes()
OpenTK.OpenGL.Glu.TessCallback(t, OpenTK.OpenGL.Enums.TessCallback.End, mycallback)
OpenTK.OpenGL.Glu.TessVertex(t, rect(0), mydata)
OpenTK.OpenGL.Glu.TessVertex(t, rect(1), mydata)
OpenTK.OpenGL.Glu.TessVertex(t, rect(2), mydata)
OpenTK.OpenGL.Glu.TessVertex(t, rect(3), mydata)

But what kind of of structure should be behind the two IntPtr's?

I don't need to display the resulting triangles but to retrieve a list of them along with vertex coordinates.

Please note that although I'm patching a VB application any c# code will be ok for me.
Any help will be highly appreciated,


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Unfortuantely, the tesselator class isn't implemented yet.

Can you link to a good tesselation tutorial? I'll try to implement the functionality for the next release (in about two weeks or so, although it will be available in SVN before that).

Anonymous's picture

Hi there,
thank you for answering.

To see a working example of tesselation (invoking a dll in c++) you can go to:

for a generic introduction to tessellation the firs half of chapter 11 could help your scope.
This also contains a small sample

For information on the callbacks and when they should be fired:

I'm not sure to be able to help you in this, but if you give me any hint to start I'd like to try.

the Fiddler's picture

Thanks for the links. There are two things to do for GLU tesselation:

  1. Add the correct data definitions and delegates for the callbacks.
  2. Write some programs to verify correctness.

I'll use these links and the GLU specs to add the correct definitions; it would be great if you could write a couple of small test applications (which could then be added as examples in the distribution, for other people to learn from :) )

I'll upload a zip here when the initial work is done (probably today or tomorrow), so you can take a look at it.


Anonymous's picture

I'll be glad to help writing some examples.

Meanwhile I've also continued searching for Tessellation implementation in managed code and I've found


here I've linked the file with some definitions such as
#region GLU Tesselation Constants
#region GLU Tesselation Callbacks
#region GLU Tesselation Functions

but in the same folder the tessellator.cs file contains a class capable of tessellating a System.Drawing.Drawing2D.GraphicsPath

Apparently it's the only OpenSource project that "uses" the tessellation functions (some others imports them, though).

Thanks Again,

the Fiddler's picture

Thanks, this will help cross-check the definitions.

the Fiddler's picture

Just dropping by to say I am still working on this. I haven't been able to find a solution that is both elegant and simple to implement yet (this topic is much more complicated than it sounds at first). I'm currently looking into dynamic IL generation, I'll get get back when I find something.

Update 1: I think I may have found a solution. Testing!

Update 2: The solution is working, but there is a problem with the bindings (some parameter combinations are incorrectly bound), which will take some time to correct.

Update 3: I have commited the updated code. You can now specify and use tesselator callbacks and that callbacks will be called, but it seems there *might* be a problem with array parameters passed to the callbacks. I have used the RedBook Tesselation example to test, which doesn't seem to work for this reason.

Unless someone knowledgeable enough shows up, I will not work on this code anymore. A fully managed triangulation solution (download the zip with the C# code) is both easier to use and *much* more safe.

Anonymous's picture

Thanks for your effort!
I do not very strong both with calling unmanaged DLLs nor with OpenGL, nevertheless I'll try to understand the code next week and to see if I can figure out what's wrong with it. In that case I'll also prepare a sample.

Kudos to the project and to your commitment, Claudio

the Fiddler's picture

Update 4: Everything now works :)

Unfortunately, the code requires the use of unsafe function pointers in the "combine" callback. I've tried to write a Tessellator class to wrap the ugly stuff up, but it didn't work in the end (when you start getting "Fatal Execution Engine Exceptions" you know things are starting to get ugly). There are three possibilities now:
a) Either someone much more knowledgable in the .Net ways shows up and finishes the task, or
b) I make the Tessellator class accept only arrays of doubles (quite restrictive, but this will work), or
c) we call it quits and leave the raw GLU API for tessellation.

I'm leaning towards option c at the moment, if only because there is more important work to do first (fullscreen support). This doesn't mean this stuff won't be improved in the future, just that it will stay as is for a little while.

Here is an example of using GLU/OpenTK. As you can see, the delegate declarations aren't very intuitive, so just copy and paste them directly.

Update 5: The latest code and binaries can be find in this post :)

If I may ask, what will you be using GLU tessellation for?

Anonymous's picture

That's great news! Thanks!

I'm trying to write a viewer for the PDMS file format.
PDMS is a plant oriented CAD (piping and such) and it doesn't export common CAD file formats.
One of the possible exported objects is composed of a number of possible surfaces defined by the bounding polygons. There's where I need to use the tessellation.

I've also had a look at the "managed triangulation solution" you mentioned before but as far I understand it cannot handle the many options that GLU tessellation does.

I'll be tied up with a lot of work up to wednesday night, and I'll try my best to look into the tesselllation problem and prepare some more samples starting from thuursday.

Cheers, Claudio

the Fiddler's picture

Thanks, sounds interesting! (Please submit a couple of pictures when your project is done - if that is allowed by your employer :) )

One more thing: there is no demand to write samples or anything, but it would be nice to verify that GLU does work as expected.