Se si utilizza OSX, si consiglia vivamente di utilizzare XCode e utilizzare NSOpenGLView. Il libro This contiene molto materiale riguardante le diverse API che è possibile utilizzare. GLUT è sicuramente il più veloce da gestire e da configurare.
Se si desidera utilizzare GLUT e compilare presso il terminale si potrebbe provare questo:
#include <GLUT/glut.h>
void display(void) {
//clear white, draw with black
glClearColor(255, 255, 255, 0);
glColor3d(0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//this draws a square using vertices
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(0, 128);
glVertex2i(128, 128);
glVertex2i(128, 0);
glEnd();
//a more useful helper
glRecti(200, 200, 250, 250);
glutSwapBuffers();
}
void reshape(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//set the coordinate system, with the origin in the top left
gluOrtho2D(0, width, height, 0);
glMatrixMode(GL_MODELVIEW);
}
void idle(void) {
glutPostRedisplay();
}
int main(int argc, char *argv) {
//a basic set up...
glutInit(&argc, &argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
//create the window, the argument is the title
glutCreateWindow("GLUT program");
//pass the callbacks
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
//we never get here because glutMainLoop() is an infinite loop
return 0;
}
e quindi compilare con:
gcc /System/Library/Frameworks/GLUT.framework/GLUT /System/Library/Frameworks/OpenGL.framework/OpenGL main.c -o myGlutApp
Questo dovrebbe fare il trucco. Direi comunque che non provi a combattere XCode, ti farà risparmiare tempo e frustrazione.
Ho provato il metodo in terminale ma ho ricevuto: ciao.c: 47: 21: errore: GL/glut.h: nessun file o directory – clwen
hmmm, sto eseguendo 10.6 (snow leopard) e funziona. puoi verificare di avere GLUT sul tuo sistema? hai installato XCode e gli strumenti di sviluppo di Apple? – whg
Funziona dopo aver modificato il percorso di inclusione da "GL/glut.h" a "GLUT/glut.h". Molte grazie! – clwen