First off, I used the following resource to generate my circles.
http://slabode.exofire.net/circle_draw.shtml
Now I am trying to apply a texture to a circle using the following, but I just cant seem to get the math right.
void drawCircle(float cx, float cy, float cz,
float r, int points,
float red, float green, float blue)
{
float theta;
theta = 2 * PI / (float)points;
float c = cosf(theta);//precalculate the sine and cosine
float s = sinf(theta);
float t;
int i;
float x = r; //we start at angle = 0
float y = 0;
float tx = c * 0.5 + 0.5;
float ty = s * 0.5 + 0.5;
glPushMatrix();
glTranslatef(cx, cy, cz);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, newBelgTex);
glBegin(GL_POLYGON);
// glColor3f(red/255.0, green/255.0, blue/255.0);
for(i = 0; i < points; i++)
{
glTexCoord2f(tx, ty);
glVertex2f(x, y);//output vertex
//apply the rotation matrix
t = x;
x = c * x - s * y;
y = s * t + c * y;
// Not sure how to update tx and ty
}
glVertex2f(-r, 0);
glEnd();
glPopMatrix();
}
I have tried a few different things but all have seemed to fail in terms of updating tx
and ty
properly.