搭建Mac下的OpenGL环境

来源:互联网 发布:js怎么给文本框赋值 编辑:程序博客网 时间:2024/06/04 20:08

1)下载

glfw是最近使用的最为广泛的OpenGL库。glfw下载地址

glfw在windows可以直接使用安装包安装,在Mac OS和Linux上需要下载github上的source文件并编译,因此我们需要编译工具cmake。
下载cmake,可以直接下载dmg双击安装。cmake下载地址
安装后在终端中还是没有识别cmake,还需要我们将cmake的路径加到bash_profile文件中。

tips:Mac下更新bash_profile的方法如下:

1) 打开terminal2)cd ~3) open .bash_profile4) 编辑并保存5) source .bash_profile 更新刚才的保存

2)编译

进入glfw目录,执行
cmake .make 

这样我们就将glfw编译成功了,测试一下,进入glfw目录下的examples目录,此时examples目录下的很多测试代码都编译出了.app文件


我们任意选一个测试一下,运行

open particles.app


3)与cmake结合写自己的OpenGL脚本

新建一个项目目录,将glfw整个复制过来,新建src目录存放我们自己写的cpp文件,还需要一个CMakeLists文件


CMakeList文件可以参考:http://blog.csdn.net/elloop/article/details/53212382

我建立了一个showWin目录,src中的main.cpp新建了一个窗口
#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, "Show Me Window", 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 */        glClear(GL_COLOR_BUFFER_BIT);        /* Swap front and back buffers */        glfwSwapBuffers(window);        /* Poll for and process events */        glfwPollEvents();    }    glfwTerminate();    return 0;}
在项目目录下
cmake .make./build/bin/showWin

效果



0 0
原创粉丝点击