00001 #ifndef __GLUT_WINDOW_H__ 00002 #define __GLUT_WINDOW_H__ 00003 00004 #include "windows.h" 00005 #include <string> 00006 #include <map> 00007 #include <GL/glew.h> 00008 #include <GL/glut.h> 00009 #include "cglib/arcball_camera.h" 00010 00011 using namespace std; 00012 00013 struct NormalKey 00014 { 00015 unsigned char key; 00016 int modifiers; 00017 00018 NormalKey() 00019 { 00020 key = 0; 00021 modifiers = 0; 00022 } 00023 00024 NormalKey(unsigned char _key, int _modifiers) 00025 { 00026 key = _key; 00027 modifiers = _modifiers; 00028 } 00029 }; 00030 00031 struct NormalKeyOrdering 00032 { 00033 bool operator()(const NormalKey a, const NormalKey b) const 00034 { 00035 return (a.key < b.key) || (a.key == b.key && a.modifiers < b.modifiers); 00036 } 00037 }; 00038 00039 struct SpecialKey 00040 { 00041 int key; 00042 int modifiers; 00043 00044 SpecialKey() 00045 { 00046 key = 0; 00047 modifiers = 0; 00048 } 00049 00050 SpecialKey(int _key, int _modifiers) 00051 { 00052 key = _key; 00053 modifiers = _modifiers; 00054 } 00055 }; 00056 00057 struct SpecialKeyOrdering 00058 { 00059 bool operator()(const SpecialKey a, const SpecialKey b) const 00060 { 00061 return (a.key < b.key) || (a.key == b.key && a.modifiers < b.modifiers); 00062 } 00063 }; 00064 00065 typedef void (*NormalKeyHandler)(unsigned char, int, int); 00066 typedef void (*SpecialKeyHandler)(int, int, int); 00067 typedef map<NormalKey, NormalKeyHandler, NormalKeyOrdering> NormalKeyHandlerMap; 00068 typedef map<SpecialKey, SpecialKeyHandler, SpecialKeyOrdering> SpecialKeyHandlerMap; 00069 00070 class GlutWindow 00071 { 00072 protected: 00073 static GlutWindow *GlutWindow_instance; 00074 00075 static void StaticDisplayFunc(); 00076 static void StaticReshapeFunc(int width, int height); 00077 static void StaticIdleFunc(); 00078 static void StaticMouseFunc(int button, int state, int x, int y); 00079 static void StaticMotionFunc(int x, int y); 00080 static void StaticKeyboardFunc(unsigned char key, int x, int y); 00081 static void StaticSpecialFunc(int key, int x, int y); 00082 00083 GlutWindow() 00084 { 00085 GlutWindow_instance = this; 00086 } 00087 00088 public: 00089 virtual void DisplayFunc(); 00090 virtual void ReshapeFunc(int width, int height); 00091 virtual void IdleFunc(); 00092 virtual void MouseFunc(int button, int state, int x, int y); 00093 virtual void MotionFunc(int x, int y); 00094 virtual void KeyboardFunc(unsigned char key, int x, int y); 00095 virtual void SpecialFunc(int key, int x, int y); 00096 00097 NormalKeyHandlerMap normalKeyHandlers; 00098 SpecialKeyHandlerMap specialKeyHandlers; 00099 00100 int windowWidth, windowHeight; 00101 string windowTitle; 00102 00103 virtual void Initialize(); 00104 virtual void InitDisplay(); 00105 virtual void Draw(); 00106 00107 virtual void Run(int *argc, char **argv); 00108 00109 virtual GlutWindow *GetGlutWindowInstance(); 00110 }; 00111 00112 #endif