I have what is essentially a file full of polygons (or “sectors”) that I want to render. Each polygon in the file may or may not be convex (but will always have at least 3 verts connected by straight lines).
I understand that I will need to tessellate the non-convex polygons and that if I attempt to tessellate all polygons (inc convex) then the results would be a disaster as you can not tessellate a convex shape with more than 6 sides?
In some detail, what is the best way of determining when I need to tessellate a polygon?
Does OpenGL have any functions that do this or should I be doing an internal angle > 180 thing or checking for boundary intersections on lines between points? Does anybody have a working snippet?
I do not understand what you mean that you cannot tesselate convex polygons with more then 6 sides ? you can tesselate convex and non convex with a huge number of sides without problems.
OpenGL does not have code for detecting complexity of a polygon, but you can find code to do it with google, it is also possible that GLU has some code for it built in (have a peek at the source code for Mesa or SGI’s implemenetation).
Using convex polygons with glBegin() is possibly a little slower then raw triangles(depending on hardware) so you might as well tesselate all triangles, at least that’s what I would have done.
[This message has been edited by mikael_aronsson (edited 02-12-2004).]
That makes sense as I would ideally tessellate all polygons (including conex) but I read somewhere about the 6 sides convex limit during my many hours on Google.
In a nutshell when I try to tessellate all of the polys my code crashes. After some debugging I have found the exact point…
I have put a snippet right here… www.jbcode.com/problems/TessellationCrash.htm
(This code is mish mash of stuff that I pulled/put together).
Usually the tesselation crashes if the callback functions are not properly defined, especially the ‘combine’ one. After you get the tesselation working, place the stuff into a display list (with GL_COMPILE). If you tesselate many polygons with many vertexes, do the tesselation per polygon (don’t consider many polygons as just contours in a big polygon), or it will go very slow.
Thats handy to know, the callback thing is quite confusing. Its an invalid memory read error so it must be going off the end of the array.
As for the contour thing it is one contour per polygon (perhaps I don’t even need the start and end countour statements?).
Ideally I want to texture my polygons and I think the callback does some colour merging thing. As its made up from sample code I am not exactly sure what it is doing.
Does anyone have an example of tessellation with textures?
Well this has all paid off. I have got the code to work fine (except for applying texture coords) and it was all related to the callbacks.
Basically I needed to copy my vertex data into an array of GLdoubles (the data was being fetched from a shared vert pool) and pass the array as the third parameter to the gluTessVertex function (instead of the v temp variable).
I have also eliminated the need for the seperate callback functions by specifying all of the callbacks as standard OpenGL function names (I am not worried about combine).
So all I need to do now is set up the texture coords! I have the textures there but the shapes are all one colour.