安装GLEW和GLFW
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install glew
brew install glfw3
Xcode工程中的设置
-
Build Settings
的Header Search Paths
添加路径/usr/local/include
-
Build Phases
的Link Binary With Libraries
中,添加OpenGL.framework
,libGLEW.2.0.0.dylib
,libglfw.3.2.dylib
这三个库
写点代码看看:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow *window;
// 初始化库
if (!glfwInit()) {
return -1;
}
// 创建 window 和 opengl context
window = glfwCreateWindow(640, 480, "Hello World ! ", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
// 得到window的context
glfwMakeContextCurrent(window);
// 循环,直到用户关闭window
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
// 渲染. 所有OpenGL的代码放在这儿
// ...
// 交换缓存
glfwSwapBuffers(window);
// 处理事件
glfwPollEvents();
}
glfwTerminate();
return 0;
}
网友评论