glfw环境配置

官方文档:https://learnopengl-cn.github.io/intro/

1 安装homebrew:https://brew.sh/index_zh-cn

2 安装glew glfw:
brew install glew
brew install glfw3
安装完成后在文件路径 /usr/local/Cellar

修改xcode偏好设置


image.png

3 配置glad
打开GLAD的在线服务

image.png

生成zip压缩文件包含两个头文件目录,和一个glad.c文件。
将两个头文件目录(glad和KHR)复制到你的Include文件夹中(即/usr/local/include),并添加glad.c文件到稍后的工程中。

5 新建工程添加依赖库

image.png

程序入口处添加代码

#include 
#include 
#include 
#include 
using namespace std;
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
int main(){
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    
    GLFWwindow *window = glfwCreateWindow(800, 600, "my window", NULL, NULL);
    if (window == NULL) {
        cout << "window = null" << endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    
    
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        cout <<"failed " << endl;
        return -1;
    }
    
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    while (!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    return 0;
}

void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    glViewport(0, 0, width, height);
}

运行程序弹出名为“my window”的黑色窗口


配置成功

你可能感兴趣的:(glfw环境配置)