现在的位置: 首页 > 综合 > 正文

VC++ OpenGL 开发环境配置

2013年09月09日 ⁄ 综合 ⁄ 共 1131字 ⁄ 字号 评论关闭

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);
}

【上篇】
【下篇】

抱歉!评论已关闭.