環境:VS2010
准備工作:
1.下載GLUT工具包,這裡給一個下載地址:http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
2.解壓得到的GLUT,得到文件如下:

描述如下

分別將5個文件復制到windows和VC對應目錄下:

這裡,是XP系統,所以需要做的就是
將glut.h放到(C:Program FilesMicrosoft SDKsWindows7.0AIncludegl)這個文件夾中.
將glut.lib和glut32.lib放到靜態函數庫所在文件夾中。(安裝目錄VClib)
將glut.dll和glut32.dll放到操作系統所在目錄下面的system32文件夾內. (C:Windowssystem32)
參考:http://www.cs.csustan.edu/~rsc/SDSU/GLUTinstall.html
好。至此,環境搭建好了。再開始寫程序。
新建一個vs2010項目,代碼如下:
// OpenGLtest.cpp : 定義控制台應用程序的入口點。
//
#include stdafx.h
#include GL/glut.h
#include GL/gl.h
void display()
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0,0.0,0.0,1.0); // set the quad color
glBegin(GL_QUADS);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,-0.5,0.0);
glVertex3f(0.5,0.5,0.0);
glVertex3f(-0.5,0.5,0.0);
glEnd();
glFlush();
}
//int _tmain(int argc, _TCHAR* argv[])
//{
// glutInit(&argc, argv);
// glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
// glutInitWindowPosition(100, 100);
// glutInitWindowSize(400, 400);
// glutCreateWindow(第一個OpenGL程序);
// glutDisplayFunc(&myDisplay);
// glutMainLoop();
// return 0;
//}
int _tmain(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow(第一個OpenGL程序);
glutDisplayFunc(&display);
glutMainLoop();
return 0;
}
可見,繪制了一個矩形。
