NeHe's OpenGL Tutorials Setting Up OpenGL In Mac OS 5
Setting Up OpenGL In Mac OS
So you've been wanting to setup OpenGL on Mac OS? Here's the place to learn what you need and how
you need to do it.
What You'll Need:
First and foremost, you'll need a compiler. By far the best and most popular on the Macintosh is Metrowerks
Codewarrior (www.metrowerks.com). If you're a student, get the educational version - there's no difference
between it and the professional version and it'll cost you a lot less.
Next, you'll need the OpenGL SDK (developer.apple.com/opengl/) from Apple. Now we're ready to create
an OpenGL program!
Getting Started with GLUT:
Ok, here is the beginning of the program, where we include headers:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "tk.h"
The first is the standard OpenGL calls, the other three provide additional calls which we will use in our
programs.
Next, we define some constants:
#define kWindowWidth 400
#define kWindowHeight 300
We use these for the height and width of our window. Next, the function prototypes:
GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);
... and the main() function:
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (kWindowWidth, kWindowHeight);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
InitGL();
glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ReSizeGLScene);
glutMainLoop();
return 0;
}
glutInit(), glutInitDisplayMode(), glutInitWindowSize(), glutInitWindowPosition(), and glutCreateWindow() all
set up our OpenGL program. InitGL() does the same thing in the Mac program as in the Windows program.
glutDisplayFunc(DrawGLScene) tells GLUT that we want the DrawGLScene function to be used when we
want to draw the scene. glutReshapeFunc(ReSizeGLScene) tells GLUT that we want the ReSizeGLScene
function to be used if the window is resized.
评论2
最新资源