Mac OS X下OpenGL环境配置,并在Qt Creator下使用

配置:OS X 10.11.2 + Cmake3.5 + GLFW3.1 + GLEW2.0 + OpenGL4.1 + Qt Creator3.5

本文假设已安装cmake,QT和QT Creator,若为安装请自行google。

glfw和glew可通过两种方式安装,一是用homebrew包管理安装,但我在安装时因为源问题,访问速度慢,终端挂vpn也不行,所以放弃并使用第二种方案;二是通过下载源码,用cmake/make编译安装,推荐使用第二种。

GLFW 和 GLEW安装

GLFW

下载GLFW源码,使用cmake/make编译安装

**Generating files with the CMake command-line tool **

To make an in-tree build, enter the root directory of the GLFW source tree (i.e. not the src subdirectory) and run CMake. The current directory is used as target path, while the path provided as an argument is used to find the source tree.


 cd <glfw-root-dir>
 cmake .

To make an out-of-tree build, make a directory outside of the source tree, enter it and run CMake with the (relative or absolute) path to the root of the source tree as an argument.

 mkdir glfw-build
 cd glfw-build
 cmake <glfw-root-dir>
 make
 make install

**CMake options ** 编译生成动态链接库,需更改cmake配置。 命令行cmake -DBUILD_SHARED_LIBS=ON .,或用GUI设置BUILD_SHARE_LIBS为ON

###GLEW 源码地址https://github.com/nigels-com/glew/releases,下载glew-2.0.0.zip。(source code.zip缺失部分代码,编译不通过)。

**Build **

$ make
$ sudo make install
$ make clean

glfw/glew编译安装一般生成include目录,还有动态链接库,osx下目录为:/usr/local/include 、/usr/local/lib.

Qt Creator运行OpenGL

新建工程,配置文件类似如下:

QT += core
QT -= gui

TARGET = QtOpenGL-osx
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp


#include glew/glfw
INCLUDEPATH += /usr/local/include

#lib glew / glfw.
LIBS += -L/usr/local/lib -lglfw -lglew

#osx opengl framework
QMAKE_LFLAGS += -F/System/Library/Frameworks/
LIBS += -framework OpenGL \
    -framework Cocoa \
    -framework CoreVideo \
    -framework IOKit \

Xcode运行openGL

1、打开Xcode,新建OSX Command Line Tool工程

2、左侧选中工程

(1)在 Build Settings 里找到 Header Search Paths

添加终端中输出的头文件路径:/usr/local/include/

(2)在 Build Settings 里找到 Library Search Paths

添加终端中输出的lib文件路径:/usr/local/lib/

3、在 Build Phases中的 Link Binary With Libraries 中,添加:

(1)IOKit.framework

(2)Cocoa.framework

(3)OpenGL.framework

(4)CoreVideo.framework

(5)libglfw3.a

若不能找到 libglfw3.a ,可通过 Add Other... 按钮手动定位该文件,文件在 /usr/local/lib/ 中。

OpenGL学习网站推荐

http://www.learnopengl.com/#!Getting-started/OpenGL

References

  1. http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/
  2. https://www.zhihu.com/question/29745396/answer/137552203
  3. http://www.jianshu.com/p/3fab28d33f0d
  4. http://www.cnblogs.com/tangyikejun/p/4508120.html

转载于:https://my.oschina.net/Jerrymingzj/blog/814231

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值