View Full Version : Strange circle texturing

05-30-2017, 07:37 PM
Hello guys

I find a operation that can apply a texture on a circle and he do it well but i can figure out why it's working

Here is the code

void shape::addCircle(float radius,glm::vec2 pos,int numVer)
//Add the first vertice and the center of the circle
vec.push_back(vertex(pos, pos, glm::vec3(0, 0, 0)));
//Add the first vertice to count vertices
//Index for glDrawElements.
vector<GLuint> index;
//here we take the number of vertices wanted and we multiply it by 3 because the circle is made with triangle
int Vertice = 3 * numVer;
//And here is the operation as i understand we take all of the angle of the triangle and we multuply it with the radius / right angle and as it's seems he can do all the texture you want
float spriteRadius = 180 * (radius / 90);
float pi = 3.1415926f;
//loops throught all of the vertices + 1 because we need a last vertices for the last triangle
for (int i = 0; i <= Vertice+1; i++)
//same as we do for the loop
indexs.push_back(countVertice+ i);
//operation for the circle
float ope = 2*pi * i / Vertice;
//We add it to a vector and the vector gonna be send to the gpu
vec.push_back(vertex(glm::vec2(pos.x + (radius * cos(ope)), pos.y + (radius * sin(ope))), glm::vec2(cos(ope) * (radius/spriteRadius) + 0.5,sin(ope) * (radius / spriteRadius) + 0.5), glm::vec3(1, 1, 1)));
//Adding the vertice
That's it
Thanks to all the people that help me to find why it work
Sorry for the code, he didn't wanna space it