well i’d like to tesselate an object using the tesseletor of glu and the recover the vertex given to store them

the problem is that i don’t know how to recover them? when my callback function is called? which parameteres are given to this function?

here is my code :

My3ds = lib3ds_file_new();

GLUtesselator *tessobj;
	tessobj = gluNewTess();
	gluTessCallback(tessobj, GLU_TESS_EDGE_FLAG, NULL);
	gluTessCallback(tessobj, GLU_TESS_VERTEX, vertex_fn);
	for (int i=0; i<model.ncares; i++){
		gluTessBeginPolygon(tessobj, NULL);
				for (int j=0; j<model.cares[i].nverts; j++){
					gluTessVertex(tessobj, model.cares[i].verts[j], vertex_data[j]);

and in my callbask function i would like to insert those vertex to a .3ds file using lib3ds

void *vertex_fn(){
	Lib3dsMesh *mesh;
	mech->pointL = vertex_data; 	// how to recover the coordinates (vertex_data)?
					// insert a face after 3 given vertex
					// or insert a point corresponding to the vertex?
	lib3ds_file_insert_mesh(My3ds, mech);


The prototype for the vertex function should be:
void vertex_fn(void *vertex_data)

vertex_data is exactly the same as the corresponding parameter of gluTessVertex, it is just handed over to you.

Don’t forget the BEGIN, END and COMBINE callbacks. Especially the BEGIN callback, because it tells you what to do with the vertices (are they triangles, tristrips, fans, …?)

To understand when exactly the callbacks are called, just imagine setting the BEGIN callback to glBegin, the VERTEX callback to a glVertex variant and the END callback to glEnd. They will be called exactly in the order required to draw the tesselated polygon.

The combine callback is called when the tesselator produce a new vertex thats not in your original data set.

precisely, just don’t forget to copy the data from the pointer given by the vertex call. That pointer that’s passed there may become invalid pretty quickly.

ok but i have a question
the aim of a tesselation is to triangularise an object or am i wrong?

if it’s true i can’t see how my callback function will deel with that

you told me that gluTessVertex is like glVertex! in this case i will receive the vertex in the same order that they are given for a polygon and no triangularisation will be realised!

i am newbee in tessalation so sorry if what i said is stupid!

i forgot to login “adidmamah” is “happy” :slight_smile:

With tesselation, you can triangularize arbitrary polygons, and you get back primitives that OpenGL can draw directly.

The input polygons can be concave, have holes, …, all the things that OpenGL cannot handle itself. The output will be a list of glBegin, glVertex and glEnd calls that are needed to draw the input.

gluTessVertex is not like glVertex, the TESS_VERTEX callback function that you can set with gluTessCallback is like glVertex.

ok thanks man :slight_smile:
so if i understand well with a function like this one :
void vertex_fn(void *vertex_data)

the callback function “vertex_fn” will be called as many times as necessary to send me all the vertices
and each time i will receive in “vertex_data” a vertex in the right order, in order to draw triangles