helpe me with this, please

Actually i want to dig down a hole or a river on a plane, i want to texture the rest part of the plane without having the digged part textured or covered. Is there a better solution than the one below which i posted a fews days ago but no anwser?
There are a number of polygons (which could be of any shape, may not be the polygon of openGl definition) on a plane(a rectangle), now i want to fill the rest of the plane with QUADS or TRIANGLE or any valid openGL polygon.
Anyone has any idea? or are there any existing algorithms that just fix this?
Thanks in advance!

Hi,

You can use the glu tesselators. Search for them, I think there should be plenty of tutorials. Basically you feed the tesselator your polygons and the plane and it spits out the opengl primitives.

-Ilkka

Hi Ilkka:
Thanks. I remember it was you that helped with my prevoius problem(finding the lost point).
I really should thank you a lot!

I did some try on tesselator, below is the code copied from a book, but nothing appeared on screen.

Regards
tess=gluNewTess();
double vv[4][3];
vv[0][0]=-5;vv[0][1]=5;vv[0][2]=0;
vv[1][0]=-5;vv[1][1]=0;vv[1][2]=0;
vv[2][0]=5;vv[2][1]=0;vv[2][2]=0;
vv[3][0]=5;vv[3][1]=5;vv[3][2]=0;
gluTessBeginPolygon(tess,NULL);
gluTessBeginContour(tess);
gluTessVertex(tess,vv[0],vv[0]);
gluTessVertex(tess,vv[1],vv[1]);
gluTessVertex(tess,vv[2],vv[2]);
gluTessVertex(tess,vv[3],vv[3]);
gluTessEndContour(tess);
vv[0][0]=-2;vv[0][1]=4;vv[0][2]=0;
vv[1][0]=-2;vv[1][1]=1;vv[1][2]=0;
vv[2][0]=2;vv[2][1]=1;vv[2][2]=0;
vv[3][0]=2;vv[3][1]=4;vv[3][2]=0;
gluTessBeginContour(tess);
gluTessVertex(tess,vv[0],vv[0]);
gluTessVertex(tess,vv[1],vv[1]);
gluTessVertex(tess,vv[2],vv[2]);
gluTessVertex(tess,vv[3],vv[3]);
gluTessEndContour(tess);
gluEndPolygon(tess);
gluDeleteTess(tess);

You have to specify the callbacks. The tesselation object uses these to output geometry. Easiest way is to bind them directly to the opengl drawing commands, like this:

gluTessCallback(tess, GLU_TESS_BEGIN, glBegin);
gluTessCallback(tess, GLU_TESS_VERTEX, glVertex3dv);
gluTessCallback(tess, GLU_TESS_END, glEnd);

You could also create your own callbacks to collect the geometry to your own data structures, but that’s a little harder, I suggest you start with these. You can draw it in a display list once so you don’t have to use the tesselation object every frame.

-Ilkka

Hi,
I got the error message below for gluTessCallback(tess, GLU_TESS_BEGIN, glBegin); (but not for glEnd)
Strange, the exactly same code used in an example has no problem. Maybe i missed something.Frankly i don’t quite understand the way Callback working.
Regards and looking forward to your reply

Liuya

error C2664: ‘gluTessCallback’ : cannot convert parameter 3 from ‘void (unsigned int)’ to ‘void (__stdcall *)(void)’

Looks like some c/c++ weirdness. I don’t know, I’ve never done it in c. It doesn’t seem to allow glBegin as an argument, since it’s not of the right type. Some typecast could help. I really don’t know, maybe somebody who knows c a little better could help. In the meantime, you can search for other tutorials, I’m sure somebody has solved that already.

-Ilkka

Visual C++ is telling you that the argument you passed for the callback (glBegin) is not of the correct type. It appears that the callback is supposed to be a function which takes no arguments (like glEnd) not a function which takes an integer argument (like glBegin).

But the callback function can be of several types. It’s arguments are specified by the second argument of the tessCallback call. The function you pass is ultimately just a pointer, I’m sure it’s just a matter of typecasting it. I think the easiest fix would be to check the type the tessCallback expects in your glu.h, and cast the glBegin to whatever that is.

-Ilkka

hi

i fixed the compilation error by searching some old messages here. But That pice of code still does nothing. Now i am also worried about the texture of the generated triangle or anything since i don’t have or don’t know how to have texturecoord.
regards, liuya

Sorry, I made a mistake, the arry for 2 contours should be seperated. It’s working now.
But as i worried, i need to know how many triangles and which 3 vertexs make each of these triangles in order to do proper texture, could you give me more help?
Thanks a lot

Hi

Now it seems i made some kind of progress. I am gussing the way to find out the number of triangle and its vertex is to do some coding for my own callback Begin/vertex/End by using the parameters and the order calling the functions as the inputs. Is that the idea?
If so now the problem comes to a basic C question:
The code now steps to my own callback"gluTessCallback(tess,GLU_TESS_VERTEX_DATA,myvertextdata)". As some book says the prototype of this callback looks like:
void myvertexdata(void *vertex_data,void *polygon_data),
but how can i access vertex data(double vv[][3] which was declared as some kind of global) through the parameter “vertex_data” (even i can see the the pointer is pointing to where it is supposed to)
Anyone be so nice as to show me how in detail?

I think you can insert it into a vector like this:

double * v;
v = (double *)vertex_data;

But I’m no c expert so forgive me if it doesn’t work. An alternative way to apply a texture would be using the automatic texture coordinate generation, here are the istructions for that: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/011409.html

-Ilkka

Hi Dear Ilkka:

You are great! I got the data i want! I will stick to this solution.
I am a chinese, I’d like to make friend with you, if you have a chance to visit china(but don’t come at this moment, we have some horrible disease spread out), I will be happy to treat you. My e mail is frank.ya@163.net
Best regards, Liuya