# Render A Circle In Opengl

OpenGL, or Open Graphics Library, is a computer graphics API (application programming interface) for writing 2D and 3D computer graphics applications across programming languages and platforms. It can be used to render anything from simple, primitive objects to complex 3D scenes. OpenGL is widely used in professional computer-assisted design, scientific visualization, flight simulation and video games. While OpenGL does not have any methods to directly draw a circle, a circle can be constructed using a series of lines. You will need a basic knowledge of OpenGL to draw a circle.

## Instructions

1. Set up a basic program that displays an OpenGL viewport window. If you are unfamiliar with this process, there is a tutorial on the basics of OpenGL.

2. Add the math.h header file to your program by entering the following code at the beginning of the program: #include This will provide you with the cos() and sin() functions (cosine and sine) needed to calculate the circle.

3. Begin your circle method by adding the following code before your display callback function: void drawCircle(GLint x, GLint y, GLint radius, int num_lines) { } The variables “x” and “y” will be used to set the center of the circle in your window, while “radius”, of course, sets radius of the circle. The integer “num_lines” is the number of lines used to compose the circle. The higher the number, the smoother the circle will appear to be.

4. Add the following set-up code inside the brackets: float angle GO int num_lines GO glColor3f(0.0, 0.0, 0.0) GO The variable “angle” will contain the angle of the lines used to construct the circle. The call to the glColor3f() function sets the color of the lines to black, where the series of three 0s correspond to the intensity of red, green, and blue on a scale of 0 to 1.