Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreSDLGLSupport.cpp

Go to the documentation of this file.
00001 #include "OgreException.h"
00002 #include "OgreLogManager.h"
00003 #include "OgreStringConverter.h"
00004 
00005 #include "OgreSDLGLSupport.h"
00006 
00007 #include "OgreSDLWindow.h"
00008 
00009 using namespace Ogre;
00010 
00011 SDLGLSupport::SDLGLSupport()
00012 {
00013 
00014     SDL_Init(SDL_INIT_VIDEO);
00015 }
00016 
00017 SDLGLSupport::~SDLGLSupport()
00018 {
00019 }
00020 
00021 void SDLGLSupport::addConfig(void)
00022 {
00023     mVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL);
00024     
00025     if (mVideoModes == (SDL_Rect **)0)
00026     {
00027         Except(999, "Unable to load video modes",
00028                 "SDLRenderSystem::initConfigOptions");
00029     }
00030 
00031     ConfigOption optFullScreen;
00032     ConfigOption optVideoMode;
00033 
00034     // FS setting possiblities
00035     optFullScreen.name = "Full Screen";
00036     optFullScreen.possibleValues.push_back("Yes");
00037     optFullScreen.possibleValues.push_back("No");
00038     optFullScreen.currentValue = "Yes";
00039     optFullScreen.immutable = false;
00040 
00041     // Video mode possiblities
00042     optVideoMode.name = "Video Mode";
00043     optVideoMode.immutable = false;
00044     for (size_t i = 0; mVideoModes[i]; i++)
00045     {
00046         char szBuf[16];
00047         snprintf(szBuf, 16, "%d x %d", mVideoModes[i]->w, mVideoModes[i]->h);
00048         optVideoMode.possibleValues.push_back(szBuf);
00049         // Make the first one default
00050         if (i == 0)
00051         {
00052             optVideoMode.currentValue = szBuf;
00053         }
00054     }
00055     
00056     mOptions[optFullScreen.name] = optFullScreen;
00057     mOptions[optVideoMode.name] = optVideoMode;
00058 }
00059 
00060 String SDLGLSupport::validateConfig(void)
00061 {
00062     return String("");
00063 }
00064 
00065 RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem)
00066 {
00067     if (autoCreateWindow)
00068     {
00069         ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
00070         if (opt == mOptions.end())
00071             Except(999, "Can't find full screen options!", "SDLGLSupport::createWindow");
00072         bool fullscreen = (opt->second.currentValue == "Yes");
00073 
00074         opt = mOptions.find("Video Mode");
00075         if (opt == mOptions.end())
00076             Except(999, "Can't find video mode options!", "SDLGLSupport::createWindow");
00077         String val = opt->second.currentValue;
00078         String::size_type pos = val.find('x');
00079         if (pos == String::npos)
00080             Except(999, "Invalid Video Mode provided", "SDLGLSupport::createWindow");
00081 
00082         unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
00083         unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
00084 
00085         return renderSystem->createRenderWindow("OGRE Render Window", w, h, 32, fullscreen);
00086     }
00087     else
00088     {
00089         // XXX What is the else?
00090         return NULL;
00091     }
00092 }
00093 
00094 RenderWindow* SDLGLSupport::newWindow(const String& name, unsigned int width, unsigned int height, unsigned int colourDepth,
00095         bool fullScreen, int left, int top, bool depthBuffer, RenderWindow* parentWindowHandle,
00096         bool vsync)
00097 {
00098     SDLWindow* window = new SDLWindow();
00099     window->create(name, width, height, colourDepth, fullScreen, left, top, depthBuffer,
00100         parentWindowHandle);
00101     return window;
00102 }
00103 
00104 void SDLGLSupport::start()
00105 {
00106     LogManager::getSingleton().logMessage(
00107         "******************************\n"
00108         "*** Starting SDL Subsystem ***\n"
00109         "******************************");
00110 
00111     SDL_Init(SDL_INIT_VIDEO);
00112 }
00113 
00114 void SDLGLSupport::stop()
00115 {
00116     LogManager::getSingleton().logMessage(
00117         "******************************\n"
00118         "*** Stopping SDL Subsystem ***\n"
00119         "******************************");
00120 
00121     SDL_Quit();
00122 }
00123 
00124 void* SDLGLSupport::getProcAddress(const String& procname)
00125 {
00126     return SDL_GL_GetProcAddress(procname.c_str());
00127 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:27 2004