标签:apple lfw href highlight int linker standard config rap
cd glfw-master cmake . # 默认是编译静态库,如果要编译动态库则 cmake -DBUILD_SHARED_LIBS=ON . make make install
最后会看到,说明编译安装成功。
Install the project... -- Install configuration: "" -- Installing: /usr/local/include/GLFW -- Installing: /usr/local/include/GLFW/glfw3.h -- Installing: /usr/local/include/GLFW/glfw3native.h -- Installing: /usr/local/lib/cmake/glfw3/glfw3Config.cmake -- Installing: /usr/local/lib/cmake/glfw3/glfw3ConfigVersion.cmake -- Installing: /usr/local/lib/cmake/glfw3/glfw3Targets.cmake -- Installing: /usr/local/lib/cmake/glfw3/glfw3Targets-noconfig.cmake -- Installing: /usr/local/lib/pkgconfig/glfw3.pc -- Installing: /usr/local/lib/libglfw3.a
在mac上默认开发工具是xcdoe,所以下面展示下xcode的配置。理论上,GLFW的使用跟IDE是无关的,所以其他IDE应该也是可以配置的。
配置项目的Build Settings:
Other Linker Flags 为 -lgfw3
Library Search Paths 的 Debug 和 Release 分别加上/usr/local/lib/
Header Search Paths 加上 /usr/local/include/
添加库,打开项目的Build Phases
在 Link Binary With Libraries 中添加:
Cocoa
OpenGL
IOKit
CoreVideo
到此GLFW的开发环境已经配置完毕,可以开始OpenGL的开发了。
选3.3版本,generate就可以。
如上图,把glad解压以后,把include里面的2个文件夹放入/usr/local/include 下面。
// // main.m // GlfwDemo // // Created by banma-087 on 2019/8/21. // Copyright © 2019 Deman. All rights reserved. // #include <glad/glad.h> #include <GLFW/glfw3.h> #include <stdio.h> #include <stdlib.h> #include <iostream> void framebuffer_size_callback(GLFWwindow* window,int width,int height); void processInput(GLFWwindow* window); int main(int argc, const char * argv[]) { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X #endif GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); if(window == NULL){ std::cout << "fail to create window" <<std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){ std::cout << "Failed to initialize GLAD" << std::endl; return -1; } glViewport(0,0,800,600); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); while (!glfwWindowShouldClose(window)) { processInput(window); glClearColor(0.2f,0.3f,0.3f,1.0f); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; } void framebuffer_size_callback(GLFWwindow* window,int width,int height){ glViewport(0,0,width,height); } void processInput(GLFWwindow* window){ if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS){ glfwSetWindowShouldClose(window, true); } }
这个时候,我们通过上述代码,生成一个页面。
效果如下:
至此,整个OpenGL的环境配置完成了。
https://www.glfw.org/docs/latest/quick.html
标签:apple lfw href highlight int linker standard config rap
原文地址:https://www.cnblogs.com/deman/p/11398259.html