# Include <Gl/glut. h> void display (void) {glclear (gl_color_buffer_bit); glbegin (gl_polygon); glvertex2f (-0.5,-0.5); glvertex2f (-0.5, 0.5); glvertex2f (0.5, 0.5); glvertex2f (0.5,-0.5); glend (); glflush ();} void Init () {glclearcolor (0.0, 0.0, 0.0, 0.0); glcolor3f (1.0, 1.0, 1.0); glmatrixmode (gl_projection); glloadidentity (); glortho (-1.0, 1.0,-1.0, 1.0,-1.0, 1.0);} int main (INT argc, char ** argv) {gluinit (& argc, argv); gluinitdisplaymode (glu_single | glu_rgb); gluinitwindowsize (500,500); gluinitwindowposition (); glucreatewindow ("simple "); gludisplayfunc (Display); Init (); glumainloop (); Return 0 ;}
ThisCodeThe general explanation is as follows:
1. First, add the necessary header file glut. H is included to use the function library provided by OpenGL.
2. display is a callback function written by the Program , used for drawing in a window. After registering it with the help of the main function,
each time the image in the window needs to be refreshed, the display function we wrote is called.
3. The gluinitwindowsize function specifies the width and height of the form.
4. Specify the coordinates in the upper left corner of the window.
5. Create a form in the window.
6. Enter form message loop.
unless otherwise stated, only the content of the display function can be changed in the Code in the following example.