int main() { RayTracer r; r.Initialize(); r.Render(); r.Clean(); return 0; }
int main(int argc, char *argv[]) { // For detecting memory leaks #ifdef _MSVC _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); #endif //// Seed the random number generator //srand( (unsigned int)time( 0 ) ); // Display license std::cout << "RayWatch - A simple cross-platform RayTracer." << std::endl << "Copyright (C) 2008" << std::endl << " Angelo Rohit Joseph Pulikotil," << std::endl << " Francis Xavier Joseph Pulikotil" << std::endl << "This program comes with ABSOLUTELY NO WARRANTY." << std::endl << "This is free software, and you are welcome to redistribute it" << std::endl << "under certain conditions; see <http://www.gnu.org/licenses/>." << std::endl << std::endl; if( argc < 3 ) { std::cout << "Insufficient arguments" << std::endl << std::endl; std::cout << "Syntax (to render a Scene file):" << std::endl << argv[0] << " <input scene filename> <output bitmap filename> [width] [height]" << std::endl << std::endl; std::cout << "Syntax (to generate a sample file): " << std::endl << argv[0] << " --gen:<sample name> <output scene filename>" << std::endl << std::endl; std::cout << "Currently supported samples are CornellBox, Example1, Example2" << std::endl; return -1; } // If we're supposed to generate a sample file if( Utility::String::CaseInsensitiveCompare( std::string( argv[1] ).substr(0, 6), "--gen:" ) == 0 ) { const std::string sampleName = std::string( argv[1] ).substr( 6 ); bool bResult = false; if( Utility::String::CaseInsensitiveCompare( sampleName, "CornellBox" ) == 0 ) { bResult = Examples::CornellBox( argv[2] ); } else if( Utility::String::CaseInsensitiveCompare( sampleName, "Example1" ) == 0 ) { bResult = Examples::Example1( argv[2] ); } else if( Utility::String::CaseInsensitiveCompare( sampleName, "Example2" ) == 0 ) { bResult = Examples::Example2( argv[2] ); } else // We don't have this sample std::cout << "Error: Unknown sample name: " << sampleName << std::endl; if( !bResult ) return -1; std::cout << "Sample '" << sampleName << "' written to file: " << argv[2] << std::endl; return 0; } // Get the required width int width = 500; if( argc > 3 ) { if( !Utility::String::FromString(width, argv[3]) || (width < 1) ) { std::cout << "Error: Invalid integer specified for width: " << argv[3] << std::endl; return -1; } } // Get the required height int height = 500; if( argc > 4 ) { if( !Utility::String::FromString(height, argv[4]) || (height < 1) ) { std::cout << "Error: Invalid integer specified for height: " << argv[4] << std::endl; return -1; } } // Create a Camera Camera camera; camera._position .Set( 0, 0, 0 ); camera._hFov = 45 * (width / (float)height); camera._vFov = 45; // Create an Image Image image; if( !image.Create( width, height ) ) { std::cout << "Error: Failed to create Image of size " << width << "x" << height << std::endl; return -1; } // Open the input scene file std::fstream stream; stream.open( argv[1], std::ios_base::in ); if( !stream.is_open() ) { std::cout << "Error: Failed to open input scene file: " << argv[1] << std::endl; return -1; } // Create a Deserializer for the stream Deserializer d; if( !d.Open( stream ) ) { std::cout << "Error: Failed to read file: " << argv[1] << std::endl; return -1; } // Load the scene from the stream Scene *pScene = d.Deserialize<Scene>( 0 ); if( !pScene ) { std::cout << "Error: Failed to load Scene from file: " << argv[1] << std::endl; return -1; } // Create a RayTracer and ray trace the scene RayTracer rayTracer; std::cout << "RayTracing"; const bool bRTResult = rayTracer.Render( camera, *pScene, image ); std::cout << "Done" << std::endl; // We're done with the scene, delete it SafeDeleteScalar( pScene ); if( !bRTResult ) { std::cout << "Error: Failed while RayTracing the Scene." << std::endl; return -1; } // Save the image to the required output file if( !image.Save( argv[2] ) ) { std::cout << "Error: Failed while saving image to file: " << argv[2] << std::endl; return -1; } return 0; }