Mac使用Xcode配置openGL
2024-08-26 06:07:08
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。
配置成功!!!
最新文章
- iOS 单元测试之XCTest详解(一)
- SpringMVC表单标签简介
- 【转】Python处理HTML转义字符
- 安装Ubuntu双系统系列——安装中文输入法
- 从某一日期开始过day天的日期
- DexIndexOverflowException: Cannot merge new index 66080 into a non-jumbo instruction!
- spring-quartz普通任务与可传参任务
- D题(贪心)
- [转载+实践理解]Android动画---如何正确使用平移动画(关于fillBefore和fillAfter的一点说明)(转载)
- Spring 接收表单List集合数据
- Android简易实战教程--第四十四话《ScrollView和HorizontalScrollView简单使用》
- [Ext.Net]动态生成控件(二)--js动态添加文本框
- hdu 3030
- 绑定Oracle Database 到 ActiveReport
- Web项目开发流程 PC端
- python类型比较的3种方式(转)
- 关于uip中的log和打印
- Tornado 多进程 &; 异步
- Beginning and Ending the Speech
- 刷新SqlServer数据库中所有的视图
热门文章
- C/C++字节序(大端/小端)判断
- org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0.0.0.0:9083.
- jquery源码 整体架构
- python--json、jsonpath
- PHP算法排序之快速排序、冒泡排序、选择排序、插入排序性能对比
- Codeforces 1045D Interstellar battle 概率期望
- JavaSE| 数组
- 001 大数据情况下linux的配置
- Python线程同步
- CentOS7 Windows双系统 修复引导