PDA

View Full Version : TESS AND TEXTURE!

02-23-2006, 02:23 AM
hi everyone, hope to find help again from you...
i used tessellation for drawing a polygon and now i would put a texture on it... it's like using glVertex that before i have to put the coordination of my texture or i need to do something else??? then another thing i would know if it's there's some other way to give the x,y,z coordination in glutessvertex; cause i have a matrix of structs and i must use it to give my vertex and not a vector...

songho
02-23-2006, 07:46 AM
<Fido>,
As you know that gluTessVertex() requires 3 params. The first one is simply the pointer to the tessellator object.

The second param is the pointer to the beginning of vertex coords. this (x,y,z) value will be used to perform tessellation. (Tessellator needs vertex coords info to tessellate a polygon.)

The third param is the pointer to vertex data, not only vertex coords but also normal, colour and UV coords. If you are interested in only the vertex coords to draw, then it would be same as the second param.

However, if you need extra info to draw polygon, for example, UV (texture) coords, the third param should be something else. Tessellator will pass the third param to your vertex callback function.

Here is an example. Let's say you have a struct with vertex coords and UV coords:

struct MyVertex {
GLdouble x;
GLdouble y;
GLdouble z;
GLfloat u;
GLfloat v;
};
...
MyVertex vertices[10];Then you call gluTessVertx() like this:

...
gluTessVertex(tess, &amp;vertices[0].x, &amp;vertices[0]);Notice that the second param is pointing "x", which the first element of vetex coords, and the second param is pointing to the struct variable.

void CALLBACK tessVertexCB(const GLvoid *data)
{
// cast back to MyVertex struct
const MyVertex *ptr = (const MyVertex*)data;

// set UV
glTexCoord2f(ptr->u, ptr->v);

// set vertex
glVertex3d(ptr->x, ptr->y, ptr->z);
}Remember that once tessellator has done its job, tessellator calls your vertex callback function with the third param. It can be anything, a pointer to class, struc or vector template, etc.
These are just snippets, so I cannot guarantee it will work. But I hope you get the idea.
Regards.
==song==