Created
January 30, 2011 18:54
-
-
Save linusthe3rd/803118 to your computer and use it in GitHub Desktop.
The two methods used to create circles in opengl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Function that handles the drawing of a circle using the triangle fan | |
* method. This will create a filled circle. | |
* | |
* Params: | |
* x (GLFloat) - the x position of the center point of the circle | |
* y (GLFloat) - the y position of the center point of the circle | |
* radius (GLFloat) - the radius that the painted circle will have | |
*/ | |
void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius){ | |
int i; | |
int triangleAmount = 20; //# of triangles used to draw circle | |
//GLfloat radius = 0.8f; //radius | |
GLfloat twicePi = 2.0f * PI; | |
glBegin(GL_TRIANGLE_FAN); | |
glVertex2f(x, y); // center of circle | |
for(i = 0; i <= triangleAmount;i++) { | |
glVertex2f( | |
x + (radius * cos(i * twicePi / triangleAmount)), | |
y + (radius * sin(i * twicePi / triangleAmount)) | |
); | |
} | |
glEnd(); | |
} | |
/* | |
* Function that handles the drawing of a circle using the line loop | |
* method. This will create a hollow circle. | |
* | |
* Params: | |
* x (GLFloat) - the x position of the center point of the circle | |
* y (GLFloat) - the y position of the center point of the circle | |
* radius (GLFloat) - the radius that the painted circle will have | |
*/ | |
void drawHollowCircle(GLfloat x, GLfloat y, GLfloat radius){ | |
int i; | |
int lineAmount = 100; //# of triangles used to draw circle | |
//GLfloat radius = 0.8f; //radius | |
GLfloat twicePi = 2.0f * PI; | |
glBegin(GL_LINE_LOOP); | |
for(i = 0; i <= lineAmount;i++) { | |
glVertex2f( | |
x + (radius * cos(i * twicePi / lineAmount)), | |
y + (radius* sin(i * twicePi / lineAmount)) | |
); | |
} | |
glEnd(); | |
} |
Thank you for this share.
my question, how I can draw a number in centre of the circle ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice