I don’t know if this helps at all but here is most of my code dealing with textures…
/* here are some snipits from several functions: */
//initialization of important constants
ave_length = tot_len/num_e;
//average resolution desired - //maximum length – from “opposite corners” of surface
res_ave_des =(res_total_des*ave_length)/max_length;
alpha = res_ave_des/ave_length;
/******************************/
//decide size of texture to create
for(j=1;j<=8;j++)
{
if ( pow(2, j) > tLength*alpha )
{
sizeX = sizeY = pow(2, j);
break;
}
}
//then I create the texture…
// and write the ppm file
/*************************************/
//later…
// when drawing triangles
sprintf(texfile, “textures/%i.ppm”, i);
read_texture(texfile);
/* define texture map */
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texname);
glBindTexture(GL_TEXTURE_2D, texname);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_ FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
/*set up mipmaps */
mip_return = gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, img_width,img_height, GL_RGBA, GL_UNSIGNED_BYTE, texImage);
if (mip_return !=0)
printf("ERROR: %s
", gluErrorString(mip_return));
glBindTexture(GL_TEXTURE_2D, texname);
glEnable(GL_TEXTURE_2D);
/* calculation of texture coordinates */
calc_tcoord(triangle[i], texcoord);
glBegin(GL_TRIANGLES);
glTexCoord2d(texcoord[0], texcoord[1]);
glVertex3d(points[a].x, points[a].y, points[a].z);
glTexCoord2d(texcoord[2], texcoord[3]);
glVertex3d(points[b].x, points[b].y, points[b].z);
glTexCoord2d(texcoord[4], texcoord[5]);
glVertex3d(points[c].x, points[c].y, points[c].z);
glEnd();
glDisable(GL_TEXTURE_2D);
/*******************************************/
//in calc_tcoord function
//basic texture coords that are NOT between 0 and 1
// note: depends on what side is longest to where in //array what coordinate placed
// theta is the angle btwn the longest side and l2 side
tex[0] = 0;
tex[1] = 0;
tex[2]=alpha*(edges[longE].length);
tex[3]=0;
tex[4]=alpha*(edges[l2].length)*cos(theta);
tex[5]=alpha*(edges[l2].length)*sin(theta);