00001
00015 #ifndef GLUTAPP_H
00016 #define GLUTAPP_H
00017
00018 #include <string>
00019 #include <vector>
00020 #include <iostream>
00021 #include <boost/shared_ptr.hpp>
00022
00023
00024
00025 #include "GLHeaders.h"
00026 #include "util/Error.h"
00027 #include "Application.h"
00028
00029 namespace green
00030 {
00043 class glutApp
00044 {
00045 public:
00050 glutApp() {
00051 if(!glutApp::initialized)
00052 glutApp::_initialize();
00053 mWindowID = -1;
00054 }
00055
00056 virtual ~glutApp() {}
00057
00067 int CreateWindow(std::string name, unsigned int displayMode,
00068 int width, int height);
00069
00070
00074 virtual void RegisterGLUTCallbacks();
00075
00077 void SetCurrent(ApplicationPtr app) {
00078 if(glutApp::currentApp.get())
00079 THROW_ERROR("there is already a running application");
00080 glutApp::currentApp = app;
00081 }
00082
00085 virtual void Init();
00086
00088 virtual void Run();
00089
00091 int WindowWidth() const;
00093 int WindowHeight() const;
00094
00095
00096
00097 protected:
00102 static inline
00103 Application::MouseButton ConvertGLUTButton(int glutButton) {
00104 Application::MouseButton button;
00105 switch(glutButton)
00106 {
00107 case GLUT_LEFT_BUTTON:
00108 button = Application::LEFT_BUTTON;
00109 break;
00110 case GLUT_RIGHT_BUTTON:
00111 button = Application::RIGHT_BUTTON;
00112 break;
00113 case GLUT_MIDDLE_BUTTON:
00114 button = Application::MIDDLE_BUTTON;
00115 break;
00116 default:
00117 THROW_ERROR("unknown glut button type");
00118 break;
00119 }
00120 return button;
00121 }
00122
00125 static inline
00126 Application::MouseState ConvertGLUTState(int state) {
00127 Application::MouseState ret;
00128 switch(state)
00129 {
00130 case GLUT_UP:
00131 ret = Application::UP;
00132 break;
00133 case GLUT_DOWN:
00134 ret = Application::DOWN;
00135 break;
00136 default:
00137 THROW_ERROR("unknown glut mouse state");
00138 break;
00139 }
00140 return ret;
00141 }
00142
00143
00144
00145
00147 int mWindowID;
00148
00149 static ApplicationPtr currentApp;
00150 static bool initialized;
00151
00155 static void _initialize();
00156
00157
00158
00159
00161 static void _display();
00163 static void _reshape(int width, int height);
00165 static void _motion(int x, int y);
00167 static void _mouse(int button, int state, int x, int y);
00169 static void _keyboard(unsigned char ch, int x, int y);
00171 static void _keyboard_up(unsigned char ch, int x, int y);
00172
00173 };
00174 typedef boost::shared_ptr<glutApp> glutAppPtr;
00175 }
00176
00177 #endif