White Rectangle on a Blue Background
First, the Basic Idea
In the init callback:
- Set the clear color to blue
- Set the drawing color to white
- Select the projection matrix
- Initialize the projection matrix to the identity
- Set the window size to 1 × 1
In the display callback:
- Clear the screen
- Draw the rectangle
- Flush the buffer
Here's the OpenGL code for init and display:
For init:
glClearColor (0.0f, 0.0f, 1.0f, 0.0f);
glColor3f (1.0f, 1.0f, 1.0f);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0f, 1.0f, 0.0f, 1.0f);
For display:
glClear (GL_COLOR_BUFFER_BIT);
glBegin (GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd ();
glFlush ();