#include <glut.h>
//
void init(void);
void display(void);
///
int main(int argc, char** argv)
{
//
glutInit(&argc,argv); //初始GLUT并处理命令行的参数
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);//使用的模式是RGB和单缓存模式
glutInitWindowSize(250,250); //大小
glutInitWindowPosition(100,100);//位置
glutCreateWindow("我的第一个OpenGL");//名称
//
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void init() //初始
{
glClearColor(0,0,0,0);//背景色
glMatrixMode(GL_PROJECTION);//对投影矩阵应用随后的矩阵操作.
glLoadIdentity();//提高效率
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT); //清除所有像素
glColor3f(1,1,1); //设置颜色
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();
}