在上篇 我们停留在概念上的,现在动手写写代码。
在OpenGL官网 我们可以看到这么一段话:
macOS Unlike other platforms, where the Operating System and OpenGL implementations are often updated separately, OpenGL updates are included as part of macOS system updates. To obtain the latest OpenGL on macOS, users should upgrade to the latest OS release, which can be found at Apple.com.
换句话来说OpenGL已经集成在我们的Mac系统中,但是我们还需要一些执行窗口任务或者处理用户输入的函数,这里需要用到的库有:
安装GLEW、GLEW 1 2 3 4 5 6 7 8 9 10 11 12 13 ➜ blogs brew install glfw3 Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/glfw-3.3.2.mojave.bottle.tar.gz ==> Pouring glfw-3.3.2.mojave.bottle.tar.gz 🍺 /usr/local /Cellar/glfw/3.3.2: 14 files, 492.8KB ➜ blogs brew install glew Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/glew-2.1.0_1.mojave.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/66/66638564b5b9d2d915b97841ef1cc117f701c7ec34707734fa1ce11919c28 ==> Pouring glew-2.1.0_1.mojave.bottle.tar.gz 🍺 /usr/local /Cellar/glew/2.1.0_1: 38 files, 3MB
在Xcode配置GLEW、GLEW
添加两个dylib文件的方法时,没有在framework中搜索到这两个文件时,点击add other,然后点击shift+command+G进入/usr/local
文件夹对应的安装路径找。
下载GLAD库
1 2 3 4 5 6 7 8 9 10 11 12 13 ➜ ~ cd /Users/samtake/Downloads/glad ➜ glad ls include src ➜ glad alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" ➜ glad tree |____include | |____KHR | | |____khrplatform.h | |____glad | | |____glad.h |____src | |____glad.c ➜ glad
将include文件夹中的两个文件复制到/usr/local/include
内,然后添加glad.c
文件到XCode工程中.
demo 复制源码代替原有的main.cpp文件,build一下编译通过即可。
demo源码