• Main Page
  • Classes
  • Files
  • File List

T:/Eigene Dateien/Visual Studio 2008/Projects/VisLuFramework/src/GlewContentManagement.cpp

00001 #include "GlewContentManagement.h"
00002 
00003 using namespace std;
00004 
00005 
00006 GlewContentManagement* GlewContentManagement::instance = NULL;
00007 bool GlewContentManagement::initialized = false;
00008 
00009 GlewContentManagement::~GlewContentManagement()
00010 {
00011         if(m_GlewRenderWindowContext)
00012                 delete m_GlewRenderWindowContext;
00013         if(m_GlewBottomWindowContext)
00014                 delete m_GlewBottomWindowContext;
00015         if(m_GlewRightWindowContext)
00016                 delete m_GlewRightWindowContext;
00017         if(m_GlewMainWindowContext)
00018                 delete m_GlewMainWindowContext;
00019 }
00020 
00021 GlewContentManagement::GlewContentManagement()
00022 {
00023         m_GlewRenderWindowContext = NULL;
00024         m_GlewBottomWindowContext = NULL;
00025         m_GlewRightWindowContext = NULL;
00026         m_GlewMainWindowContext = NULL;
00027 
00028         m_RenderWindowID = 0;
00029         m_BottomWindowID = 0;
00030         m_RightWindowID = 0;
00031         m_MainWindowID = 0;
00032 }
00033 
00034 GlewContentManagement *GlewContentManagement::getInstance()
00035 {
00036         if(!initialized)
00037         {
00038                 instance = new GlewContentManagement();
00039                 initialized = true;
00040         }
00041 
00042         return instance;
00043 }
00044 
00045 void GlewContentManagement::initRenderWindowContext()
00046 {
00047         m_RenderWindowID = glutGetWindow();
00048         m_GlewRenderWindowContext = new GLEWContext();
00049 
00050         initGlew();
00051 }
00052 
00053 void GlewContentManagement::initBottomWindowContext()
00054 {
00055         m_BottomWindowID = glutGetWindow();
00056         m_GlewBottomWindowContext = new GLEWContext();
00057 
00058         initGlew();
00059 }
00060 
00061 void GlewContentManagement::initRightWindowContext()
00062 {
00063         m_RightWindowID = glutGetWindow();
00064         m_GlewRightWindowContext = new GLEWContext();
00065 
00066         initGlew();
00067 }
00068 
00069 void GlewContentManagement::initMainWindowContext()
00070 {
00071         m_MainWindowID = glutGetWindow();
00072         m_GlewMainWindowContext = new GLEWContext();
00073 
00074         initGlew();
00075 }
00076 
00077 
00078 GLEWContext* GlewContentManagement::getCurrentGlewContent()
00079 {
00080         if(glutGetWindow() == m_RenderWindowID) 
00081                 return m_GlewRenderWindowContext;
00082         if(glutGetWindow() == m_BottomWindowID) 
00083                 return m_GlewBottomWindowContext;
00084         if(glutGetWindow() == m_RightWindowID) 
00085                 return m_GlewRightWindowContext;
00086         if(glutGetWindow() == m_MainWindowID) 
00087                 return m_GlewMainWindowContext;
00088 
00089         cout << "Failed to find the correct GLEWContext associated with the current glut window" << endl;
00090         return m_GlewRenderWindowContext;
00091 }
00092 
00093 void GlewContentManagement::initGlew()
00094 {
00095         // Initialize GLEW
00096         std::cout << "- Initializing GLEW for ";
00097 
00098         if(glutGetWindow() == m_RenderWindowID)
00099                 std::cout << "the main display window";
00100         if(glutGetWindow() == m_BottomWindowID)
00101                 std::cout << "the bottom window";
00102         if(glutGetWindow() == m_RightWindowID)
00103                 std::cout << "the right window";
00104         if(glutGetWindow() == m_MainWindowID)
00105                 std::cout << "the main window";
00106 
00107         std::cout << "..." << std::endl;
00108 
00109         GLenum err = glewInit();
00110 
00111         if (err != GLEW_OK)
00112         {
00113                 // glewInit failed, something is seriously wrong
00114                 std::cerr << "Error initializing GLEW: " << glewGetErrorString(err) << std::endl;
00115         }
00116 
00117         fprintf(stdout, "- GLEW initialized (OpenGL  %s, GLSL %s) \n\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
00118 }
00119 
00120 
00121 
00122 GLEWContext* glewGetContext()
00123 {
00124         GlewContentManagement* glewContentManager = GlewContentManagement::getInstance();
00125 
00126         return glewContentManager->getCurrentGlewContent();
00127 }

Generated on Tue Dec 14 2010 03:52:55 for VolVis by  doxygen 1.7.2