一、下載和安裝HomeBrewgit
打開terminal,輸入下面的命令:github
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
x
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
可能在下載的過程當中遇到以下問題,不要慌,多是網絡問題致使的,從新執行一遍安裝命令便可macos
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" //經常使用命令: //安裝軟件,如:brew install oclint //卸載軟件,如:brew uninstall oclint //搜索軟件,如:brew search oclint //更新軟件,如:brew upgrade oclint //查看安裝列表, 如:brew list //更新Homebrew,如:brew update
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
//經常使用命令:
//安裝軟件,如:brew install oclint
//卸載軟件,如:brew uninstall oclint
//搜索軟件,如:brew search oclint
//更新軟件,如:brew upgrade oclint
//查看安裝列表, 如:brew list
//更新Homebrew,如:brew update
很過教程都是基於GLUT的,但Xcode上會顯示deprecate的warning,主要由於GLUT從1998年再也不更新了,使用也有必定隱患。如今使用的通常爲GLEW,GLFW,FreeGLUT(兼容GLUT),在terminal中輸入ruby
brew install glew brew install glfw brew install freeglut
brew install glew
brew install glfw
brew install freeglut
freeglut: XQuartz 2.7.11 (or newer) is required to install this formula. X11Requirement unsatisfied! You can install with Homebrew-Cask: brew cask install xquartz You can download from: https://xquartz.macosforge.org Error: An unsatisfied requirement failed this build.
freeglut: XQuartz 2.7.11 (or newer) is required to install this formula. X11Requirement unsatisfied!
You can install with Homebrew-Cask:
brew cask install xquartz
You can download from:
https://xquartz.macosforge.org
Error: An unsatisfied requirement failed this build.
#include <stdio.h> #include <GL/glew.h> #include <GLFW/glfw3.h> int main(int argc, const char * argv[]) { GLFWwindow *window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "Hello OpenGL", 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 */ glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); // Red glVertex3f(0.0, 1.0, 0.0); glColor3f(0.0, 1.0, 0.0); // Green glVertex3f(-1.0, -1.0, 0.0); glColor3f(0.0, 0.0, 1.0); // Blue glVertex3f(1.0, -1.0, 0.0); glEnd(); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwTerminate(); return 0; }
x
int main(int argc, const char * argv[]) {
GLFWwindow *window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello OpenGL", 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 */
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0); // Red
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0); // Green
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0, 0.0, 1.0); // Blue
glVertex3f(1.0, -1.0, 0.0);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">網絡