document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. -------------------------------------------------------------------------------
  3.     This file is part of OgreKit.
  4.     http://gamekit.googlecode.com/
  5.  
  6.     Copyright (c) 2006-2010 Charlie C.
  7.  
  8.     Contributor(s): silveira.nestor, xavier.thomas.1980.
  9. -------------------------------------------------------------------------------
  10.   This software is provided \'as-is\', without any express or implied
  11.   warranty. In no event will the authors be held liable for any damages
  12.   arising from the use of this software.
  13.  
  14.   Permission is granted to anyone to use this software for any purpose,
  15.   including commercial applications, and to alter it and redistribute it
  16.   freely, subject to the following restrictions:
  17.  
  18.   1. The origin of this software must not be misrepresented; you must not
  19.      claim that you wrote the original software. If you use this software
  20.      in a product, an acknowledgment in the product documentation would be
  21.      appreciated but is not required.
  22.   2. Altered source versions must be plainly marked as such, and must not be
  23.      misrepresented as being the original software.
  24.   3. This notice may not be removed or altered from any source distribution.
  25. -------------------------------------------------------------------------------
  26. */
  27. #include "tclap/CmdLine.h"
  28. #include "OgreKit.h"
  29.  
  30.  
  31.  
  32. const gkString gkDefaultBlend   = "momo_ogre.blend";
  33. const gkString gkDefaultConfig  = "OgreKitStartup.cfg";
  34.  
  35.  
  36.  
  37. class OgreKit : public gkCoreApplication, public gkWindowSystem::Listener
  38. {
  39. public:
  40.     gkString    m_blend;
  41.     gkScene*    m_scene;
  42. public:
  43.     OgreKit();
  44.     virtual ~OgreKit() {}
  45.  
  46.     int setup(int argc, char** argv);
  47.  
  48.     void keyReleased(const gkKeyboard& key, const gkScanCode& sc);
  49. private:
  50.  
  51.     bool setup(void);
  52. };
  53.  
  54.  
  55.  
  56. OgreKit::OgreKit()
  57.     :   m_blend(gkDefaultBlend), m_scene(0)
  58. {
  59. }
  60.  
  61.  
  62. int OgreKit::setup(int argc, char** argv)
  63. {
  64.     int winsize_x       = 800;
  65.     int winsize_y       = 600;
  66.     m_prefs.wintitle    = gkString("OgreKit Demo (Press Escape to exit)[") + m_blend + gkString("]");
  67.  
  68.  
  69.     gkString cfgfname;
  70.  
  71.     // Parse command line
  72.     try
  73.     {
  74.         TCLAP::CmdLine cmdl("Ogrekit", \' \', "n/a");
  75.         cmdl.setExceptionHandling(false);
  76.  
  77.         //cfg arguments
  78.  
  79.         TCLAP::ValueArg<std::string>    rendersystem_arg        ("r", "rendersystem",           "Set rendering system. (gl, d3d9, d3d10, d3d11)", false, "", "string"); //default GL
  80.         TCLAP::ValueArg<std::string>    viewportOrientation_arg ("",  "viewportorientation",    "Set viewport orientation.", false, m_prefs.viewportOrientation, "string");
  81.         TCLAP::ValueArg<std::string>    log_arg                 ("",  "log",                    "Set log file name.", false, m_prefs.log, "string");
  82.         TCLAP::ValueArg<bool>           verbose_arg             ("v", "verbose",                "Enable verbose log.", false, m_prefs.verbose, "bool");
  83.         TCLAP::ValueArg<int>            winsize_x_arg           ("",  "width",                  "Set window width.", false, winsize_x, "int");
  84.         TCLAP::ValueArg<int>            winsize_y_arg           ("",  "height",                 "Set window height.", false, winsize_y, "int");
  85.         TCLAP::ValueArg<std::string>    wintitle_arg            ("",  "wintitle",               "Set window title.", false, m_prefs.wintitle, "string");
  86.         TCLAP::ValueArg<bool>           fullscreen_arg          ("f", "fullscreen",             "Enable fullscreen mode.", false, m_prefs.fullscreen, "bool");
  87.         TCLAP::ValueArg<std::string>    framingType_arg         ("",  "framingtype",            "Set viewport framing type. (extend, crop, letterbox)", false, "", "string");
  88.         TCLAP::ValueArg<std::string>    resources_arg           ("",  "resources",              "Set resouces.", false, m_prefs.resources, "string");
  89.         TCLAP::ValueArg<bool>           blendermat_arg          ("",  "blendmat",               "Convert meshes using blender materials.", false, m_prefs.blendermat, "bool");
  90.         TCLAP::ValueArg<bool>           matblending_arg         ("",  "matblending",            "Enable material pass blending mode.", false, m_prefs.matblending, "bool");    
  91.         TCLAP::ValueArg<bool>           grapInput_arg           ("g", "grabinput",              "Grap mouse input.", false, m_prefs.grabInput, "bool");
  92.         TCLAP::ValueArg<bool>           debugFps_arg            ("d", "debugfps",               "Display debug fps.", false, m_prefs.debugFps, "bool");
  93.         TCLAP::ValueArg<bool>           debugPhysics_arg        ("p", "debugphysics",           "Display debug physics.", false, m_prefs.debugPhysics, "bool");
  94.         TCLAP::ValueArg<bool>           debugPhysicsAabb_arg    ("a", "debugphysicsaabb",       "Display debug physics aabb.", false, m_prefs.debugPhysicsAabb, "bool");
  95.         TCLAP::ValueArg<bool>           buildStaticGeometry_arg ("",  "buildinstances",         "Build Static Geometry.", false, m_prefs.buildStaticGeometry, "bool");
  96.         TCLAP::ValueArg<bool>           useBulletDbvt_arg       ("",  "frustumculling",         "Enable view frustum culling by dbvt.", false, m_prefs.useBulletDbvt, "bool");
  97.         TCLAP::ValueArg<bool>           showDebugProps_arg      ("t", "showdebugprops",         "Show debug props.", false, m_prefs.showDebugProps, "bool");
  98.         TCLAP::ValueArg<bool>           debugSounds_arg         ("",  "debugsounds",            "Debug sounds.", false, m_prefs.debugSounds, "bool");
  99.         TCLAP::ValueArg<bool>           disableSound_arg        ("s", "disablesound",           "Disable sounds.", false, m_prefs.disableSound, "bool");
  100.         TCLAP::ValueArg<bool>           fsaa_arg                ("",  "fsaa",                   "Enable fsaa.", false, m_prefs.fsaa, "bool");
  101.         TCLAP::ValueArg<int>            fsaaSamples_arg         ("",  "fsaasSamples",           "Set fsaa samples.", false, m_prefs.fsaaSamples, "int");
  102.         TCLAP::ValueArg<bool>           enableshadows_arg       ("",  "enableshadows",          "Enable Shadows.", false, m_prefs.enableshadows, "bool");
  103.         TCLAP::ValueArg<int>            defaultMipMap_arg       ("",  "defaultmipmap",          "Set default mipMap.", false, m_prefs.defaultMipMap, "int");
  104.         TCLAP::ValueArg<std::string>    shadowtechnique_arg     ("",  "shadowtechnique",        "Set shadow technique.", false, m_prefs.shadowtechnique, "string");
  105.         TCLAP::ValueArg<std::string>    colourshadow_arg        ("",  "colourshadow",           "Set shadow colour.", false, "", "string");
  106.         TCLAP::ValueArg<float>          fardistanceshadow_arg   ("",  "fardistanceshadow",      "Set far distance shadow.", false, m_prefs.fardistanceshadow, "float");
  107.         TCLAP::ValueArg<std::string>    shaderCachePath_arg     ("",  "shadercachepath",        "RTShaderSystem cache file path.", false, m_prefs.shaderCachePath, "string");
  108.        
  109.  
  110.         cmdl.add(rendersystem_arg);
  111.         cmdl.add(viewportOrientation_arg);
  112.         cmdl.add(log_arg);
  113.         cmdl.add(verbose_arg);
  114.         cmdl.add(winsize_x_arg);
  115.         cmdl.add(winsize_y_arg);
  116.         cmdl.add(wintitle_arg);
  117.         cmdl.add(fullscreen_arg);
  118.         cmdl.add(framingType_arg);
  119.         cmdl.add(resources_arg);
  120.         cmdl.add(blendermat_arg);
  121.         cmdl.add(matblending_arg);
  122.         cmdl.add(grapInput_arg);
  123.         cmdl.add(debugFps_arg);
  124.         cmdl.add(debugPhysics_arg);
  125.         cmdl.add(debugPhysicsAabb_arg);
  126.         cmdl.add(buildStaticGeometry_arg);
  127.         cmdl.add(useBulletDbvt_arg);
  128.         cmdl.add(showDebugProps_arg);
  129.         cmdl.add(debugSounds_arg);
  130.         cmdl.add(disableSound_arg);
  131.         cmdl.add(fsaa_arg);
  132.         cmdl.add(fsaaSamples_arg);
  133.         cmdl.add(enableshadows_arg);
  134.         cmdl.add(defaultMipMap_arg);
  135.         cmdl.add(shadowtechnique_arg);
  136.         cmdl.add(colourshadow_arg);
  137.         cmdl.add(fardistanceshadow_arg);
  138.         cmdl.add(shaderCachePath_arg);
  139.  
  140.         //input file arguments
  141.        
  142.         TCLAP::ValueArg<std::string>            cfgfname_arg("c", "config-file", "Startup configuration file (.cfg) to use.", false, gkDefaultConfig, "string");
  143.         TCLAP::UnlabeledValueArg<std::string>   bfname_arg("blender-file", "Blender file to launch as game.", false, gkDefaultBlend, "string");
  144.  
  145.         cmdl.add(cfgfname_arg);
  146.         cmdl.add(bfname_arg);
  147.  
  148.         cmdl.parse( argc, argv );
  149.  
  150.         cfgfname                        = cfgfname_arg.getValue();
  151.         m_blend                         = bfname_arg.getValue();
  152.  
  153.         m_prefs.rendersystem            = gkUserDefs::getOgreRenderSystem(rendersystem_arg.getValue());
  154.         m_prefs.viewportOrientation     = viewportOrientation_arg.getValue();
  155.         //m_prefs.sceneManager          = sceneManager_arg.getValue();
  156.         m_prefs.log                     = log_arg.getValue();
  157.         m_prefs.verbose                 = verbose_arg.getValue();
  158.  
  159.         m_prefs.winsize                 = gkVector2(winsize_x_arg.getValue(), winsize_y_arg.getValue());
  160.         m_prefs.wintitle                = wintitle_arg.getValue();
  161.  
  162.         m_prefs.fullscreen              = fullscreen_arg.getValue();
  163.         m_prefs.framingType             = gkUserDefs::getViewportFramingType(framingType_arg.getValue());
  164.         m_prefs.resources               = resources_arg.getValue();
  165.         m_prefs.blendermat              = blendermat_arg.getValue();
  166.         m_prefs.matblending             = matblending_arg.getValue();
  167.         m_prefs.grabInput               = grapInput_arg.getValue();
  168.         m_prefs.debugFps                = debugFps_arg.getValue();
  169.         m_prefs.debugPhysics            = debugPhysics_arg.getValue();
  170.         m_prefs.debugPhysicsAabb        = debugPhysicsAabb_arg.getValue();
  171.         m_prefs.buildStaticGeometry     = buildStaticGeometry_arg.getValue();
  172.         m_prefs.useBulletDbvt           = useBulletDbvt_arg.getValue();
  173.         m_prefs.showDebugProps          = showDebugProps_arg.getValue();
  174.         m_prefs.debugSounds             = debugSounds_arg.getValue();
  175.         m_prefs.disableSound            = disableSound_arg.getValue();
  176.  
  177.         m_prefs.fsaa                    = fsaa_arg.getValue();
  178.         m_prefs.fsaaSamples             = fsaaSamples_arg.getValue();
  179.         m_prefs.enableshadows           = enableshadows_arg.getValue();
  180.         m_prefs.defaultMipMap           = defaultMipMap_arg.getValue();
  181.         m_prefs.shadowtechnique         = shadowtechnique_arg.getValue();
  182.         m_prefs.fardistanceshadow       = fardistanceshadow_arg.getValue();
  183.         m_prefs.shaderCachePath         = shaderCachePath_arg.getValue();
  184.  
  185.         if (colourshadow_arg.isSet())
  186.             m_prefs.colourshadow        = Ogre::StringConverter::parseColourValue(colourshadow_arg.getValue());
  187.  
  188. #ifdef __APPLE__
  189.         if (m_blend.find("-psn") != gkString::npos)
  190.             m_blend = gkDefaultBlend;
  191. #endif
  192.  
  193.     }
  194.     catch (TCLAP::ArgException& e)
  195.     {
  196.         std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
  197.         return -1;
  198.     }
  199.     catch (TCLAP::ExitException&)
  200.     {
  201.         // just return and exit app
  202.         return -1;
  203.     }
  204.     catch (...)
  205.     {
  206.         std::cerr << "Unknown exception." << std::endl;
  207.         return -1;
  208.     }
  209.  
  210.  
  211.  
  212.     gkPath path = cfgfname;
  213.  
  214.     // overide settings if found
  215.     if (path.isFile())
  216.         m_prefs.load(path.getPath());
  217.  
  218.     return 0;
  219. }
  220.  
  221.  
  222. bool OgreKit::setup(void)
  223. {
  224.     gkBlendFile* blend = gkBlendLoader::getSingleton().loadFile(gkUtils::getFile(m_blend), gkBlendLoader::LO_ALL_SCENES);
  225.     if (!blend)
  226.     {
  227.         gkPrintf("File loading failed.\\n");
  228.         return false;
  229.     }
  230.  
  231.     //gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_POSTERIZE);
  232.  
  233.     m_scene = blend->getMainScene();
  234.     if (!m_scene)
  235.     {
  236.         gkPrintf("No usable scenes found in blend.\\n");
  237.         return false;
  238.     }
  239.  
  240.  
  241.     m_scene->createInstance();
  242.  
  243.     // add input hooks
  244.     gkWindowSystem::getSingleton().addListener(this);
  245.  
  246. #ifdef OGREKIT_USE_COMPOSITOR
  247.     //gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_BLOOM);
  248. #endif
  249.  
  250.     return true;
  251. }
  252.  
  253. int compositorNum = 0;
  254. int oldCompositorNum = 0;
  255.  
  256. void OgreKit::keyReleased(const gkKeyboard& key, const gkScanCode& sc)
  257. {
  258.     if (sc == KC_ESCKEY)
  259.         m_engine->requestExit();
  260.  
  261.     if (sc == KC_PKEY)
  262.     {
  263.         gkEngine::getSingleton().saveTimestampedScreenShot("gkEngine_shoot_","jpg");
  264.     }
  265.  
  266.     if (sc == KC_QKEY)
  267.     {
  268.         oldCompositorNum = compositorNum;
  269.         compositorNum++;
  270.         if (compositorNum>14) compositorNum = 0;
  271.  
  272.         if (compositorNum==1) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_BLOOM);
  273.         if (compositorNum==2) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_BW);
  274.         if (compositorNum==3) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_EMBOSSED);
  275.         if (compositorNum==4) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_SHARPEN_EDGES);
  276.         if (compositorNum==5) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_INVERT);
  277.         if (compositorNum==6) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_POSTERIZE);
  278.         if (compositorNum==7) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_LAPLACE);
  279.         if (compositorNum==8) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_TILING);
  280.         //if (compositorNum==9) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_HDR);
  281.         //if (compositorNum==10) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_GAUSSIAN_BLUR);
  282.         if (compositorNum==11) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_RADIAL_BLUR);
  283.         //if (compositorNum==12) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_HALFTONE);
  284.         if (compositorNum==13) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_DITHER);
  285.         if (compositorNum==14) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_GLASS);
  286.  
  287.         if (oldCompositorNum==1) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_BLOOM);
  288.         if (oldCompositorNum==2) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_BW);
  289.         if (oldCompositorNum==3) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_EMBOSSED);
  290.         if (oldCompositorNum==4) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_SHARPEN_EDGES);
  291.         if (oldCompositorNum==5) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_INVERT);
  292.         if (oldCompositorNum==6) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_POSTERIZE);
  293.         if (oldCompositorNum==7) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_LAPLACE);
  294.         if (oldCompositorNum==8) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_TILING);
  295.         //if (oldCompositorNum==9) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_HDR);
  296.         //if (oldCompositorNum==10) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_GAUSSIAN_BLUR);
  297.         if (oldCompositorNum==11) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_RADIAL_BLUR);
  298.         //if (oldCompositorNum==12) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_HALFTONE);
  299.         if (oldCompositorNum==13) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_DITHER);
  300.         if (oldCompositorNum==14) gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_GLASS);
  301.  
  302.         switch(compositorNum)
  303.         {
  304.             case 1: printf("GK_COMPOSITOR_BLOOM\\n"); break;
  305.             case 2: printf("GK_COMPOSITOR_BW\\n"); break;
  306.             case 3: printf("GK_COMPOSITOR_EMBOSSED\\n"); break;
  307.             case 4: printf("GK_COMPOSITOR_SHARPEN_EDGES\\n"); break;
  308.             case 5: printf("GK_COMPOSITOR_INVERT\\n"); break;
  309.             case 6: printf("GK_COMPOSITOR_POSTERIZE\\n"); break;
  310.             case 7: printf("GK_COMPOSITOR_LAPLACE\\n"); break;
  311.             case 8: printf("GK_COMPOSITOR_TILING\\n"); break;
  312.             case 9: printf("-GK_COMPOSITOR_HDR\\n"); break;
  313.             case 10: printf("-GK_COMPOSITOR_GAUSSIAN_BLUR\\n"); break;
  314.             case 11: printf("GK_COMPOSITOR_RADIAL_BLUR\\n"); break;
  315.             case 12: printf("-GK_COMPOSITOR_HALFTONE\\n"); break;
  316.             case 13: printf("GK_COMPOSITOR_DITHER\\n"); break;
  317.             case 14: printf("GK_COMPOSITOR_GLASS\\n"); break;
  318.             case 0: printf("none\\n"); break;
  319.         }
  320.     }
  321.  
  322.  
  323.     /*
  324.     if (sc == KC_WKEY)
  325.         {
  326.             w != w;
  327.             if (w)
  328.                 gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_BW);
  329.             else
  330.                 gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_BW);
  331.         }
  332.  
  333.     if (sc == KC_WKEY)
  334.         {
  335.             w != w;
  336.             if (w)
  337.                 gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_ADD, GK_COMPOSITOR_BW);
  338.             else
  339.                 gkCompositorManager::getSingleton().setCompositorChain(GK_COMPOSITOR_OP_DEL, GK_COMPOSITOR_BW);
  340.         }
  341.     */
  342. }
  343.  
  344. int main(int argc, char** argv)
  345. {
  346.  
  347.     TestMemory;
  348.  
  349.     OgreKit okit;
  350.     if (okit.setup(argc, argv) != 0)
  351.     {
  352.         // error
  353.         return -1;
  354.     }
  355.  
  356.     // Launch runtime
  357.     okit.run();
  358.     return 0;
  359. }
');