irrlichtWrapper.cpp

00001 
00002 #include "main.h"
00003 #include "physxDebugHelper.h"
00004 #include "irrlichtWrapper.h"
00005 #include "physxWrapper.h"
00006 
00007 
00008 // will result in fullscreen only if video card can handle. windowed else.
00009 #define SCREEN_WIDTH    1024//1280
00010 #define SCREEN_HEIGHT   SCREEN_WIDTH/16*9//768//960
00011 
00012 
00013 // only visible within this file
00014 static NxDebugRenderer* nxDebugRenderer = NULL;
00015 
00016 
00017 // init irrlicht and setup global symbols from main.h
00018 ERR_TYPE irrlichtInit()
00019 {
00020         // try create DX9 graphics
00021         // DX9, windowSize, 32 bitPerPixel, fullscreen NO, stancilShadows YES
00022         device = createDevice( EDT_DIRECT3D9, dimension2d<s32>(SCREEN_WIDTH, SCREEN_HEIGHT), 32, false, true );
00023         if ( NULL == device )
00024         {
00025                 // failed, try create openGL graphics
00026                 device = createDevice( EDT_OPENGL, dimension2d<s32>(SCREEN_WIDTH, SCREEN_HEIGHT), 32, false, true );
00027                 if ( NULL == device )
00028                 {
00029                         // failed, try create Software graphics
00030                         device = createDevice( EDT_BURNINGSVIDEO, dimension2d<s32>(SCREEN_WIDTH, SCREEN_HEIGHT) );
00031                         if ( NULL == device )
00032                         {
00033                                 return ERR_IRRLICHT_INIT_FAILED;
00034                         }
00035                 }
00036         }
00037 
00038         driver = device->getVideoDriver();
00039         smgr = device->getSceneManager();
00040         guienv = device->getGUIEnvironment();
00041         logger = device->getLogger();
00042         timer = device->getTimer();
00043 
00044         // create our physics debug renderer
00045         nxDebugRenderer = new NxDebugRenderer();
00046 
00047         // fill window black and display text
00048         IGUIStaticText* text = guienv->addStaticText(   stringw("loading").c_str(),
00049                                                                                                         rect<s32>(      SCREEN_WIDTH/2-16, 
00050                                                                                                                                 SCREEN_HEIGHT/2-6, 
00051                                                                                                                                 SCREEN_WIDTH/2+17, 
00052                                                                                                                                 SCREEN_HEIGHT/2+6),
00053                                                                                                         true, 
00054                                                                                                         true, 
00055                                                                                                         NULL, 
00056                                                                                                         -1, 
00057                                                                                                         true );
00058         driver->beginScene( true, true, SColor(0) );
00059         guienv->drawAll();
00060         driver->endScene();
00061         text->remove();
00062 
00063         // disable mip map creation, we want full resolution on any scale
00064         driver->setTextureCreationFlag( ETCF_CREATE_MIP_MAPS, false );
00065         // enable A8R8G8B8 color format by default
00066         driver->setTextureCreationFlag( ETCF_ALWAYS_32_BIT, true );
00067 
00068         return ERR_OK;
00069 }
00070 
00071 
00072 // to be called every frame
00073 ERR_TYPE irrlichtUpdate()
00074 {
00075         static s32 lastFPS = 0;
00076         static bool firstCall = true;
00077 
00078         if ( device->run() )
00079         {
00080                 if ( 1 ) //device->isWindowActive() )
00081                 {
00082                         // if this function is called the very first time, setup a "fade in" effect
00083                         if ( true == firstCall )
00084                         {
00085                                 IGUIInOutFader* fader = device->getGUIEnvironment()->addInOutFader();
00086                                 fader->setColor( SColor(0) );   // black
00087                                 fader->fadeIn( 4000 );  // 4 seconds until finished
00088                                 firstCall = false;
00089                         }
00090 
00091                         //driver->beginScene( true, true, SColor(240, 240, 240, 240) ); // background color bright grey
00092                         driver->beginScene( true, true, SColor(255, 100, 100, 100) );   // gray
00093                         //driver->beginScene( true, true, SColor(255, 0, 0, 0) );       // black
00094                         
00095                         smgr->drawAll();
00096                         guienv->drawAll();
00097                         
00098                         // draw frame around physx objects and those tricolor arrows
00099                         // can be disabled (slows down FPS alot on my machine)
00100                         if ( true == getPhysxDebugRenderingEnabled() )
00101                         {
00102                                 nxDebugRenderer->update( 0 );
00103                         }
00104 
00105                         driver->endScene();
00106 
00107                         // get irrlicht FramesPerSecond
00108                         s32 fps = driver->getFPS();
00109 
00110                         if ( lastFPS != fps )
00111                         {
00112                                 stringw str(L"");
00113                                 str += fps;
00114                                 str += " FPS";
00115 
00116                                 device->setWindowCaption( str.c_str() );
00117                                 lastFPS = fps;
00118                         }
00119                 }
00120                 return ERR_OK;
00121         }
00122         
00123         // someone quit irrlicht window somehow
00124         return ERR_IRRLICHT_UPDATE_FAILED;
00125 }
00126 
00127 
00128 // destroy irrlicht
00129 ERR_TYPE irrlichtDeinit()
00130 {
00131         if ( nxDebugRenderer )
00132         {
00133                 delete nxDebugRenderer;
00134                 nxDebugRenderer = NULL;
00135         }
00136 
00137         if ( device )
00138         {
00139                 device->drop();
00140                 device = NULL;
00141         }
00142 
00143         return ERR_OK;
00144 }

Generated on Sun Dec 2 03:10:23 2007 for TableTop by  doxygen 1.5.4