我正在尝试在opengl中对一个圆锥体进行纹理贴图。这是我的代码。
glPushMatrix();
float radius=1;
float r=1;
float h=1;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texSet[2]);
float t,s;
float i=0.05;
for(s=0.0;s<1.0;s+=i)
{
for(t=0.0;t<=1.0;t+=i)
{
float r=((h-t)/h)*radius;
glBegin(GL_POLYGON);
glTexCoord2f(s,t);
glVertex3f(r*cos(2*M_PI*s),t,r*sin(2*M_PI*s));
glTexCoord2f(s+i,t);
glVertex3f(r*cos(2*M_PI*(s+i)),t,r*sin(2*M_PI*(s+i)));
glTexCoord2f(s+i,t+i);
glVertex3f(r*cos(2*M_PI*(s+i)),(t+i),r*sin(2*M_PI*(s+i)));
glTexCoord2f(s,t+i);
glVertex3f(r*cos(2*M_PI*s),(t+i),r*sin(2*M_PI*s));
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
glPopMatrix();
我没有得到正确的结果。我在这里做错了吗?