---
title: "OpenGL环境搭建"
author: "codeone"
date: "2011-12-28T13:45:23Z"
tags: []
categories: ["开源软件"]
slug: "opengl"
draft: false
lastmod: "2011-12-28T13:45:23Z"
id: 1328520
url: "https://codeone.iteye.com/blog/1328520"
---

1.首先去下载附件中的“[glutdlls37beta.zip](http://dl.iteye.com/topics/download/956b1914-4544-3136-95a9-debc85b35e8a) ”

 

2.配置三个文件

把glut.h  复制到x:/Program Files/Microsoft/Visual Studio 9.0/VC/include/GL文件夹中,如果没有GL这个文件夹则可以自己新建一个。（x是你安装VS的盘符号，如果装的是VC++的话，里面有个gl文件，Visual Studio 2008则需要自己去新建一个）

然后把glut32.lib  复制到C:/Program Files/Microsoft Visual Studio 9.0/VC/lib中

最后把glut32.dll  复制到C:/Windows/System32中

3.测试是否配置成功：

打开visual studio2008,新建一个visual C++的Win32控制台应用程序的空项目,然后在项目中添加一个C++文件,然后copy下面的代码运行:

```
#include <GL/glut.h>  
void myDisplay(void)  
{  
   glClear(GL_COLOR_BUFFER_BIT);  
   glRectf(-0.5f, -0.5f, 0.5f, 0.5f);  
   glFlush();  
}  
int main(int argc, char *argv[])  
{  
   glutInit(&argc, argv);  
   glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);  
   glutInitWindowPosition(100, 100);  
   glutInitWindowSize(400, 400);  
   glutCreateWindow("第一个OpenGL程序");  
   glutDisplayFunc(&myDisplay);  
   glutMainLoop();  
   return 0;  
}  
```