// C program to demonstrate
// drawing a circle using
// OpenGL
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#define pi 3.142857
// function to initialize
void myInit(void) {
// making background color black as first
// 3 arguments all are 0.0
glClearColor(0.0, 0.0, 0.0, 1.0);
// making picture color green (in RGB mode), as middle argument
// is 1.0
glColor3f(0.0, 1.0, 0.0);
// breadth of picture boundary is 1 pixel
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// setting window dimension in X- and Y- direction
gluOrtho2D(-780, 780, -420, 420);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
float x, y, i;<--- The scope of the variable 'x' can be reduced. [+]The scope of the variable 'x' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
<--- The scope of the variable 'y' can be reduced. [+]The scope of the variable 'y' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
// iterate y up to 2*pi, i.e., 360 degree
// with small increment in angle as
// glVertex2i just draws a point on specified co-ordinate
for (i = 0; i < (2 * pi); i += 0.001) {
// let 200 is radius of circle and as,
// circle is defined as x=r*cos(i) and y=r*sin(i)
x = 200 * cos(i);
y = 200 * sin(i);
glVertex2i(x, y);
}
glEnd();
glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// giving window size in X- and Y- direction
glutInitWindowSize(1366, 768);
glutInitWindowPosition(0, 0);
// Giving name to window
glutCreateWindow("Circle Drawing");
myInit();
glutDisplayFunc(display);
glutMainLoop();
}