PDA

View Full Version : texture mapping



sdwwq
09-12-2008, 10:10 PM
Hi
i posted a question about drawing an egg, i got that part working now i am stuck with the texture mapping part.

this is the code i am trying to initialize the texture coordinate.


for(int longVertCount=0; longVertCount<NUM_LONGITUDINAL_VERTICES; longVertCount++){ // along z axis
for(int circumVertCount=0; circumVertCount<NUM_CIRCUMFERENTIALL_VERTICES; circumVertCount++){ // x and y
a = (float)longVertCount/(float) (NUM_LONGITUDINAL_VERTICES);
b = (float)circumVertCount / (float)(NUM_CIRCUMFERENTIALL_VERTICES);
texture_coordinates[longVertCount][circumVertCount][1] = a*basketRadius;
texture_coordinates[longVertCount][circumVertCount][0] = b*basketHeight;
}
}





and this is the code for drawing the texture

for(int longVertCount=0; longVertCount<NUM_LONGITUDINAL_VERTICES-1; longVertCount++){ // along z axis
glBegin(GL_QUAD_STRIP);
for(int circumVertCount=0; circumVertCount<NUM_CIRCUMFERENTIALL_VERTICES; circumVertCount++){
glTexCoord2fv(texture_coordinates[longVertCount][circumVertCount]);
glVertex3fv(vertices[longVertCount][circumVertCount]);
glTexCoord2fv(texture_coordinates[longVertCount+1][circumVertCount]);
glVertex3fv(vertices[longVertCount+1][circumVertCount]);
}
glEnd();
}



but my texture mapping is wrong. any help??

trinitrotoluene
09-13-2008, 09:56 PM
Verify the range of your texture coordinates. It must be between
[0 1] if you don't want the texture to repeat on your egg. Because you multiply by basketRadius and basketHeight, I suspect that it is not the case.

Beware that you try to map a square texture on an egg, so expect some texture deformation and/or artifact on it (unless you have generated your texture for this kind of mapping).