LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 June 14 2014

Johnaudi
Member

Explanation needed, OpenGL Circle Colors

Hey,

I've recently drawn a simple circle in OpenGL, but I have some questions about it...

Since it uses vertexes (vecteurs...), I've made the last position - new position in the x and y coordinates.

Though once I'm coloring it, it is coloring not from the center, but the bottom, I don't understand this, isn't it supposed to show it from the center of the circle?

Here's a picture:

0632183ce3.jpg

And here's the code:

glBegin(GL_POLYGON);

static float lstx = 1.0f, lsty = 0.0f;

for (int i = 1; i <= 360; i++) {
		
  float xx =  10 * PI * cos(i * PI / 180);
  float yy =  10 * PI * sin(i * PI / 180);
  glVertex2f(lstx - xx, lsty - yy);
  glColor3f((rand() % 99) / 10.0f, (rand() % 99) / 10.0f, (rand() % 99) / 10.0f);

  lstx = xx;
  lsty = yy;
}

glEnd();

And another question, why does the circle gets bended on the left side when I remove the static prefix from lstx and lsty?

Thanks in advance.

Last edited by Johnaudi (June 15 2014)

Offline

#2 June 15 2014

NuclearVision
Member

Re: Explanation needed, OpenGL Circle Colors

i think you are loop-changing both of the vectors' start-end positions, if you want them to hit the center of the circle then one point of the 'vector' should be constant, the center of the circle. and why did you multiply by sin and cos, those functions make the lines curve, i do not see any reason for that.
again i am not sure of all of the above, i could have misunderstood your code\.

Offline

#3 June 15 2014

Johnaudi
Member

Re: Explanation needed, OpenGL Circle Colors

NuclearVision wrote:

i think you are loop-changing both of the vectors' start-end positions, if you want them to hit the center of the circle then one point of the 'vector' should be constant, the center of the circle. and why did you multiply by sin and cos, those functions make the lines curve, i do not see any reason for that.
again i am not sure of all of the above, i could have misunderstood your code\.

Hey thanks for the reply.

Well, to draw a circle you'd need X = Center + Ray * PI * Cos(angle_in_rad), Y = Center + Ray * PI * Sin(angle_in_rad)

So I subtracted the old positions with the new positions to form a vector since GL_POLYGON is vector based, right? (x2-x1, y2-y1)

Though the question is, why is it being drawn as if the centers' coordinates (depending on the colors) are 0,-1?

Thanks in advance.

Edit: Made the code more readable.

Last edited by Johnaudi (June 15 2014)

Offline

#4 June 16 2014

Ra8
Member

Re: Explanation needed, OpenGL Circle Colors

Hi,
I went trough the documentation to understand how this works. https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml.
You should define the circle by a series of points.

By the way I think this what got you confused: A Vertex is a Point in french not a Vecteur. A Vector is a Vecteur.

I never used opengl but I hope I helped you. Let me know if it worked..

Offline

#5 June 16 2014

Johnaudi
Member

Re: Explanation needed, OpenGL Circle Colors

Ra8 wrote:

Hi,
I went trough the documentation to understand how this works. https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml.
You should define the circle by a series of points.

By the way I think this what got you confused: A Vertex is a Point in french not a Vecteur. A Vector is a Vecteur.

I never used opengl but I hope I helped you. Let me know if it worked..

Woah! Now I understand why code works in weird conditions, especially when i had to create vectors for this.

This helped me a lot; thanks!

I'll keep this thread for more questions purposes.

Offline

Board footer