1 OpenGL需要搭配一些窗口库来做,比如Qt、MFC等,或者用跨平台的GLUT。mac自带GLUT和opengl。
2 创建os x的Application。选择command line tool。
3 在target的build phases里面将GLUT.framework和OpenGL.framework添加进来。
4测试代码(绘制一个三角形):
#include <iostream>
#include <GLUT/GLUT.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex2f(-0.5, -0.5);
glColor3f(0,1,0);
glVertex2f(-0.5, 0.5);
glColor3f(0,0,1);
glVertex2f(0.5, 0.5);
glEnd();
glFlush();
}
int main(int argc, char ** argv)
{
std::cout << "Hello, World!\n";
glutInit(&argc, argv);
glutCreateWindow("hello world opengl");
glutDisplayFunc(display);
glutMainLoop();
}