第一步:下载OpenGL2.0库(百度搜索一大堆下载链接);
第二步:把库文件里面的GL文件夹复制到D:\Program Files\Microsoft Visual Studio 9.0\VC\include下,如果你的VS2008安装在C盘或其他盘,请到相应的目录下寻找;
第三步:把lib文件夹里面的lib文件复制到D:\Program Files\Microsoft Visual Studio 9.0\VC\lib,如果你的VS2008安装在C盘或其他盘,请到相应的目录下寻找;
第四步:把lib文件夹里面的动态链接库dll复制到C:\Windows\System32目录下;
第五步:打开VS2008,在工具->选项->Projects and Solutions->VC++ Directories,Show directories for选择Include files,添加D:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL,注意与第二步的路径要一致;
第六步:新建Win32控制台程序,在项目->属性->Linker->Input->Additional Dependencies中添加:
glut32.lib
Opengl32.lib
Glu32.lib
glew32.lib
第七步:测试程序与效果:
#include <windows.h> //这个必不可少 #include <glut.h> void display( void ) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glBegin(GL_POLYGON); 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(); glFlush(); } void init( void ) { glClearColor(0.0,0.0,0.0,0.0); //以黑色清屏 glMatrixMode(GL_PROJECTION); //glMatrixMode - 指定哪一个矩阵是当前矩阵 //GL_PROJECTION,对投影矩阵应用随后的矩阵操作 glLoadIdentity(); //该函数的功能是重置当前指定的矩阵为单位矩阵 glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0); } int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(250,250); glutInitWindowPosition(100,100); glutCreateWindow("Hello OpenGL"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }运行效果: