GLUT - The OpenGL Utility Toolkit

GLUT (pronounced like the glut in gluttony) is the OpenGL Utility Toolkit, a window system independent toolkit for writing OpenGL programs. It implements a simple windowing application programming interface (API) for OpenGL. GLUT makes it considerably easier to learn about and explore OpenGL programming. GLUT provides a portable API so you can write a single OpenGL program that works across all PC and workstation OS platforms.

GLUT is designed for constructing small to medium sized OpenGL programs. While GLUT is well-suited to learning OpenGL and developing simple OpenGL applications, GLUT is not a full-featured toolkit so large applications requiring sophisticated user interfaces are better off using native window system toolkits. GLUT is simple, easy, and small.

The GLUT library has both C, C++ (same as C), FORTRAN, and Ada programming bindings. The GLUT source code distribution is portable to nearly all OpenGL implementations and platforms. The current version is 3.7. Additional releases of the library are not anticipated.

GLUT is not open source. Mark Kilgard maintains the copyright. There are a number of newer and open source alternatives.

窗口管理

GLUT通过几个函数执行初始化窗口所需要的任务:

glutInit(int *argc,char **argv)对GLUT进行初始化,并处理所有的命令行参数。glutInit()应该在调用其他任何GLUT函数之前调用。

glutInitDisplayMode(unsigned int mode)指定了是使用RGBA模式还是颜色索引模式。另外还可以指定是使用单缓冲还是使用双缓冲窗口。如果想使用颜色索引模式,就需要把一些颜色加载到颜色映射表中,这个任务可以用glutSetColor()完成。最后还可以使用这个函数表示希望窗口拥有相关联的深度、模板、多重采样和/或累积缓冲区。例如,如果需要一个双缓冲,RGBA颜色模式以及带有一个深度缓冲区的窗口,可以调用glutInitDisplay Mode(GLUT_GOUBLE|GLUT_RGBA|GLUT_DEPTH);

glutInitWindowPosition(int x,int y)指定了窗口左上角的屏幕位置;

glutInitWindowSize(int width,int size)指定了窗口的大小(以像素为单位);

 

显示回调函数

glutDisplayFunc(void (*func)(void)),每当GLUT确定一个窗口的内容需要重新显示时,通过glutDisplayFunc()注册的那个回调函数就会被执行。因此,应该把重绘场景所需要的所有代码都放在这个显示回调函数里。

你可能感兴趣的:(OpenGL)