这本书的环境配置:

image.png

glfw

从 GitHub 下载 glfw 的源码并编译,这里直接使用 VSCode 的 CMake 插件进行 Build 即可,

https://github.com/glfw/glfw

image.png

image.png

GLEW

按照书中附录的指示,然后从 GitHub 的仓库中下载了 Releases 中的最新版,时间有点老,只能说,将就用了。

GLM

这个也是直接从 GitHub 的 Releases 中下载的最近发布版,

https://github.com/g-truc/glm

SOIL2

同上,直接在 VSCode 中使用 CMake 插件进行 build 即可。本来书上是说要使用 premake 结合 VS 来构建,后发现这个项目现在也有提供 CMake 配置,所以现在直接使用 CMake 进行 build 就可以了。

image.png

最后

最后配置一下我日常的 CMake 工作流即可。

然后可以测试一下书上的第一个代码,

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>

using namespace std;

void init(GLFWwindow *window)
{
}
void display(GLFWwindow *window, double currentTime)
{
    glClearColor(1.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
}

int main(void)
{
    if (!glfwInit())
    {
        exit(EXIT_FAILURE);
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    GLFWwindow *window = glfwCreateWindow(600, 600, "Chapter2 - program1", NULL, NULL);
    glfwMakeContextCurrent(window);
    if (glewInit() != GLEW_OK)
    {
        exit(EXIT_FAILURE);
    }
    glfwSwapInterval(1);
    init(window);
    while (!glfwWindowShouldClose(window))
    {
        display(window, glfwGetTime());
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

image.png