#include<GL/glut.h>
#include<math.h>
#define PI 3.1415926535898
GLint circle_points=100;
// if you wanna specify the radius declare float rd=0.2;
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0,1.0,0.0);
glBegin(GL_LINE_LOOP);
int i;
float angle;
glColor3f(1.0,0.0,0.0);
for(i=0;i<circle_points;i++)
{
angle=2*PI*i/circle_points;
glVertex2f((cos(angle)),(sin(angle)));
/* if you have specified the radius then use glVertex2f((cos(angle)*rd),(sin(angle)*rd)); instead of above statement */
}
glEnd();
glFlush();
}
void initGL()
{
glClearColor(1,1,1,1);
glColor3f(1,0,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1,1,-1,1,-1,1);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(50, 50);
glutCreateWindow("circle");
glutDisplayFunc(display);
initGL();
glutMainLoop();
return 0;
}
No comments:
Post a Comment