1. 下載GLUT工具包
http://www.opengl.org/resources/libraries/glut/
2. 進入VC安裝目錄
VC\include\GL,將工具包中的.h檔案複製進來。
將.lib檔案複製到VC安裝目錄下的 \VC\lib
將.dll檔案複製到系統目錄下的system32檔案夾
3. 建立C++工程,測試如下代碼成功,則環境配置成功
#include
<GL/glut.h>
#include <GL/gl.h>
#include <GL/glaux.h>
#pragma comment(lib, "opengl32.lib" )
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glaux.lib")
#include <Windows.h>
void myinit(void);
void CALLBACK myReshape(GLsizei w,GLsizei h);
void CALLBACK display(void);
void myinit(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void CALLBACK myReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w,-1.5,1.5,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CALLBACK display(void)
{
glColor3f(1.0,1.0,0.0);
auxWireSphere(1.0);
glFlush();
}
void main(void)
{
//設定顯示模式:單緩衝|RGBA顏色模式
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
//初始化視窗位置
auxInitPosition(400,200,500,500);
//設定視窗標題
auxInitWindowA("OpenGL程式");
myinit();
auxReshapeFunc(myReshape);
auxMainLoop(display);
}