Social Icons

Wednesday, 16 July 2014

Open GL Program to create a Circle

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void display()
{
float cx=0.0,cy=0.0, r=0.5;
int num_segments=50;
int i;
glClearColor(0.0,0.6,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for(i = 0; i < num_segments; i++)
{
float angle;
angle = (2.0 * 3.1415926 * (i)) / (num_segments);
float x = r * cosf(angle);
float y = r * sinf(angle);
glVertex2f(x + cx, y + cy);
}
glEnd();
glFlush();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE| GLUT_RGB );
glutInitWindowSize (500, 400);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Circle");
glutDisplayFunc(display);
glutMainLoop();
}




                                                         OUTPUT

                                


No comments:

Post a Comment