# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

nelu.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "nel/misc/path.h"
00029 #include "nel/misc/file.h"
00030 
00031 #include "3d/nelu.h"
00032 #include "3d/dru.h"
00033 #include "3d/camera.h"
00034 #include "3d/register_3d.h"
00035 #include "3d/init_3d.h"
00036 #include "nel/misc/debug.h"
00037 using namespace std;
00038 using namespace NLMISC;
00039 
00040 
00041 namespace NL3D 
00042 {
00043 
00044 const float             CNELU::DefLx=0.26f;
00045 const float             CNELU::DefLy=0.2f;
00046 const float             CNELU::DefLzNear=0.15f;
00047 const float             CNELU::DefLzFar=1000.0f;
00048 
00049 IDriver                         *CNELU::Driver=NULL;
00050 CScene                          CNELU::Scene;
00051 CShapeBank                      *CNELU::ShapeBank;
00052 CRefPtr<CCamera>        CNELU::Camera;
00053 CEventServer            CNELU::EventServer;
00054 CEventListenerAsync     CNELU::AsyncListener;
00055 
00056 
00057 bool                    CNELU::initDriver (uint w, uint h, uint bpp, bool windowed, void *systemWindow, bool offscreen) throw(EDru)
00058 {
00059         // Init debug system
00060 //      NLMISC::InitDebug();
00061 
00062         ShapeBank = new CShapeBank;
00063         // Init driver.
00064         CNELU::Driver= CDRU::createGlDriver();
00065         if (!CNELU::Driver->init())
00066         {
00067                 nlwarning ("CNELU::initDriver: init() failed");
00068                 return false;
00069         }
00070         if (!CNELU::Driver->setDisplay(systemWindow, GfxMode(w, h, bpp, windowed, offscreen)))
00071         {
00072                 nlwarning ("CNELU::initDriver: setDisplay() failed");
00073                 return false;
00074         }
00075         if (!CNELU::Driver->activate())
00076         {
00077                 nlwarning ("CNELU::initDriver: activate() failed");
00078                 return false;
00079         }
00080         return true;
00081 }
00082 
00083 
00084 void                    CNELU::initScene(CViewport viewport)
00085 {
00086         // Register basic csene.
00087         CScene::registerBasics();
00088 
00089         // Init Scene.
00090         CNELU::Scene.initDefaultTravs();
00091 
00092         // Don't add any user trav.
00093         // init default Roots.
00094         CNELU::Scene.initDefaultRoots();
00095         
00096         // Set driver.
00097         CNELU::Scene.setDriver(CNELU::Driver);
00098 
00099         // Set viewport
00100         CNELU::Scene.setViewport (viewport);
00101 
00102         // Init the world instance group
00103         CNELU::Scene.initGlobalnstanceGroup();
00104 
00105         // Create coarse mesh manager.
00106         CNELU::Scene.initCoarseMeshManager ();
00107 
00108         // init QuadGridClipManager
00109         CNELU::Scene.initQuadGridClipManager ();
00110 
00111         // Create/link a camera.
00112         CNELU::Camera= (CCamera*)Scene.createModel(NL3D::CameraId);
00113         CNELU::Scene.setCam(CNELU::Camera);
00114         CNELU::Camera->setFrustum(DefLx, DefLy, DefLzNear, DefLzFar);
00115 
00116         // Link to the shape bank
00117         CNELU::Scene.setShapeBank(CNELU::ShapeBank);
00118 }
00119 
00120 
00121 void                    CNELU::initEventServer()
00122 {
00123         CNELU::AsyncListener.reset ();
00124         CNELU::EventServer.addEmitter(CNELU::Driver->getEventEmitter());
00125         CNELU::AsyncListener.addToServer(CNELU::EventServer);
00126 }
00127 
00128 
00129 void                    CNELU::releaseEventServer()
00130 {
00131         CNELU::AsyncListener.removeFromServer(CNELU::EventServer);
00132         if (CNELU::Driver != NULL)
00133         {
00134                 CNELU::EventServer.removeEmitter(CNELU::Driver->getEventEmitter());
00135         }
00136 }
00137 
00138         
00139 void                    CNELU::releaseScene()
00140 {
00141         // Release the camera.
00142         CNELU::Camera= NULL;
00143 
00144         // "Release" the Scene.
00145         CNELU::Scene.setDriver(NULL);
00146         CNELU::Scene.release();
00147 }
00148 
00149 
00150 void                    CNELU::releaseDriver()
00151 {
00152         // "Release" the driver.
00153         if (CNELU::Driver != NULL)
00154         {
00155                 CNELU::Driver->release();
00156                 delete CNELU::Driver;
00157                 CNELU::Driver = NULL;
00158         }
00159         if( CNELU::ShapeBank != NULL )
00160         {
00161                 delete CNELU::ShapeBank;
00162                 CNELU::ShapeBank = NULL;
00163         }
00164 }
00165 
00166 bool                    CNELU::init (uint w, uint h, CViewport viewport, uint bpp, bool windowed, void *systemWindow, bool offscreen) throw(EDru)
00167 {
00168         NL3D::registerSerial3d();
00169         if (initDriver(w,h,bpp,windowed,systemWindow,offscreen))
00170         {
00171                 initScene(viewport);
00172                 initEventServer();
00173                 return true;
00174         }
00175         else
00176                 return false;
00177 }
00178 
00179 void                    CNELU::release()
00180 {
00181         releaseEventServer();
00182         releaseScene();
00183         releaseDriver();
00184 }
00185 
00186 void                    CNELU::screenshot()
00187 {
00188         if (AsyncListener.isKeyPushed(KeyF12))
00189         {
00190                 CBitmap btm;
00191                 CNELU::Driver->getBuffer(btm);
00192                 string filename = CFile::findNewFile ("screenshot.tga");
00193                 COFile fs(filename);
00194                 btm.writeTGA (fs,24,true);
00195                 nlinfo("Screenshot '%s' saved", filename.c_str());
00196         }
00197 }
00198 
00199 
00200 void                    CNELU::clearBuffers(CRGBA col)
00201 {
00202         CNELU::Driver->clear2D(col);
00203         CNELU::Driver->clearZBuffer();
00204 }
00205 
00206 void                    CNELU::swapBuffers()
00207 {
00208         CNELU::Driver->swapBuffers();
00209 }
00210 
00211 
00212 
00213 } // NL3D