00001 #include "RenderTools.h"
00002
00003 namespace RenderTools{
00004
00005 bool s_initialized = false;
00006 bool s_initializedGL = false;
00007 StringList s_arguments;
00008 const StringList & getArguments( void ){
00009 return( s_arguments );
00010 }
00011
00078 void initialize( int argc, char ** argv ){
00079 StringList arguments;
00080 for( int i = 0; i < argc; i++ ){
00081 arguments.push_back( string( argv[ i ] ) );
00082 }
00083 initialize( arguments );
00084 }
00085
00086 void initialize( const StringList & arguments ){
00087 if( s_initialized ){
00088 return;
00089 }
00090
00091 s_arguments = arguments;
00092
00093 string rootDir;
00094 string appName;
00095
00096 for( unsigned int i = 0; i < s_arguments.size(); i++ ){
00097 string arg( s_arguments[ i ] );
00099 if( ( ( ! i ) && ( arg[ 0 ] == '/' || arg[ 1 ] == ':' ) ) && basename( arg, rootDir, appName ) ){
00103 #ifdef WIN32
00105 size_t offset = appName.find_last_of( '.' );
00106 if( offset != string::npos ){
00107 appName.erase( offset, appName.size() - offset );
00108 }
00109 #endif
00110 }
00111 else{
00113 for( string::iterator it = arg.begin(); it != arg.begin(); it++ ) {
00115 *it = tolower( *it );
00116 }
00117
00118 if( arg == "-rootdir" || arg == "-root_dir" || arg == "-root" ){
00120 rootDir = s_arguments[ i + 1 ];
00121 }
00122 else if( arg == "-appname" || arg == "-app_name" || arg == "-app" || arg == "-name" ){
00124 appName = s_arguments[ i + 1 ];
00125 }
00126 }
00127 }
00128
00130 if( rootDir.size() ){
00131 if( rootDir[ rootDir.size() - 1 ] != '/' ){
00132 rootDir += "/";
00133 }
00134 }
00135
00137 char cwdChars[256];
00138 if( ! getCWD( cwdChars, sizeof( cwdChars ) ) ){
00139 Error::error( Error::NULL_POINTER, __FILE__, __LINE__, "current working directory not found" );
00140 }
00142 string cwdString( cwdChars );
00143 cwdString += "/";
00144
00145 addSearchRoot( "./" );
00146 addSearchRoot( "./rsrc" );
00147 addSearchRoot( rootDir );
00148 addSearchRoot( cwdString );
00149 addSearchRoot( rootDir + appName );
00150 addSearchRoot( cwdString + appName );
00151 addSearchRoot( rootDir + "/rsrc" );
00152 addSearchRoot( cwdString + "/rsrc" );
00153 addSearchRoot( rootDir + appName + "/rsrc" );
00154 addSearchRoot( cwdString + appName + "/rsrc" );
00155 #ifdef __APPLE__
00156 addSearchDir( "Contents" );
00157 addSearchDir( "Contents/MacOS" );
00158 addSearchDir( "Documents" );
00159 #endif
00160 addSearchDir( "fonts" );
00161 addSearchDir( "rendergroups" );
00162 addSearchDir( "textures" );
00163 addSearchDir( "shaders" );
00164
00166 Factory::registerClass( "Application", Application::create );
00167 Factory::registerClass( "Camera", Camera::create );
00168 Factory::registerClass( "Image", Image::create );
00169 Factory::registerClass( "RelationalNode", RelationalNode::create );
00170 Factory::registerClass( "Circle", Circle::create );
00171 Factory::registerClass( "Plane", Plane::create );
00172 Factory::registerClass( "Curve", AbstractCurve::create );
00173 Factory::registerClass( "Rendergroup", Rendergroup::create );
00174 Factory::registerClass( "Rendernode", Rendernode::create );
00175 Factory::registerClass( "Renderpass", Renderpass::create );
00176 Factory::registerClass( "Sampler", Sampler::create );
00177 Factory::registerClass( "Stateset", Stateset::create );
00178 Factory::registerClass( "Ellipsoid", Ellipsoid::create );
00179 Factory::registerClass( "TextNode", TextNode::create );
00180 Factory::registerClass( "Vertexbuffer", Vertexbuffer::create );
00181 Factory::registerClass( "PhysicsWorld", PhysicsWorld::create );
00182 Factory::registerClass( "Renderbuffer", Renderbuffer::create );
00183 Factory::registerClass( "Framebuffer", Framebuffer::create );
00184 Factory::registerClass( "RendergroupGLView", RendergroupGLView::create );
00185
00186 #ifndef RT_AS3
00187 # ifndef RT_GLES1
00189 Factory::registerClass( "Program", Program::create );
00190 # endif
00191 #endif
00193 PhysicsWorld::initialize();
00194
00196 Matrix::initialize();
00197
00198 #ifdef RT_DEVIL
00200 ilInit();
00201 #endif
00202
00203 #ifdef RT_GLUT
00205 int argc = ( int )s_arguments.size();
00206 char ** argv = ( char ** )malloc( argc * sizeof( char * ) );
00207 for( unsigned int i = 0; i < s_arguments.size(); i++ ){
00208 argv[ i ] = const_cast< char * >( s_arguments[ i ].c_str() );
00209 }
00210 glutInit( & argc, argv );
00211 free( argv );
00212 #endif
00213
00214 s_initialized = true;
00215 }
00216
00217 void initializeGL( void ){
00218 if( s_initializedGL ){
00219 return;
00220 }
00221 #ifdef RT_GLEW
00222 if( glewInit() != GLEW_OK ){
00223 Error::error( Error::GLEW_INITIALIZATION_FAILED, __FILE__, __LINE__ );
00224 }
00225 #endif
00226 s_initializedGL = true;
00227 }
00228
00229 bool isInitialized( void ){
00230 return( s_initialized );
00231 }
00232
00233 bool isGLInitialized( void ){
00234 return( s_initializedGL );
00235 }
00236
00237 };
00238
00239
00240