glut下载
Windows Visual Studio上配置
将下载下来的压缩包解压,.h文件 .dll文件 和 .lib文件
.h 头文件
将解压得到的头文件glut.h复制到目录如下目录下:
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL
提示:如果在incluce目录下没有GL文件夹,则需要手动创建
.dll 文件
将glut.dll,glut32.dll这两个动态库文件放到操作系统目录下面的C:\Windows\system32文件夹内(32位系统)或C:\Windows\SysWOW64(64位系统)。
为了兼容性考虑,最好在这两个目录下都复制相应的文件。
.lib文件
解压后将得到的glut.lib和glut32.lib这两个静态函数库复制到文件目录的lib文件夹下
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
程序测试
简单的OpenGL程序,画一条红线
#include <GL/glut.h>
void init()
{
glClearColor(1.0, 1.0, 1.0, 1.0); // set display-window color to white
glMatrixMode(GL_PROJECTION); // set projection parameters
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void lineSegment()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0, 0.0, 0.0); // Set line segment color to red
glBegin(GL_LINES);
glVertex2i(180, 15);
glVertex2i(10, 145);
glEnd();
glFlush(); // Process all OpenGL routines as quickly as possible
}
void main(int argc, char ** argv)
{
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Set display mode
glutInitWindowPosition(50, 100); // Set top-left display-window position
glutInitWindowSize(400, 300); // Set display-window width and height
glutCreateWindow("An Example OpenGL Program"); // Create display window
init(); // Execute initialization procedure
glutDisplayFunc(lineSegment); // Send graphics to display window
glutMainLoop(); // Display everything and wait
}