美文网首页
OpenGL学习(1) —— 为Xcode设置环境

OpenGL学习(1) —— 为Xcode设置环境

作者: 秦枫桀 | 来源:发表于2017-08-03 02:18 被阅读0次

安装GLEW和GLFW

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install glew
brew install glfw3

Xcode工程中的设置

  • Build SettingsHeader Search Paths添加路径/usr/local/include
  • Build PhasesLink Binary With Libraries中,添加OpenGL.frameworklibGLEW.2.0.0.dyliblibglfw.3.2.dylib这三个库

写点代码看看:

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

int main(void)
{
    GLFWwindow *window;
    
    // 初始化库
    if (!glfwInit()) {
        return -1;
    }
    
    // 创建 window 和 opengl context
    window = glfwCreateWindow(640, 480, "Hello World ! ", NULL, NULL);
    if (!window) {
        glfwTerminate();
        return -1;
    }
    
    // 得到window的context
    glfwMakeContextCurrent(window);
    
    // 循环,直到用户关闭window
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        
        // 渲染. 所有OpenGL的代码放在这儿
        // ...
        
        // 交换缓存
        glfwSwapBuffers(window);
        
        // 处理事件
        glfwPollEvents();
    }
    
    glfwTerminate();
    return 0;
}

相关文章

网友评论

      本文标题:OpenGL学习(1) —— 为Xcode设置环境

      本文链接:https://www.haomeiwen.com/subject/ibjulxtx.html