How to safely load RenderSystems

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Kai-Peter
Greenskin
Posts: 133
Joined: Tue Oct 15, 2002 10:14 am
Location: Helsinki, Finland
x 1

How to safely load RenderSystems

Post by Kai-Peter »

Having your application crash on loading is pretty sad. It's slightly unprofessional and is tedious to debug with an user. One thing that can fail in a great number of ways is loading the rendersystems, especially the DX variants.

This is the solution I use in ShortHike. I have disable the plugins.cfg file and load the plugins manually instead. I use this snippet of code to check for the DirectX version and to load the rendersystem. The GetDXVersion is included with the DirectX SDK.

This snipped guards against two common situations:
- The computer is running an older version of DirectX (5, 6, 7 etc). Loading the DX9 plugin would crash your application with a missing DLL call
- You have compiled OGRE on 9.0c and the user has 9.0b. The versions aren't compatible so the we need an inner try/catch

Enjoy! :D

Code: Select all

void
Main::loadRenderSystems()
{
  Root* ogreRoot = Root::getSingletonPtr();

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
  HRESULT hr;
  DWORD dwDirectXVersion = 0;
  TCHAR strDirectXVersion[10];
  
  hr = GetDXVersion( &dwDirectXVersion, strDirectXVersion, 10 );
  if( SUCCEEDED(hr) ) {
    ostringstream dxinfoStream;
    dxinfoStream << "DirectX version: " << strDirectXVersion;
    LogManager::getSingleton().logMessage(dxinfoStream.str());
    
    if(dwDirectXVersion >= 0x00090000) {
      try {
        ogreRoot->loadPlugin("RenderSystem_Direct3D9");
      }
      catch(Exception& e) {
        LogManager::getSingleton().logMessage(String("Unable to create D3D9 RenderSystem: ") + e.getFullDescription());
      }
    }
  }
#endif
  try {
    ogreRoot->loadPlugin("RenderSystem_GL");  
  }
  catch(Exception& e) {
    LogManager::getSingleton().logMessage(String("Unable to create OpenGL RenderSystem: ") + e.getFullDescription());
  }

  try {
    ogreRoot->loadPlugin("Plugin_CgProgramManager");  
  }
  catch(Exception& e) {
    LogManager::getSingleton().logMessage(String("Unable to create CG Program manager RenderSystem: ") + e.getFullDescription());
  }
}
Kai Backman, programmer (Blog)
ShortHike - Space Station Game
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Wiki please :)
Kai-Peter
Greenskin
Posts: 133
Joined: Tue Oct 15, 2002 10:14 am
Location: Helsinki, Finland
x 1

Post by Kai-Peter »

Kai Backman, programmer (Blog)
ShortHike - Space Station Game
Drew_Benton
Halfling
Posts: 95
Joined: Sun Apr 03, 2005 6:58 pm

Post by Drew_Benton »

Thank you so much! :D This is definitly needed since the release of the new DX SDK is a pain to use with computers that do not have it. Keep up the good work!

- Drew