00001
00002
00003 #include "DemoConfig.h"
00004
00005 #if defined(__APPLE__)
00006 #include <GLUT/glut.h>
00007 #else
00008 #include <GL/glut.h>
00009 #endif
00010
00011
00012
00013 DemoEventHandler handler;
00014 GuiWrapper gui(&handler);
00015
00016 void MouseClicked(int button, int state, int x, int y) ;
00017 void MouseMoved(int x, int y);
00018 void KeyTyped(unsigned char key, int x, int y);
00019 void InitializeScene();
00020 void SetPerspective(int width, int height);
00021 void RenderScene();
00022 void InputKey(int key, int x, int y);
00023
00024 int main(int argc, char *argv[])
00025 {
00026
00027 std::string DataDir = DEMO_DATA_DIR;
00028 if (argc == 2) DataDir = argv[1];
00029
00030 glutInit(&argc, argv);
00031 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
00032 glutInitWindowPosition(0, 0);
00033 glutInitWindowSize(700, 500);
00034 glutCreateWindow("GLUT Demo");
00035
00036
00037
00038 glutKeyboardFunc(KeyTyped);
00039 glutSpecialFunc(InputKey);
00040
00041
00042 glutDisplayFunc(RenderScene);
00043 glutIdleFunc(RenderScene);
00044
00045 glutReshapeFunc(SetPerspective);
00046
00047
00048 glutMouseFunc(MouseClicked);
00049 glutPassiveMotionFunc(MouseMoved);
00050 glutMotionFunc(MouseMoved);
00051
00052 gui.Init(DataDir.c_str());
00053
00054 glutMainLoop();
00055
00056 return(0);
00057 }
00058
00059 int oldTime = 0;
00060
00061 void RenderScene()
00062 {
00063 glClearColor(handler.red, handler.green, handler.blue, 0.0f);
00064 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00065
00066
00067 int time = glutGet(GLUT_ELAPSED_TIME);
00068 gui.Update((time-oldTime)/1000.0f);
00069 oldTime = time;
00070
00071 if (gui.IsActive()) gui.RenderScene();
00072 glutSwapBuffers();
00073 }
00074
00075
00076 void SetPerspective( int width, int height)
00077 {
00078 float aspectRatio = 1.33f;
00079 height = height <= 0 ? 1 : height;
00080 aspectRatio = (float)width/height;
00081
00082 glViewport(0, 0, width, height);
00083 glMatrixMode(GL_PROJECTION);
00084
00085 glLoadIdentity();
00086 gluPerspective(90.0f, aspectRatio, 1.0f, 1500.0f);
00087
00088 glMatrixMode(GL_MODELVIEW);
00089 glLoadIdentity();
00090
00091 gui.SetDimensions(width, height);
00092 }
00093
00094 void MouseClicked(int button, int state, int x, int y)
00095 {
00096 button = (button == GLUT_LEFT_BUTTON ) ? 1 :
00097 (button == GLUT_RIGHT_BUTTON) ? 2 : 3;
00098
00099 gui.MouseClicked(button, (state == GLUT_DOWN), x, y);
00100 }
00101
00102 void MouseMoved(int x, int y)
00103 {
00104 gui.MouseMoved(x, y);
00105 }
00106
00107 void KeyTyped(unsigned char key, int x, int y)
00108 {
00109 gui.AsciiKeyDown(key);
00110
00111 if (key == 27)
00112 exit(0);
00113 }
00114
00115 void InputKey(int key, int x, int y)
00116 {
00117 gui.SpecialKeyDown(key);
00118 }
00119