How to make a smaller circle in opengl using this code as a starting point?

I am trying to draw a circle using opengl, which is smaller than the one shown. The problem is that I cannot find a way to reduce its size ... Can someone 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(); } 
+4
source share
2 answers

You can change the line:

  glVertex2d(cos(angle1),sin(angle1)); 

in

  glVertex2d(0.25f * cos(angle1),0.25f * sin(angle1)); 

This will draw a circle with a radius of 0.25 instead of 1.

Edit: as stated in Dasen, you also need to add 0.25f * to the line:

  glVertex2d(cos(0.0),sin(0.0)); 
+5
source

You can, of course, also add the drawing code with:

 glScalef(0.25f, 0.25f, 1.0f); 

This will change your model matrix, so it’s better to save it also with the matrix stack:

 glPushMatrix(); glScalef(0.25, 0.25f, 1.0f); /* drawing code goes here. */ glPopMatrix(); 
+1
source

All Articles