Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7989 for code/branches


Ignore:
Timestamp:
Feb 27, 2011, 5:08:13 PM (14 years ago)
Author:
landauf
Message:

added console command to change screen resolution and fullscreen mode at runtime
added console commands to change FSAA and VSync (require restart)

Location:
code/branches/usability/src/libraries/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/core/GraphicsManager.cc

    r7966 r7989  
    4949#include "SpecialConfig.h"
    5050#include "util/Clock.h"
     51#include "util/Convert.h"
    5152#include "util/Exception.h"
    5253#include "util/StringUtils.h"
     
    6869namespace orxonox
    6970{
     71    static const std::string __CC_GraphicsManager_group = "GraphicsManager";
     72    static const std::string __CC_setScreenResolution_name = "setScreenResolution";
     73    static const std::string __CC_setFSAA_name = "setFSAA";
     74    static const std::string __CC_setVSync_name = "setVSync";
     75    DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name, &prototype::string__uint_uint_bool);
     76    DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name, &prototype::string__string);
     77    DeclareConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name, &prototype::string__bool);
     78
    7079    static const std::string __CC_printScreen_name = "printScreen";
    7180    DeclareConsoleCommand(__CC_printScreen_name, &prototype::void__void);
     
    138147        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
    139148        ModifyConsoleCommand(__CC_printScreen_name).resetFunction();
     149        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).resetFunction();
     150        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).resetFunction();
     151        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).resetFunction();
    140152
    141153        // Undeclare the resources
     
    332344        // add console commands
    333345        ModifyConsoleCommand(__CC_printScreen_name).setFunction(&GraphicsManager::printScreen, this);
     346        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).setFunction(&GraphicsManager::setScreenResolution, this);
     347        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setFSAA_name).setFunction(&GraphicsManager::setFSAA, this);
     348        ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setVSync_name).setFunction(&GraphicsManager::setVSync, this);
    334349    }
    335350
     
    463478    }
    464479
     480    std::string GraphicsManager::setScreenResolution(unsigned int width, unsigned int height, bool fullscreen)
     481    {
     482        this->ogreRoot_->getRenderSystem()->setConfigOption("Video Mode", multi_cast<std::string>(width) + " x " + multi_cast<std::string>(height) + " @ " + multi_cast<std::string>(this->getRenderWindow()->getColourDepth()) + "-bit colour");
     483        this->ogreRoot_->getRenderSystem()->setConfigOption("Full Screen", fullscreen ? "Yes" : "No");
     484
     485        std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions();
     486
     487        if (validate == "")
     488        {
     489            GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height);
     490            this->ogreRoot_->saveConfig();
     491            Core::getInstance().updateOgreConfigTimestamp();
     492        }
     493
     494        return validate;
     495    }
     496
     497    std::string GraphicsManager::setFSAA(const std::string& mode)
     498    {
     499        this->ogreRoot_->getRenderSystem()->setConfigOption("FSAA", mode);
     500
     501        std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions();
     502
     503        if (validate == "")
     504        {
     505            //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
     506            this->ogreRoot_->saveConfig();
     507            Core::getInstance().updateOgreConfigTimestamp();
     508        }
     509
     510        return validate;
     511    }
     512
     513    std::string GraphicsManager::setVSync(bool vsync)
     514    {
     515        this->ogreRoot_->getRenderSystem()->setConfigOption("VSync", vsync ? "Yes" : "No");
     516
     517        std::string validate = this->ogreRoot_->getRenderSystem()->validateConfigOptions();
     518
     519        if (validate == "")
     520        {
     521            //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
     522            this->ogreRoot_->saveConfig();
     523            Core::getInstance().updateOgreConfigTimestamp();
     524        }
     525
     526        return validate;
     527    }
     528
    465529    void GraphicsManager::printScreen()
    466530    {
  • code/branches/usability/src/libraries/core/GraphicsManager.h

    r7401 r7989  
    9696        // console commands
    9797        void printScreen();
     98        std::string setScreenResolution(unsigned int width, unsigned int height, bool fullscreen);
     99        std::string setFSAA(const std::string& mode);
     100        std::string setVSync(bool vsync);
    98101
    99102        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
  • code/branches/usability/src/libraries/core/command/ConsoleCommand.h

    r7861 r7989  
    317317        inline void void__void(void) {}
    318318        inline void void__string(const std::string&) {}
     319
     320        inline std::string string__bool(bool) { return ""; }
     321        inline std::string string__string(const std::string&) { return ""; }
     322        inline std::string string__uint_uint_bool(unsigned int, unsigned int, bool) { return ""; }
    319323    }
    320324
Note: See TracChangeset for help on using the changeset viewer.