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     ConfigOption optFSAA;
    00034
    00035     // FS setting possiblities
    00036     optFullScreen.name = "Full Screen";
    00037     optFullScreen.possibleValues.push_back("Yes");
    00038     optFullScreen.possibleValues.push_back("No");
    00039     optFullScreen.currentValue = "Yes";
    00040     optFullScreen.immutable = false;
    00041
    00042     // Video mode possiblities
    00043     optVideoMode.name = "Video Mode";
    00044     optVideoMode.immutable = false;
    00045     for (size_t i = 0; mVideoModes[i]; i++)
    00046     {
    00047         char szBuf[16];
    00048         snprintf(szBuf, 16, "%d x %d", mVideoModes[i]->w, mVideoModes[i]->h);
    00049         optVideoMode.possibleValues.push_back(szBuf);
    00050         // Make the first one default
    00051         if (i == 0)
    00052         {
    00053             optVideoMode.currentValue = szBuf;
    00054         }
    00055     }
    00056
    00057     //FSAA possibilities
    00058     optFSAA.name = "FSAA";
    00059     optFSAA.possibleValues.push_back("0");
    00060     optFSAA.possibleValues.push_back("2");
    00061     optFSAA.possibleValues.push_back("4");
    00062     optFSAA.possibleValues.push_back("6");
    00063     optFSAA.currentValue = "0";
    00064     optFSAA.immutable = false;
    00065
    00066     mOptions[optFullScreen.name] = optFullScreen;
    00067     mOptions[optVideoMode.name] = optVideoMode;
    00068     mOptions[optFSAA.name] = optFSAA;
    00069 }
    00070
    00071 String SDLGLSupport::validateConfig(void)
    00072 {
    00073     return String("");
    00074 }
    00075
    00076 RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)
    00077 {
    00078     if (autoCreateWindow)
    00079     {
    00080         ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
    00081         if (opt == mOptions.end())
    00082             Except(999, "Can't find full screen options!", "SDLGLSupport::createWindow");
    00083         bool fullscreen = (opt->second.currentValue == "Yes");
    00084
    00085         opt = mOptions.find("Video Mode");
    00086         if (opt == mOptions.end())
    00087             Except(999, "Can't find video mode options!", "SDLGLSupport::createWindow");
    00088         String val = opt->second.currentValue;
    00089         String::size_type pos = val.find('x');
    00090         if (pos == String::npos)
    00091             Except(999, "Invalid Video Mode provided", "SDLGLSupport::createWindow");
    00092
    00093         int fsaa_x_samples = 0;
    00094         opt = mOptions.find("FSAA");
    00095         if(opt != mOptions.end()) //check for FSAA parameter, if not ignore it...
    00096         {
    00097             fsaa_x_samples = StringConverter::parseInt(opt->second.currentValue);
    00098             if(fsaa_x_samples>1) {
    00099                 // If FSAA is enabled in the parameters, enable the MULTISAMPLEBUFFERS
    00100                 // and set the number of samples before the render window is created.
    00101                 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
    00102                 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,fsaa_x_samples);
    00103             }
    00104         }
    00105
    00106         unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
    00107         unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
    00108
    00109         const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
    00110         return renderSystem->createRenderWindow(windowTitle, w, h, videoInfo->vfmt->BitsPerPixel, fullscreen);
    00111     }
    00112     else
    00113     {
    00114         // XXX What is the else?
    00115         return NULL;
    00116     }
    00117 }
    00118
    00119 RenderWindow* SDLGLSupport::newWindow(const String& name, unsigned int width, unsigned int height, unsigned int colourDepth,
    00120         bool fullScreen, int left, int top, bool depthBuffer, RenderWindow* parentWindowHandle,
    00121         bool vsync)
    00122 {
    00123     SDLWindow* window = new SDLWindow();
    00124     window->create(name, width, height, colourDepth, fullScreen, left, top, depthBuffer,
    00125         parentWindowHandle);
    00126     return window;
    00127 }
    00128
    00129 void SDLGLSupport::start()
    00130 {
    00131     LogManager::getSingleton().logMessage(
    00132         "******************************\n"
    00133         "*** Starting SDL Subsystem ***\n"
    00134         "******************************");
    00135
    00136     SDL_Init(SDL_INIT_VIDEO);
    00137 }
    00138
    00139 void SDLGLSupport::stop()
    00140 {
    00141     LogManager::getSingleton().logMessage(
    00142         "******************************\n"
    00143         "*** Stopping SDL Subsystem ***\n"
    00144         "******************************");
    00145
    00146     SDL_Quit();
    00147 }
    00148
    00149 void* SDLGLSupport::getProcAddress(const String& procname)
    00150 {
    00151     return SDL_GL_GetProcAddress(procname.c_str());
    00152 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:45 2004