Texturing triangle fans
Posted: Sat Oct 17, 2009 1:28 am
It's late, and I got (the texture coordinate part of) this code from wherever, and it works just fine, but I'm not sure why the equation for the texture coordinates is what it is. Why "+1 * 0.5"? (Java)
Code: Select all
float texcoord[] = {0.5f, 0.5f};
texture.enable();
texture.bind();
gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
// Clock face
gl.glBegin(GL.GL_TRIANGLE_FAN);
{
//gl.glColor3f(1, 1, 1);
gl.glTexCoord2fv(texcoord, 0);
gl.glVertex2f(0, 0);
final float max = NUM_PARTS * ANGLE_CHANGE;
for (float rad = 0; rad < max; rad += ANGLE_CHANGE) {
final double cosr = cos(rad);
final double sinr = sin(rad);
texcoord[0] = (float)((cosr + 1.0) * 0.5); //<--this part
texcoord[1] = (float)((sinr + 1.0) * 0.5); //<-- & this part
gl.glTexCoord2fv(texcoord, 0);
gl.glVertex2d(cosr * radius, sinr * radius);
}
}
gl.glEnd();
texture.disable();