Mac xcode 配置OpenGL

配置过程

安装homebrew

打开命令行

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

安装GLEW和GLFW

brew install glew
brew install glfw 

brew安装的目录在/usr/local/Cellar下,后面会使用到路径。

新建一个Xcode Command Line C++项目

  • 修改Build Settings的Header Search Path和Library Search Path,分别添加两个库的头文件和库文件路径(请自行忽略里面的freeglut,因为博主也配好了,与步骤无关)
  • 我下载的是glew 2.0.0,后面的lib也是,大家记住自己的版本号哈

  • 在Build Phases里面添加库文件

  • 在使用时只要把头文件包含进来就可以了
  • 这一步骤是搜索不出来的,需要直接打开lib所在文件夹,然后手动拖进来。
 

测试

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(void)

{
    
    GLFWwindow* window;
    
    /* Initialize the library */
    
    if (!glfwInit())
        
        return -1;
    
    /* Create a windowed mode window and its OpenGL context */
    
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    
    if (!window)
        
    {
        
        glfwTerminate();
        
        return -1;
        
    }
    
    /* Make the window's context current */
    
    
    glfwMakeContextCurrent(window);
    
    
    /* Loop until the user closes the window */
    
    while (!glfwWindowShouldClose(window))
        
    {
        
        /* Render here */
        
        /* Swap front and back buffers */
        
        glfwSwapBuffers(window);
        
        /* Poll for and process events */
        
        glfwPollEvents();
        
    }
    glfwTerminate();
    
    return 0;
}
 

显示了一个标题为hello world的黑框,0 warnings, 0 errors。

配置成功!!!

猜你喜欢

转载自www.cnblogs.com/Anita9002/p/9143515.html