Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

/Users/blackie/Documents/myRepository/phobosengine-vc2005/phobosengine/phobosengine/GLApplication.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include "GLApplication.h"
00004 #include "Renderer.h"
00005 #include "CoreEngine.h"
00006 #include "InputSystem.h"
00007 
00008 
00009 namespace pge {
00010 
00011 
00012         //****************************************************************************
00013         //
00014         //
00015         //
00016         //****************************************************************************
00017         GLApplication::GLApplication(int resX, int resY, int bits, bool fullscreen, const std::string &title) {
00018 
00019                 // Open a window
00020                 m_windowOK = openWindow(resX, resY, bits, fullscreen, title);
00021 
00022                 if(isWindowOpened()) {
00023 
00024                         // Init OpenGL subsystem directly after opening the window.
00025                         renderer::glInit();
00026 
00027                         // Core Engine init
00028                         CoreEngine::getInstance()->init(this, resX, resY);
00029 
00030                 } else {
00031                         printf("Could not create the window.");
00032                 }
00033 
00034 #ifdef GLAPP_MAIN_LOOP
00035                 m_delay = 15;
00036                 m_lastTime = getTicks();
00037 #endif
00038         }
00039 
00040 
00041         //****************************************************************************
00042         //
00043         //
00044         //
00045         //****************************************************************************
00046         GLApplication::~GLApplication(void) {
00047         }
00048 
00049 
00050         //****************************************************************************
00051         //
00052         //
00053         //
00054         //****************************************************************************
00055         bool GLApplication::isWindowOpened(void) {
00056                 return m_windowOK;
00057         }
00058 
00059 
00060 #ifdef GLAPP_MAIN_LOOP
00061         //****************************************************************************
00062         //
00063         //
00064         //
00065         //****************************************************************************
00066         void GLApplication::setDelay(unsigned int delay) {
00067                 m_delay = delay;
00068         }
00069 
00070 
00071         //****************************************************************************
00072         //
00073         //
00074         //
00075         //****************************************************************************
00076         void GLApplication::renderCall(void) {
00077                 CoreEngine::getInstance()->render();
00078         }
00079 #endif
00080 
00081         
00082         //****************************************************************************
00083         //
00084         //
00085         //
00086         //****************************************************************************
00087         void GLApplication::initCall(void) {
00088                 CoreEngine::getInstance()->init();
00089         }
00090 
00091 
00092         //****************************************************************************
00093         //
00094         //
00095         //
00096         //****************************************************************************
00097         void GLApplication::reshapeCall(GLsizei width, GLsizei height) {
00098                 CoreEngine::getInstance()->reshape(width, height);
00099         }
00100 
00101 
00102 #ifdef GLAPP_MAIN_LOOP
00103         //****************************************************************************
00104         //
00105         //
00106         //
00107         //****************************************************************************
00108         void GLApplication::timerCall(unsigned int delay) {
00109                 InputSystem::getInstance()->timer(delay);
00110         }
00111 #endif
00112 
00113 
00114         //****************************************************************************
00115         //
00116         //
00117         //
00118         //****************************************************************************
00119         void GLApplication::keyDownCall(int key) {
00120                 InputSystem::getInstance()->keyDown(key);
00121         }
00122 
00123 
00124         //****************************************************************************
00125         //
00126         //
00127         //
00128         //****************************************************************************
00129         void GLApplication::keyUpCall(int key) {
00130                 InputSystem::getInstance()->keyUp(key);
00131         }
00132 
00133 
00134 #ifdef GLAPP_MAIN_LOOP  
00135         //****************************************************************************
00136         //
00137         //
00138         //
00139         //****************************************************************************
00140         void GLApplication::mouseMotionCall(unsigned int delay, int x, int y) {
00141                 InputSystem::getInstance()->mouseMotion(delay, x, y);
00142         }
00143 #endif
00144 
00145 
00146         //****************************************************************************
00147         //
00148         //
00149         //
00150         //****************************************************************************
00151         void GLApplication::mousePressCall(int button, int x, int y) {
00152                 InputSystem::getInstance()->mousePress(button, x, y);
00153         }
00154 
00155 
00156         //****************************************************************************
00157         //
00158         //
00159         //
00160         //****************************************************************************
00161         void GLApplication::mouseReleaseCall(int button, int x, int y) {
00162                 InputSystem::getInstance()->mouseRelease(button, x, y);
00163         }
00164 
00165 
00166         //****************************************************************************
00167         //
00168         //
00169         //
00170         //****************************************************************************
00171         void GLApplication::mainLoopCall() {
00172 
00173 #ifdef GLAPP_MAIN_LOOP
00174 
00175                 unsigned int temp = 0;
00176                 MouseCoordinate m;
00177 
00178 
00179                 renderCall();
00180                 // swap the buffer
00181                 swapBuffer();
00182 
00183                 temp = getTicks();
00184                 // timer
00185                 if(temp >= (m_lastTime + m_delay)) {
00186                         timerCall(temp - m_lastTime);
00187 
00188                         // mouse motion
00189                         m = getMousePointer();
00190                         mouseMotionCall(temp - m_lastTime, m.x, m.y);
00191                         // Set mouse pointer to the middle of the screen.
00192                         setMousePointer(getResolutionWidth() / 2, getResolutionHeight() / 2);
00193 
00194                         m_lastTime = temp;
00195                 }
00196 
00197                 // TODO
00198                 sleep(10);
00199 
00200 #else
00201                 CoreEngine::getInstance()->mainLoop();
00202 #endif
00203         }
00204 };

Generated on Mon Oct 16 12:08:10 2006 for Phobosengine by doxygen 1.3.4