rtcRenderManager.cpp
Go to the documentation of this file.
00001 //== INCLUDES ==================================================================
00002 #include <cmath>
00003 #include <IL/il.h>
00004 #include <IL/ilu.h>
00005 #include <IL/ilut.h>
00006 #include "rtc/rtcRenderer.h"
00007 #include "rtc/rtcRenderManager.h"
00008 
00009 //== NAMESPACES ===============================================================
00010 namespace rtc {
00011 
00012 Renderer* renderers[MAX_NUMBER_OF_RENDERERS];
00013 
00014 int RenderManager::m_currentIdleRenderer = 0;
00015 int RenderManager::m_idleFunctionEnabled = 0;
00016 static int use_glui = 1;
00017 
00018 //== IMPLEMENTATION ============================================================
00019 
00020 // --------------------------------------------------
00021 // RenderManager
00022 // --------------------------------------------------
00023 
00024 // constructor
00025 RenderManager::RenderManager(int* argc, char **argv)
00026 {
00027   // initialize il
00028   ilInit();
00029   iluInit();
00030   ilutRenderer(ILUT_OPENGL);
00031   // initialize glut
00032   glutInit(argc, argv);
00033 }
00034 
00035 // destructor
00036 RenderManager::~RenderManager()
00037 {
00038 }
00039 
00040 void RenderManager::callbackDisplayFunc(void)
00041 {
00042 //  int windowID = glutGetWindow();
00043   renderers[0]->display();
00044 }
00045 
00046 void RenderManager::callbackIdleFunc(void)
00047 {
00048   if(m_idleFunctionEnabled && m_currentIdleRenderer){
00049     glutSetWindow(m_currentIdleRenderer);
00050     //TODO: implement idle callback
00051     //renderers[m_currentIdleRenderer]->idle();
00052   }
00053   renderers[0]->idle();
00054 }
00055 
00056 void RenderManager::callbackKeyboardFunc(unsigned char key, int x, int y)
00057 {
00058 //  int windowID = glutGetWindow();
00059   renderers[0]->keyboard(key, x, y);
00060 }
00061 
00062 void RenderManager::callbackMotionFunc(int x, int y)
00063 {
00064 //  int windowID = glutGetWindow();
00065   renderers[0]->motion(x, y);
00066 }
00067 
00068 void RenderManager::callbackMouseFunc(int button, int state, int x, int y)
00069 {
00070 //  int windowID = glutGetWindow();
00071   renderers[0]->mouse(button, state, x, y);
00072 }
00073 
00074 void RenderManager::callbackPassiveMotionFunc(int x, int y)
00075 {
00076 //  int windowID = glutGetWindow();
00077   renderers[0]->passive_motion(x, y);
00078 }
00079 
00080 void RenderManager::callbackReshapeFunc(int w, int h)
00081 {
00082 //  int windowID = glutGetWindow();
00083   renderers[0]->reshape(w, h);
00084 }
00085 
00086 void RenderManager::callbackSpecialFunc(int key, int x, int y)
00087 {
00088 //  int windowID = glutGetWindow();
00089   renderers[0]->special(key, x, y);
00090 }
00091 
00092 void RenderManager::callbackVisibilityFunc(int visible)
00093 {
00094 //  int windowID = glutGetWindow();
00095   renderers[0]->visibility(visible);
00096 }
00097 
00098 void RenderManager::callbackTimerFunc(int value)
00099 {
00100 //  int windowID = glutGetWindow();
00101   renderers[0]->timer();
00102   glutTimerFunc((int)floor(1000.0 / 30.0), callbackTimerFunc, 0);
00103 }
00104 
00105 int RenderManager::createWindow(const char* title, Renderer* renderer)
00106 {
00107   // Open new window, record its windowID ,
00108   int windowID = glutCreateWindow(title);
00109 
00110   // Initialize glew
00111   GLenum err = glewInit();
00112   if (GLEW_OK != err) {
00113     printf("Error: %s\n", glewGetErrorString(err));
00114     exit(0);
00115   }
00116 
00117   fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
00118 
00119   // Store the address of new window in global array
00120   // so RenderManager can send events to propoer callback functions.
00121   renderers[0] = renderer;
00122 
00123   // Hand address of universal static callback functions to Glut.
00124   // This must be for each new window, even though the address are constant.
00125   if(use_glui) {
00126       GLUI_Master.set_glutKeyboardFunc(callbackKeyboardFunc);
00127       GLUI_Master.set_glutSpecialFunc(callbackSpecialFunc);
00128       GLUI_Master.set_glutMouseFunc(callbackMouseFunc);
00129       GLUI_Master.set_glutReshapeFunc(callbackReshapeFunc);
00130       // Do not uncomment this line.  It causes CPU usage to go to
00131       // 100 %
00132       //GLUI_Master.set_glutIdleFunc(callbackIdleFunc);
00133   }
00134   else {
00135     glutReshapeFunc(callbackReshapeFunc);
00136     glutSpecialFunc(callbackSpecialFunc);
00137     glutKeyboardFunc(callbackKeyboardFunc);
00138     glutMouseFunc(callbackMouseFunc);
00139   }
00140 
00141   glutDisplayFunc(callbackDisplayFunc);
00142   glutIdleFunc(callbackIdleFunc);
00143   glutMotionFunc(callbackMotionFunc);
00144   //glutPassiveMotionFunc(callbackPassiveMotionFunc);
00145   //glutVisibilityFunc(callbackVisibilityFunc);
00146   glutTimerFunc((int)floor(1000.0 / 30.0), callbackTimerFunc, 0);
00147 
00148   return windowID;
00149 }
00150 
00151 void RenderManager::dispatch(void)
00152 {
00153   glutMainLoop();
00154 }
00155 
00156 void RenderManager::disableIdleFunction(void)
00157 {
00158   m_idleFunctionEnabled = 0;
00159 }
00160 
00161 void RenderManager::enableIdleFunction(void)
00162 {
00163   m_idleFunctionEnabled = 1;
00164 }
00165 
00166 int RenderManager::idleFunctionEnabled(void)
00167 {
00168   // Is idle function enabled?
00169   return(m_idleFunctionEnabled);
00170 }
00171 
00172 int RenderManager::idleSetToCurrentWindow(void)
00173 {
00174   // Is current idle window same as current window?
00175   return( m_currentIdleRenderer == glutGetWindow() );
00176 }
00177 
00178 void RenderManager::setIdleToCurrentWindow(void)
00179 {
00180   m_currentIdleRenderer = glutGetWindow();
00181 }
00182 
00183 //==============================================================================
00184 } // namespace rtc
00185 //==============================================================================


rtc
Author(s): Benjamin Pitzer
autogenerated on Thu Jan 2 2014 11:04:53