VS2015下配置OpenGL库

本文详细介绍如何在Visual Studio 2015中配置OpenGL环境,包括glew、glut、freeglut及gltools等组件的具体步骤,并提供了一个简单的测试案例。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

正文:

资源地址:http://down.51cto.com/data/2300181

下载资源后,解压“OpenGL安装包.zip”,在“OPenGL安装包”文件夹下可以看到Demo、freeglut、glew、gltools、glut五个文件夹,其中Demo是示例程序,其余四个是安装包。

下面简单说一下配置。

1.glew配置

glew文件夹下有compiled和src两个文件夹,其中,compiled文件夹下是已经编译好的安装包,而src文件夹下是源码。在下是用已编译好的安装包配置的,src文件夹下的源码是为安装gltools准备的(见后面附录部分)。有想用源码安装glew的读者,请自行探索。下面说明安装步骤。

1.解压compiled文件夹下的“glew-2.0.0-win32.zip”,得到glew-2.0.0文件夹。

2.找到VS2015的安装目录,如果是安装在C盘的,多半是类似C:\Program Files(x86)\Microsoft Visual Studio 15.0这样的路径;本人是装在其它盘的,目录是“D:\SoftwareInstall\VS2015”,为了表述方便,后面一律按本人的目录进行说明。

3.找到C++的头文件目录,如在下的是“D:\SoftwareInstall\VS2015\VC\include”,在include目录下新建GL文件夹(如果没有的话)。

4.将1中glew-2.0.0\include\GL文件夹下的4个头文件都拷贝到D:\SoftwareInstall\VS2015\VC\include\GL下。

5.将glew-2.0.0\bin\Release\Win32下的glew32.dll拷贝到D:\SoftwareInstall\VS2015\VC\bin目录下。

6.将glew-2.0.0\lib\Release\Win32下的两个lib文件拷贝到D:SoftwareInstall\VS2015\VC\lib目录下。

注意,没必要将dll文件拷贝到C:\Windows\System32或C:\Windows\SysWOW64下。

至此,glew配置完毕。

2.glut配置

1.将glut文件夹下的“glutdlls37beta.zip”解压,得到5个文件,分别是glut.h、gult.dll、glut32.dll、glut.lib、glut32.lib。

2.将glut.h拷贝到D:\SoftwareInstall\VS2015\VC\include\GL目录下。

3.将gult.dll、glut32.dll拷贝到D:\SoftwareInstall\VS2015\VC\bin目录下。

4.将glut.lib、glut32.lib拷贝到D:\SoftwareInstall\VS2015\VC\lib目录下。

至此,glut配置完毕。

3.freeglut配置

1.将freeglut文件夹下的“freeglut-MSVC-3.0.0-2.mp.zip”解压,得到freeglut文件夹。

2.在freeglut/include/GL目录下有4个头文件,将除了glut.h之外的3个头文件拷贝到D:\SoftwareInstall\VS2015\VC\include\GL目录下。

3.将freeglut/bin目录下的freeglut.dll文件拷贝到D:\SoftwareInstall\VS2015\VC\bin目录下。

4.将freeglut/lib目录下的freeglut.lib文件拷贝到D:\SoftwareInstall\VS2015\VC\lib目录下。

至此,freeglut配置完毕。

4.gltools配置

1.将gltools\include目录下的11个头文件全部拷贝到D:\SoftwareInstall\VS2015\VC\include目录下(注意是include目录,而不是GL子目录)。

2.将gltools\lib目录下的gltools.lib文件拷贝到D:\SoftwareInstall\VS2015\VC\lib目录下。

至此,gltools配置完毕。

至此,OpenGL配置完毕。

测试

1、新建Win32控制台应用程序。

2、将Demo\Block目录下的所有文件拷贝到刚才新建的工程目录下(如本例是E:\OpenGLDemo\OpenGLDemo)

3、“源文件”右键-->“添加”-->“现有项”,将2中的Block.cpp文件添加到工程中。

4、在Block.cpp文件的include语句后添加#pragma comment(lib,"gltools.lib")。

5、项目中移除删除OpenGLDemo.cpp文件或删除main()函数,避免存在两个main()导致编译错误。

6、编译过程可能会遇到以下错误

   6.1链接错误 error LNK2026

 

链接错误 error LNK2026的解决方案:项目->属性->连接器/命令行 其他选项中增加   /SAFESEH:NO

链接错误1的结局方案

6.2 error LNK2001 无法解析的外部符号 __CrtDbgReport

error 2001 解决方案:项目->属性->连接器/输入 忽略特定库中填写 MSVCRT.lib

OK,编译通过,以下为显示效果

按下空格键,中央的立方体的样式会发生变化,一共有6种变化,6种变化循环往复。

 

附录 gltools.lib的编译生成方法

注意,要想编译生成gltools.lib,必须先配置好glew。下面说明编译步骤。

1.将gltools\include目录下的11个头文件全部拷贝到D:\软件安装\VS2015\VC\include目录下(注意是include目录,而不是GL子目录)。

2.启动VS2015,创建名为gltools的Win32应用程序。

3.选择“静态库”,将“预编译头”前的勾点掉。

4.将gltools\src目录下的6个文件文件拷贝到刚才新建的工程目录中(如本例,就是E:\gltools\gltools)。

5.“源文件”右键-->“添加”-->“现有项”,将4中的6个文件添加到工程中。

注意,这里的glew.c就是glew\src\glew-2.0.0\src目录下的glew.c文件。

6.生成-->生成gltools

编译时会出现一大推“dll链接不一致“的警告(在下把网上能找到的办法都试过了,都没有用,希望知道解决办法的读者不吝赐教),但最终还是编译成功了。

 7.在E:\gltools\Debug目录下可以找到生成的gltools.lib文件。

至此,gltools编译生成完毕。

 

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

What is this? ============= This is a stand alone package for GLTools. According to the OpenGL SuperBible, written by the author of GLTools: >GLTools began life in the third edition of this >book. Over time it has grown and provides a lot of shortcuts and handy tools, much like >the OpenGL utility library (GLU) used to. GLTools includes a 3D math library to manipulate >matrices and vectors and relies on GLEW for full OpenGL 3.3 support of functions >that generate and render some simple 3D objects and manage your view frustum, camera, >and transformation matrices GLTools is incredibly useful, however, it is a real pain to get set up under Linux. The makefiles provided with the companion source code for the book all rebuild GLTools from scratch and statically link it to the executable. For this distribution, I removed the included copy of GLEW and wrote some CMake files to make it easier to use with your own programs. The official repository is available at http://code.google.com/p/oglsuperbible5/ **NOTE**: I only tested the build process under Ubuntu 10.04, if there are any issues on other platforms, patches are appreciated. COMPILATION AND INSTALLATION ============================ List of packages needed for compilation on Ubuntu: build-essential g++ cmake libx11-dev freeglut3-dev libglu1-mesa-dev libxcb1-dev libxext-dev libxxf86vm-dev libxi-dev libxmu-dev glew-utils libglew1.5-dev To compile and install GLTools: cd build cmake .. make sudo make install sudo ldconfig By default, headers will be in */usr/local/include* and libraries will be in */usr/local/lib*
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值