SKELETON GLUT PROGRAM
/* glutskel.c */
/*
* A skeleton/template GLUT program
*/
#include <stdio.h >
#include <stdlib.h >
#include <math.h >
#include <GL/glut.h >
static void Idle( void )
{
/* update animation vars --
THIS ONLY MARKS THE CURR WINDOW FOR REDISPLAY! */
glutPostRedisplay();
}
static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
/* draw stuff here */
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
/* width and height are in pixels */
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -15.0 );
}
static void Key( unsigned char key, int x, int y )
{
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
/* Special keys include the function keys (1-12),
arrow directions, page up/down, home, end */
static void SpecialKey( int key, int x, int y )
{
switch (key) {
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
case GLUT_KEY_LEFT:
break;
case GLUT_KEY_RIGHT:
break;
}
glutPostRedisplay();
}
static void Init( void )
{
/* setup lighting, etc */
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv ); // glutInit() has arguments like main()
glutInitWindowSize( 400, 400 );
// So we want a color buffer,
// double buffering and z-buffering:
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
// Get a top level window:
glutCreateWindow(argv[0]);
Init();
// Now we register callback functions:
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutMainLoop(); // This is always the last glut
// command to call -- it does not return.
}