zoukankan      html  css  js  c++  java
  • Mac使用Xcode配置openGL

    Mac使用Xcode配置openGL

    博主这学期有图形学课要用到OpenGL,于是首先就开始配置开发环境了。应该说网上Windows上配置OpenGL教程比较多,Mac版的比较少。博主特来分享配置过程。

    介绍

    OpenGL(Open Graphics Library)是指定义了一个跨编程语言、跨平台的编程接口规格的专业的图形程序接口。它用于三维图像(二维的亦可),是一个功能强大,与硬件无关,调用方便的底层图形库。

    在编程的时候,一般会采用基于OpenGL封装的几个库,它们提供了OpenGL本身没有的功能。

    很过教程都是基于GLUT的,但Xcode上会显示deprecate的warning,主要因为GLUT从1998年不再更新了,使用也有一定隐患。

    现在使用的一般为GLEW,GLFW,FreeGLUT(兼容GLUT)。

    本文介绍GLEW和GLFW(二者可以组合使用)的配置过程,要配置FreeGLUT也完全类似。

    配置过程

    安装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,因为博主也配好了,与步骤无关)

    • 在Build Phases里面添加库文件

    • 在使用时只要把头文件包含进来就可以了
    #include <GL/glew.h>
    #include <GLFW/glfw3.h>
    

    测试

    由于博主也刚开始学,于是只能从网上找了一段代码来测试环境。

    #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。

    配置成功!!!

  • 相关阅读:
    linux下启动和关闭网卡命令及DHCP上网
    python 编码问题
    paddlepaddle
    Convolutional Neural Network Architectures for Matching Natural Language Sentences
    deep learning RNN
    Learning Structured Representation for Text Classification via Reinforcement Learning 学习笔记
    Python IO密集型任务、计算密集型任务,以及多线程、多进程
    EM 算法最好的解释
    tensorflow 调参过程
    tensorflow 学习纪录(持续更新)
  • 原文地址:https://www.cnblogs.com/fanghao/p/7559768.html
Copyright © 2011-2022 走看看