#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glut.h>
void display(void)
{
/*clear all pixels 清除所有像素*/
glClear(GL_COLOR_BUFFER_BIT); //把窗口清除为当前颜色
glColor3f(1.0,1.0,1.0); //设置颜色为白色
glBegin(GL_POLYGON); //绘制了一个凸多边形,和glEnd()一块使用
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();
/*don't wait! start processing buffered OpenGL routines*/
glFlush(); //强制刷新缓冲,保证绘图命令将被执行
}
void init(void)
{
/*select clearing(background) color*/
glClearColor(0.0,0.0,0.0,0.0); //设置清除颜色
/*initialize viewing values 初始化查看值*/
glMatrixMode(GL_PROJECTION); //将当前矩阵指定为投影矩阵
glLoadIdentity(); //重置当前指定的矩阵为单位矩阵
}
/*Declear initial window size,podition, and display mode
(single buffer and RGBA). Open window with "hello" in its
title bar. Call initialization routines. Register callback
function to display graphics. Enter main loop and process
events.*/
int main(int argc,char** argv)
{
glutInit(&argc,argv); //初始化glut库
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250,250); //设置初始窗口的大小
glutInitWindowPosition(100,100);//设置初始窗口的位置(窗口左上角相对于桌面坐标(x,y)),
//坐标(0,0)是指屏幕左上角的位置.
glutCreateWindow("hello");//根据前面设置的信息创建窗口。参数将被作为窗口的标题。
//注意:窗口被创建后,并不立即显示到屏幕上。需要调用
//glutMainLoop才能看到窗口。
init();
glutDisplayFunc(display); //调用之前的画图函数
glutMainLoop();
return 0;
/*IOS C requires main to return int.*/
}