您的位置:首页 > 运维架构

Windows XP虚拟机绿色VC配置OpenGL开发环境

2015-03-01 15:47 651 查看
针对Oracle virtual box中windows XP(32位)虚拟机中,采用VC6绿色开发ide,配置OpenGL的步骤。

1 下载GLUT编译版

http://user.xmission.com/~nate/glut/glut-3.7.6-bin.zip

2 解压缩后的头文件、库文件设置

解压缩该文件,

把glut.h文件复制到绿色VC的include\GL下,例如:C:\VC6\VC98\Include\GL

把glut32.lib文件复制到绿色VC的lib下,例如:C:\VC6\VC98\Lib

把glut32.dll复制到c:\windows\system32下。

3 Demo项目

打开VC6 ide,新建Console工程,一路Next。

设置工程属性(Alt+F7),

在“设置(S)”下拉列表框中选择“所有配置”,

在对话框的“连接”页中的“对象/库模块”中添加以下连接库名

opengl32.lib Glut32.lib Glaux.lib glu32.lib

4 工程代码修改

打开工程的StdAfx.h文件

在#endif前添加头文件包含

#include <windows.h>

#include <GL/glu.h>

#include <GL/gl.h>

#include <GL/glut.h>

#include <GL/glaux.h>  

5 修改工程主程序,内容如下:

//opengl1.cpp

#include "stdafx.h"

#include <windows.h>
#include <gl\glut.h>

float points[] = {0.8, 0.8, 0.8, 0, 0.8, -0.8, -0.8, 0};

//Called to draw scene
void RenderSence(void)
{
//Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);

//绘制Demo点
//设置点的颜色
glColor3f(1.0, 0.0, 0);
glPointSize(15.0);
glBegin(GL_POINTS);
int i, j, cnt = sizeof(points)/sizeof(float)/ 2;
for(i = 0; i < cnt; i++)
glVertex3f(points[i * 2], points[i * 2 + 1], 0);
glEnd();

//绘制Demo线
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
for(i = 0; i < cnt; i++)
{
j = i + 1;
if (j == cnt) j = 0;
glVertex3f(points[2 * i], points[2 * i + 1], 0);
glVertex3f(points[2 * j], points[2 * j + 1], 0);
}
glEnd();

//Flush drawing commands
glFlush();
}

//Set up the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //此时背景色为蓝色
}

int main(int argc, char* argv[])
{
//printf("Hello World!\n");
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600, 600);
glutCreateWindow("Demo OpenGL应用"); //窗口名为“Simple”
glutDisplayFunc(RenderSence);
SetupRC();
glutMainLoop();
return 0;
}
6 按Ctrl+F5编译运行该项目
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: