I’m trying to draw a circle in c using opengl, that’s smaller than the one shown. The problem is I can’t seem to find how to reduce the size of it…Can anyone help me?
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535898
GLint circle_points =100;
// This is the draw function.
void draw()
{
glClear(GL_COLOR_BUFFER_BIT);
double angle = 2* PI/circle_points ;
glPolygonMode( GL_FRONT, GL_FILL );
glColor3f(0.2, 0.5, 0.5 );
glBegin(GL_POLYGON);
double angle1=0.0;
glVertex2d( cos(0.0) , sin(0.0));
int i;
for ( i=0 ; i< circle_points ;i++)
{
printf( "angle = %f \n" , angle1);
glVertex2d(cos(angle1),sin(angle1));
angle1 += angle ;
}
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
}
void keyboard (unsigned char key , int x, int y)
{
exit(0);
}
void main( int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow("ch06");
init();
glutKeyboardFunc(keyboard);
glutDisplayFunc(draw);
glutMainLoop();
}
You can change the line:
to:
That will draw a circle with a radius of 0.25 instead of 1.
Edit: As spotted by Dasen, you also need to add the
0.25f *to the line: