Empty window or invisible circle?

Please help me?
Having combined some poached circle code and a sample program, my supposedly red circle doesn’t appear. Is “(GL_COLOR_BUFFER_BIT);” in the wrong place, or is it something more serious? I don’t think the “double buffer” problem applies in this case.

/* 4th attempt to draw a red circle on a white background*/

#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

void myinit(void)

/* attributes */

  glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
  glColor3f(1.0, 0.0, 0.0); /* draw in red */

/* set up viewing /
500 x 500 window with origin lower left */

  gluOrtho2D(0.0, 500.0, 0.0, 500.0);


void display( void )
GLint t;
GLfloat M_PI;

glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */

	GLfloat angle=((GLfloat)t/(GLfloat)CIRCLE_RES)*2.0*M_PI;
	glVertex2f(cos(angle), sin(angle));

glFlush(); /* clear buffers */


void main(int argc, char** argv)

/* Standard GLUT initialization */

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
glutInitWindowSize(500,500); /* 500 x 500 pixel window */
glutInitWindowPosition(0,0); /* place window top left on display */
glutCreateWindow("Circle"); /* window title */
glutDisplayFunc(display); /* display callback invoked when window opened */

myinit(); /* set attributes */

glutMainLoop(); /* enter event loop */


First, glLoadIdentity() after the Modelview Matrix has been established.

Second, your circle has no radius.

rcos(phi) for Y, and rsin(phi) for X.

Third, it is much easier to draw in degrees, not radians:

// translate to center of the circle
// setup r and Z

for (int i=0; i<360; i+=ANGLE_STEP) {
float phi= i*PI/180;
Y= r * cos(phi);
X= r * sin(phi);
glVertex3f(X, Y, Z);

Hope this helps.

First, glLoadIdentity() after the Modelview Matrix has been established.

Not needed. He’s not touching the modelview matrix, and it’s set to identity by default. It’s good practice to explicitly set it though, but not needed.

Second, your circle has no radius.

His circle has radius 1.

Third, it is much easier to draw in degrees, not radians:

That’s a personal taste, and don’t forget that you have to convert it to radians anyways.

I bet you have a circiel in the very bottom left corner of your window. Your window is 500x500 large, but your circle is only covering the very bottom left pixel, since it has radius 1 with origin at (0,0). Increase the radius and see what happens.


Certain hardware implementations demand explicit reset of MODELVIEW matrix identity…

His circle has a radius of 1, yes, but if you notice the viewport size (of 500x500), the circle is smaller than a pixel… perhaps I should have said that way…

Finally, drawing in degrees is much simplier because of the control over the circle, and is much easier to debug. All he has to do is to set the appropriate circle step, and has 360 degrees of freedom, as per 4 df with radians, fractions not included.