学习computer graphics或者进行游戏开发之前的准备工作,opengl的配置是第一步。在linux、unix以及Mac系统中,配置都较为简单,在windows中我们需要进行一系列的准备工作。下面是step by step的配置内容。本文是从Thought from my life中总结简化而来,尤其是修改了一些opengl库的获取方式。
一、Download
OpenGL库文件:
1,freeglut from the freeglut SourceForge page.
2,original GLUT from Nate Robins' site.
Visual Studio 2008 Express的下载安装问题请见《OpenCV入门一:安装配置(with
二、编译freeglut
freeglut压缩包下载解压之后,只有部分include里面的头文件,此时需要用visual studio 2008进行编译:
1.上步骤1生成的 freeglut-2.6.0->include->GL 中有我们需要的freeglut.h,freeglut_ext.h,freeglut_std.h,glut.h
2.上步骤1生成的 freeglut-2.6.0->VisualStudio2008中,运行freeglut.sln,直接进行编译。在生成的Release或者Debug文件夹中,有我们需要的freeglut.lib和freeglut.dll
3.上步骤2生成的glut-3.7.6-bin包中,有我们需要的glut32.dll,glut32.lib。(注意,这个里面的glut.h不要)
4.拷贝需要的文件到对应系统文件夹中
- Copy all the .h files into the C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\GL folder. This should be glut.h, freeglut.h, freeglut_ext.h, and freeglut_std.h.
- Copy all the .lib files into the C:\Program Files\Microsoft SDKs\Windows\v6.1\Libfolder. This should be freeglut.lib and glut32.lib.
- Copy all the .dll files into the C:\Windows\system32 folder. This should befreeglut.dll and glut32.dll.
注意:其中的C:\Program Files\Microsoft SDKs\Windows\v6.1 文件路径取决于你安装的Visual Studio 2008和SDK,也可能是V6.0。
5.建立新的工程和空的cpp文件
6.配置工程文件属性
- Click on Project -> [project name] Properties.
- Expand Configuration Properties.
- In the Configuration dropdown, select All Configurations.
- Select Linker -> Input.
- In the Additional Dependencies field, enter in GlU32.Lib OpenGL32.Lib freeglut.lib glut32.lib. Then click OK.
7.在空cpp中输入代码
#include<GL/glut.h>
void mydisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, -0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}int main(int argc, char** argv){
glutInit(&argc, argv);
glutCreateWindow("Simple");
glutDisplayFunc(mydisplay);
glutMainLoop();
}
8.编译该工程,出现图形窗口显示。