Well, here’s hoping that that A. the formatting (with tabs and all) goes through and B. that I don’t tick off too many folks with the large post.
You’ll have to guess what the MySystem object is doing (it’s pretty obvious tho (I think)).
// main.cpp
#include <glut.h>
#include “MySystem.h”
//==============================================================================
static MySystem * mySys = static_cast<MySystem *>( 0 );
static float light_pos = { 1.5 , 0.0 , 0.0 , 1.0 }; // Positional.
//==============================================================================
void init()
{
glClearColor( 0.0 , 0.0 , 0.0 , 0.0 );
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
float mat_specular = { 1.0 , 1.0 , 1.0 , 1.0 };
float mat_shininess = 50.0 ;
float mat_amb_and_diffuse = { 0.0 , 0.8 , 0.2 , 1.0 };
float light_ambient = { 0.4 , 0.4 , 0.4 , 1.0 };
float white_light = { 1.0 , 1.0 , 1.0 , 1.0 };
glMaterialfv( GL_FRONT_AND_BACK , GL_SPECULAR , mat_specular );
glMaterialf( GL_FRONT_AND_BACK , GL_SHININESS , mat_shininess );
glMaterialfv( GL_FRONT_AND_BACK , GL_AMBIENT_AND_DIFFUSE , mat_amb_and_diffuse );
glLightfv( GL_LIGHT0 , GL_AMBIENT , light_ambient );
glLightfv( GL_LIGHT0 , GL_DIFFUSE , white_light ); // redundant
glLightfv( GL_LIGHT0 , GL_SPECULAR , white_light ); // redundant
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER , GL_TRUE );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE , GL_TRUE );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
mySys = new MySystem();
}
//==============================================================================
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
mySys->draw();
glutSwapBuffers();
}
//==============================================================================
void idleFunc()
{
mySys->update();
glutPostRedisplay();
}
//==============================================================================
void reshape( int w , int h )
{
glViewport( 0 , 0 , static_cast( w ) , static_cast( h ) );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 30.0 , // fovy
static_cast( w ) / static_cast( h ) , // aspect
1.0 , // near
8.0 // far
);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 1.0 , 1.0 , 5.0 , // eye
0.3 , 0.5 , 0.0 , // where it’s aimed
0.0 , 1.0 , 0.0 // which way is up
);
glLightfv( GL_LIGHT0 , GL_POSITION , light_pos );
}
//==============================================================================
void mouse( int button , int state , int x , int y )
{
switch ( button )
{
case GLUT_LEFT_BUTTON :
if ( state == GLUT_DOWN )
{
glutIdleFunc( idleFunc );
}
break ;
case GLUT_RIGHT_BUTTON :
if ( state == GLUT_DOWN )
{
glutIdleFunc( 0 );
}
break ;
default :
break ;
}
}
//==============================================================================
int main( int argc , char * * argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH );
glutInitWindowSize( 250 , 250 );
glutInitWindowPosition( 100 , 100 );
glutCreateWindow( “glutSys” );
init();
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutMouseFunc( mouse );
glutMainLoop();
delete mySys ;
return 0 ;
}
//==============================================================================