#include "GL/glut.h"<span style="white-space:pre"> </span>//头文件,包含了gl.h glu.h
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
void reshape();
void display();
void init();
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);<span style="white-space:pre"> </span>
glColor3f(1.0, 0.0, 0.0);
glRectf(0, 0, 40, 40);
glutSwapBuffers();<span style="white-space:pre"> </span><span style="color:#ff0000;">//一定要记得此操作,若为单缓冲则用glutFlush()</span>
}
void reshape(int width, int height)
{
glMatrixMode(GL_PROJECTION);<span style="white-space:pre"> </span>//设置当前为投影矩阵
glLoadIdentity();<span style="white-space:pre"> </span>//当前矩阵设置为单位矩阵
gluOrtho2D(0, width, 0, height);<span style="white-s