Texturing and Texture Mapping GLUTess Polygons?
How exactly does one provide texture coordinates and bind a texture for a GLUTess polygon? Than开发者_开发百科ks
I don't know If I understend you correctly. Texturing is described well in redbook. They use GLUT in the book, so you should find the answer in the examples.
In short: call glTexCoord2f(u,v) before call to glVertex (if you do not use VBO), where u,v are texture coordinates.
HTH
EDIT: Sorry, now I understand the question.
I have never used tesselators, but maybe I can help :-)
Tesselators only find points where new vertices should be created. Standard glVertex is used to send them to the GPU.
You can use your own function to draw vertex. If you register callback with
gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (*) ()) &vertexCallback);
then your function is called every time new vertex is created. You can also use
gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid (*) ()) &combineCallback);
to add some information to the vertex - like normals, colors, tex coordinates.
See redbook - chapter11 example 11-2
/* a different portion of init() */
gluTessCallback(tobj, GLU_TESS_VERTEX,
(GLvoid (*) ()) &vertexCallback);
gluTessCallback(tobj, GLU_TESS_BEGIN,
(GLvoid (*) ()) &beginCallback);
gluTessCallback(tobj, GLU_TESS_END,
(GLvoid (*) ()) &endCallback);
gluTessCallback(tobj, GLU_TESS_ERROR,
(GLvoid (*) ()) &errorCallback);
gluTessCallback(tobj, GLU_TESS_COMBINE,
(GLvoid (*) ()) &combineCallback);
/* new callback routines registered by these calls */
void vertexCallback(GLvoid *vertex)
{
const GLdouble *pointer;
pointer = (GLdouble *) vertex;
glColor3dv(pointer+3);
glVertex3dv(vertex);
}
void combineCallback(GLdouble coords[3],
GLdouble *vertex_data[4],
GLfloat weight[4], GLdouble **dataOut )
{
GLdouble *vertex;
int i;
vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
vertex[0] = coords[0];
vertex[1] = coords[1];
vertex[2] = coords[2];
for (i = 3; i < 7; i++)
vertex[i] = weight[0] * vertex_data[0][i]
+ weight[1] * vertex_data[1][i]
+ weight[2] * vertex_data[2][i]
+ weight[3] * vertex_data[3][i];
*dataOut = vertex;
}
It should be sufficient to bind texture as usually - do it before drawing with tesselators.
HTH
The tessellator should interpolate texture coordinates based on the vertices it was derived from. Another method would be to use automatic texture-coordinate generation if that works for the situation.
精彩评论