archangelwar's picture

Problems with tesselation

I was investigating the implementation of the Glu.Tess functionality in OpenTK, and I have run into a puzzling problem.

I was looking at http://codepad.org/jOEzlot5 this code which is included as an example.

Since I want to use the tesselator to create geometry for a DirectX application, I removed the graphics code and tried to form a Tesselator class. The result is http://codepad.org/P4gDhN2T this code.

The problem that I have is that when the main function reaches the tesse.EndPolygon() function, it spits out a Glu Error that basically states that it "needs Combine callback." What is strange is that the Combine callback that exists seems to already be working, as it creates the appropriate vertices in the list I created and assigned them the appropriate index (which is the basic functionality of the combine callback that I created). So the vertices are there, it just never gets to the Vertex callback (which prints out the order of the indices).

If you notice, the vertices I use are the same as the example's, only I do not include the extra info and use an integer index as the vertex callback data. If you uncomment the "triangle inside a rectangle" code, it works just fine.

Am I going crazy, or is there something simple I have missed?

Edit: If you notice, I have the wrong section commented in the code I posted. The problem section is the commented code, and the uncommented part is the "triangle in a box" portion. Since I ultimately only need a routine that will put "holes" in a rectangular region, the code may work as is for my purposes, but I really want the "star" code to work considering it works in the example and my code does not seem to be much different.

Edit 2: I noticed that I forgot to set the WindingRule, so I fixed that but I am still having the same problem...

Edit 3: I have been stepping through the debug to see what I can find. I set up the OpenTK as a project in my solution so it did not try and disassemble the .DLL when stepping through the code. I set a breakpoint at the tesse.EndPolygon() and stepped through it. It seems to go through the Combine callback once and as soon as it hits the end of the callback is when it throws up the error "need Combine callback." If I click OK, it puts me back at the end of the EndPolygon() function, but magically, the vertices list is completely populated with the 4 additional vertices (it creates 5 new ones for the tesselation and it errored after creating the first). Even though it is created the vertices, it does not call the Vertex callback at all.

I assume the problem is internal to the unmanaged TessEndPolygon()?

Edit 4: Sorry for the edits, I think this should be the last. I had the breakpoint in the wrong spot so I missed it going through the Combine callback multiple times. I now see it doing that (although it still throws the error immediately after executing the last instruction on the first go through), and all the values of the variables appear correct. It just seems to want to throw that error and then never perform the Vertex callback.

Edit 5: I think I know what the problem is. I am not correctly working with the pointers and letting things fall out of scope, etc. Is there an easier way to just pass integers to the vertex callback?


Comments

Comment viewing options

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

I am not correctly working with the pointers and letting things fall out of scope, etc.
This might be the problem. Unfortunately I don't of any other way to work with Glu.

Maybe this code could be of help. I haven't tested it myself, but it looks like it works and doesn't rely on pinvokes.

archangelwar's picture

I actually have it working now after spending a lot of time playing with it. I think my primary problem was working with safe and unsafe code in a very reckless way. The class works pretty well now and I have created a nice rectangle with 2500 nested "hole" polygons and it seems to work just fine. Thanks for the info though!