据我所知,NeHe教程专门针对Windows而言,非常适合更高级别的东西.但是,当涉及到基础知识时,它们可能变得过于复杂.所以这是一个简单的骨架程序,用于仅使用过剩和opengl功能渲染三角形.如果您想成为Apple特定的,请尝试使用agl.
// The OpenGL libraries, make sure to include the GLUT and OpenGL frameworks #include#include #include // This is just an example using basic glut functionality. // If you want specific Apple functionality, look up AGL void init() // Called before main loop to set up the program { glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); } // Called at the start of the program, after a glutPostRedisplay() and during idle // to display a frame void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, -10.0); glVertex3f(1.0, 0.0, -10.0); glVertex3f(0.0, 1.0, -10.0); glEnd(); glutSwapBuffers(); } // Called every time a window is resized to resize the projection matrix void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-0.1, 0.1, -float(h)/(10.0*float(w)), float(h)/(10.0*float(w)), 0.5, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char **argv) { glutInit(&argc, argv); // Initializes glut // Sets up a double buffer with RGBA components and a depth component glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA); // Sets the window size to 512*512 square pixels glutInitWindowSize(512, 512); // Sets the window position to the upper left glutInitWindowPosition(0, 0); // Creates a window using internal glut functionality glutCreateWindow("Hello!"); // passes reshape and display functions to the OpenGL machine for callback glutReshapeFunc(reshape); glutDisplayFunc(display); glutIdleFunc(display); init(); // Starts the program. glutMainLoop(); return 0; }