#include #ifdef _WIN32 #include #endif #ifdef __APPLE__ # include #else # include #include #include #endif #include "cvec2t.h" #include "cvec3t.h" using namespace std; typedef CVec2T Vec2f; typedef CVec3T Vec3f; namespace Params { const float WorldWidth = 1.33; const float WorldHeight = 1; const int TimerStep = 16; // millisec }; namespace WindowParams { static int WindowWidth = 800; static int WindowHeight = 600; static int MainWindow; }; void Reshape(int width, int height) { // glViewport defines part of the window we are going to use WindowParams::WindowWidth = width; WindowParams::WindowHeight = height; glViewport(0,0,width,height); // initialize the viewing transformation (camera position) to identity; // this corresponds to camera looking down negative z axis glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // specify the projection transformation (camera parameters); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // this defines a camera with orthogonal projection that captures the // part of the virtual world inside the box from // -WorldWidth/2 to WorldWidth/2 in the X direction // -WorldHeight/2 to WorldHeight/2 in the Y direction // and from 0 to 1 (default in Z direction gluOrtho2D(-Params::WorldWidth/2, Params::WorldWidth/2,-Params::WorldHeight/2,Params::WorldHeight/2); } void Keyboard( unsigned char key, int, int) { } void Draw() { glClearColor( 0.0, 0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); glMatrixMode(GL_MODELVIEW); // draw everything here glutSwapBuffers(); } void Animate(int time) { glutTimerFunc(Params::TimerStep,Animate,0); glutPostRedisplay(); } int main(int argc, char* argv[]) { // initialize glut and parse command-line aguments that glut understands glutInit(&argc, argv); // initialize dislay mode: 4 color components, double buffer and depth buffer glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(WindowParams::WindowWidth,WindowParams::WindowHeight); WindowParams::MainWindow = glutCreateWindow("Template"); // register all callbacks glutDisplayFunc(Draw); glutReshapeFunc(Reshape); glutKeyboardFunc(Keyboard); glutTimerFunc(Params::TimerStep,Animate,0); // this is an infinite loop get event - dispatch event which never returns glutMainLoop(); return 0; }