Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GlutSystem.cpp

Go to the documentation of this file.
00001 #ifdef WIN32
00002 #pragma warning (disable : 4786)
00003 #endif //WIN32
00004 
00005 #include "GlutSystem.h"
00006 #include <GL/glut.h>
00007 #include "GlutKeyboardDevice.h"
00008 
00009 MyGlutSystem* gGlutSystem=NULL;
00010 char *fake_argv[] =
00011 {
00012   "program",
00013 //  "-display",
00014 //  ":0",
00015 //  "-geometry",
00016 //  "500x400-34-23",
00017 //  "-indirect",
00018 //  "-iconic",
00019   NULL};
00020 
00021 int fake_argc = sizeof(fake_argv) / sizeof(char *) - 1;   
00022 SCA_ISystem* NewGlutSystem()

00023 {
00024         if (!gGlutSystem)
00025         {
00026                 gGlutSystem = new MyGlutSystem();
00027         }
00028   glutInit(&fake_argc, fake_argv);
00029     glutInitDisplayMode(GLUT_DOUBLE);
00030     glutInitWindowPosition(1, 1);
00031     glutInitWindowSize(500, 500);
00032     glutCreateWindow("GlutGamePlayer");      
00033         return gGlutSystem;
00034 }
00035 
00036 void MyGlutSystem::NextFrame()

00037 {
00038         std::vector<SCA_IInputDevice*>::iterator idev;
00039         for (idev = m_inputDevices.begin();!(idev == m_inputDevices.end());idev++) {
00040                         (*idev)->NextFrame();
00041         }
00042 }
00043 
00044 
00045 void MyGlutSpecialUp(int key, int x, int y)

00046 {
00047     
00048         if (gGlutSystem)
00049                 gGlutSystem->AddKey(key,0);
00050 }
00051 
00052 void MyGlutSpecialDown(int key, int x, int y)

00053 {
00054     
00055         if (gGlutSystem)
00056                 gGlutSystem->AddKey(key,1);
00057 }
00058 
00059 
00060 
00061 void MyGlutKeyboardUp(unsigned char key, int x, int y)

00062 {
00063     
00064         if (gGlutSystem)
00065                 gGlutSystem->AddKey(key,0);
00066 }
00067 
00068 void MyGlutKeyboardDown(unsigned char key, int x, int y)

00069 {
00070     
00071         if (gGlutSystem)
00072                 gGlutSystem->AddKey(key,1);
00073 }
00074 
00075 void MyGlutSystem::Sleep(int millisec)

00076 {
00077         // do nothing for now ;)
00078 }
00079 
00080 //void MyGlutSystem::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
00081 //{
00082 //      // do nothing for now ;)
00083 //}
00084 
00085 
00086 void MyGlutSystem::AddKey(unsigned char key, bool down)

00087 {
00088         GlutKeyboardDevice* keydev = (GlutKeyboardDevice*) this->GetKeyboardDevice();
00089         if (keydev)
00090         {
00091                 //SCA_IInputDevice::KX_EnumInputs inp = keydev->ToNative(key);
00092                 keydev->ConvertGlutEvent(key,down);
00093         }
00094         if (key ==27) /* escape */
00095         {
00096                 m_exitrequested=true;
00097                 exit(0);
00098         }
00099         //KX_KeyList is a vector<KeyData> and KeyData contains the event,val pair
00100         // todo: translate these values
00101         //m_keylist->push_back(KX_KeyData(key,down));
00102         
00103 }
00104 
00105 void MyGlutDisplay(void) {
00106     
00107         if (gGlutSystem)
00108         {
00109                 gGlutSystem->DoMainLoopCallback();
00110         
00111                 // this updates the inputdevice stuff
00112                 gGlutSystem->NextFrame();
00113         }
00114 
00115         // this is hopefully done by the client later on
00116         //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
00117     //glFlush();
00118     //glutSwapBuffers();
00119         
00120 }
00121 
00122 void MyIdleFunc(void)

00123 {
00124         glutPostRedisplay();
00125 }
00126 
00127 void MyGlutSystem::StartMainLoop()

00128 {
00129     //myinit();
00130     glutKeyboardFunc(MyGlutKeyboardDown);
00131         glutKeyboardUpFunc(MyGlutKeyboardUp);
00132     glutSpecialFunc(MyGlutSpecialDown);
00133         glutSpecialUpFunc(MyGlutSpecialUp);
00134     //glutReshapeFunc(myReshape);
00135     //createMenu();
00136     glutIdleFunc(MyIdleFunc);
00137     glutDisplayFunc(MyGlutDisplay);
00138     glutMainLoop();
00139 }
00140 
00141 
00142 double MyGlutSystem::GetTimeInSeconds()

00143 {
00144         return 0;
00145 }
00146 
00147 
00148 

Generated at Thu Feb 1 13:03:02 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000