使用VS2015编译FreeGLUT

使用VS2015编译FreeGLUT

今天去图书馆还书,发现《OpenGL编程指南》(俗称“红宝书”)已经出版到了第八版。新书最大的特色就是彻底抛弃了glBegin()之类让人作呕的函数,全面转向shader语言。纯碎为了复习一下图形学的基础知识,打算运行里面的例子,结果发现居然没有针对VS2015的FreeGLUT库。叔可忍,婶不可忍,决定编译一下,方便以后使用。

1 下载与安装

(1)CMake
官方下载网址是这里,我下载的是彼时彼刻的最新版本cmake-3.4.0-rc1-win32-86.exe。
(2)FreeGLUT
官方下载地址是这里,我下载的是Freeglut 3.0.0[Released: 7 March 2015]。
(3)GLEW
GLEW(OpenGL Extension Wrangler)可以简化获取函数地址的过程,并且包含了可以跨平台使用的其他一些OpenGL编程方法。官方下载地址是这里,我下载的是源代码glew-1.13.0.zip。
(4)Visual Studio
最后当然是Visual Studio 2015。Community版本已经是完全免费,虽然以前破解也很容易,但正式免费还是让人少了不少负罪感,哈哈。现在的Visual Studio不仅集成了Xamarin可以使用C#语言编写Android和iOS应用,更重要的是可以使用C++来编写,在安装的时候就可以勾选,之后就直接使用,无需配置Android NDK之类的。可以说,现在的Microsoft变化很大,印度人还是有两下子的。

2 编译FreeGLUT

编译的话,官方有教程,我就不当翻译工了。

  1. Download CMake (http://www.cmake.org/cmake/resources/software.html).
    Get one of the releases from the binary distribution section.
  2. Run the CMake installer, install wherever you like.
  3. Launch CMake via Start > Program Files > CMake 2.8 > CMake (GUI)
    (note that the shortcut put by the installer on your desktop does NOT point to the CMake GUI program!)
  4. In the “Where is the source code” box, type or browse to the root directory of your freeglut source (so that’s /freeglut, not
    /freeglut/src).
  5. In the “Where to build the binaries” box, type or browse to any
    folder you like - this will be where the Visual Studio solution will be generated. This folder does not have to exist yet.
  6. Hit the Configure button near the bottom of the window.
  7. Pick your target compiler, make sure that its installed on your
    system of course!
  8. Answer Ok when asked if you want to create the build directory.
  9. Wait for the configure process to finish.
  10. The screen will now have some configuration options on it, for
    instance specifying whether you want to build static and/or shared libraries (see below for a complete list). When you’ve selected your options, click the Configure button again.
  11. The Generate button at the bottom will now be enabled. Click Generate.
  12. The build files will now be generated in the location you picked.
    You can now navigate to the build directory you specified in step 5.
    Open the freeglut.sln file that was generated in your build directory, and compile as usual.

值得一提的是用VS2015打开freeglut.sln的时候,要Release和Debug模式各编译一次,这样才会得到想要的文件。

3 搬运头文件和库文件

不当翻译工,却免不了当搬运工。为了避免每次建立工程的时候都需要配置FreeGLUT相关文件,需要人肉将相关文件放到相关位置上。我的操作系统是64位的Windows 10,具体如下:
(1)将头文件“freeglut.h”,“freeglut_ext.h”,“freeglut_std.h”和“glut.h”搬至MSVC的包含目录,我的是“C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\GL”。
(2)将库文件“freeglut.lib”或“freeglut_static.lib”搬至MSVC的库目录,我的是“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib”。
(3)将DLL文件“freeglut.dll”搬至“C:\Windows\System32”。
注:步骤(2)和(3)有时候不起作用,这时还是需要在项目属性中设置。

4 编译GLEW

(1)将glew下载包解压缩后,依次打开build→vc12,用Visual Studio 2015打开sln文件,将对所涉及的项目进行自动升级。
(2)根据red book示例代码的需要,对glew_static工程进行编译。由于该工程默认的生成库文件名称为glews.lib,需在编译之前在配置属性→常规→目标文件名中,将其改为glew_static。
(3)按照步骤3,搬运相关头文件和库文件。

5测试代码

为了测试是否安装成功,可建立一个简单的Win32 console工程测试。代码如下:

#include <GL/glut.h>

void myDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
    glFlush();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);;
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 400);
    glutCreateWindow("First GLUT Sample");
    glutDisplayFunc(&myDisplay);
    glutMainLoop();
    return 0;
}

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值