(第一章)OpGL超级宝典学习:配置和超级宝典相同的工作环境

前言

最近发现学习好像到了一定的瓶颈,马上要到2023年了,想要在新的一年开始后对自己有一定的突破,加上想往TA上尝试发展一下,所以想要开始系统的学习OpenGL,遂新开一个专栏专门记录对OpenGL超级宝典,也就是蓝宝书的学习过程,预计第一遍的学习时间在3-5个月,加之过年,希望本专栏能够在来年6月份前能结束第一遍的学习记录,本文根据openGL超级宝典,配置和书中相同的开发环境,并成功的运行官方提供的演示示例

  • 注:学习本专栏需要拥有蓝宝书,电子版和纸质版均可,博主使用的第七版

配套资源

  • 下载地址

https://box.lenovo.com/l/Jonqdf

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ouATyLNu-1671767188526)(https://note.youdao.com/yws/res/11766/WEBRESOURCEdcb1942ce176eba1140ebb1eef958c21)]

  • sb7code-master

书中所有讲解的源码,可能和书中存在细微差距,基本相同

  • superbible7-media

示例用到的资源内容,shader、纹理等


配置

解压文件夹

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QORsjWWU-1671767188528)(https://note.youdao.com/yws/res/11778/WEBRESOURCE70549f1e8c7b12037df21a26b91fcce9)]

第一步解压两个文件夹


复制资源

在这里插入图片描述
在这里插入图片描述

将superbible7-media文件下的资源全部拷贝到sb7code-master目录下bin\media文件夹内


HOWTOBUILD

在这里插入图片描述

在源码根目录下有一个HOWTOBUILD文档,该文档描述了如何去构建项目,我们简单看一下

OpenGL SuperBible 7th Edition Examples - How to Build
=====================================================

This source code archive uses CMake to build. The samples also use GLFW library, a
snapshot of which is included in the `extern` folder. It's also possible to use a different
copy of GLFW if desired, but that's an excercise for you. Instructions for each supported
platform are as follows:

开篇介绍了源码使用CMake去构建,并且使用了GLFW库


什么是CMake

  • 百度百科
https://baike.baidu.com/item/cmake/7138032?fr=aladdin

在这里插入图片描述

跨平台编译工具,可以编译源代码,制作程式库


什么是GLFW

  • 官方地址
https://www.glfw.org/

glfw是一个开源的openGL工具程序库

Windows / Microsoft Visual Studio 2013
--------------------------------------

Install CMake. Windows binaries are available from http://www.cmake.org/.
Ensure that CMake is in your path.
Open a command prompt and change to the directory where you've checked out the code.

### Build GLFW

If you are going to use the copy of GLFW included in the archive, enter the
GLFW directory in `extern/glfw-3.0.4`, and type:

    cmake -G "Visual Studio 12" .

(Yes, that's not a mistake - Visual Studio 12 is 2013)

Open the resulting GLFW.sln file in Visual Studio and build both the debug and release configurations.

Copy and rename the resulting glfw3 libraries:

* Copy `glfw-3.0.4/src/Debug/glfw3.lib` into the `lib` directory and **rename it to glfw3_d.lib**.
* Copy `glf3-3.0.4/src/Release/glfw3.lib` into the `lib` directory but don't rename it.

### Build the samples

Open a command prompt and change to the build directory in the source archive.
Type:

    cmake -G "Visual Studio 12" ..

Open the resulting superbible7.sln project in Visual Studio.

The examples will build into the `bin` directory.

这里我们是在windows上去做的测试,所以只看windows上和编译相关的内容即可


安装CMake

  • 官网
https://cmake.org/

在这里插入图片描述
在这里插入图片描述

博主选的版本是3.19.0,下载完成后一路安装,博主选择将CMake添加到环境变量里和创建了桌面图标

在这里插入图片描述

运行GUI后长这个样子


开始构建

build glfw

在这里插入图片描述

  • Browse Source

选择源码下的extern/glfw-3.0.4路径

  • Browse Build

选择源码下的extern/glfw-3.0.4/build路径,没有build文件夹就新建一个就行

依次点击Configure和Generate,生成解决方案


生成debug和release的lib库

  • 打开GLFW.slb

在这里插入图片描述

生成完毕后会在build文件夹生成sln的解决方案,打开GLFW.sln

  • 编译

![在这里插入图片描述](https://img-blog.csdnimg.cn/3d42c477694a43a49588640f33c24be5.png在这里插入图片描述

依次运行编译Debug和Release

  • 查看生成的lib

在这里插入图片描述

在build/src目录下会生成Debug和Release两个文件夹,目录下均有一个glfw3.lib文件

  • 拷贝

在这里插入图片描述

将两个glfw.lib拷贝到sb7code-master\lib目录下,根据HOWTOBUILD的要求,debug的lib重命名成glfw_d.lib


build sample

  • CMake构建

在这里插入图片描述

  • Browse Source

sb7code-master源码路径

  • Browse Build

sb7code-master源码路径下的build文件

和build Glfw类似,设置好source和build,依次点击Configure和Generate,生成解决方案

  • 查看生成的解决方案

在这里插入图片描述

构建完成后会在build文件下生成一大堆的文件,我们主要用的是superbible7.sln文件,这个文件是所有示例的入口文件

  • 编译示例

在这里插入图片描述

点开后直接点击运行,等待编译完成

  • 运行

在这里插入图片描述
在这里插入图片描述

编译完成后,选择右侧的其中一个例子,右键设置为启动项,然后运行,我们可以看到例子已经跑了起来


推送

  • Github
https://github.com/KingSun5

结语

若是觉得博主的文章写的不错,不妨关注一下博主,点赞一下博文,另博主能力有限,若文中有出现什么错误的地方,欢迎各位评论指摘。
本文属于原创文章,转载请著名作者出处并置顶!!

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值