Example #1
0
int main(int argc, char *argv[])
{
    AllocConsole();
    freopen("CONOUT$", "w+t", stdout);

    QApplication a(argc, argv);
    ModelViewer w;
    w.show();
    return a.exec();
}
Example #2
0
void ModelViewer::Run(const std::string &modelName)
{
	ScopedPtr<GameConfig> config(new GameConfig);

	Graphics::Renderer *renderer;
	ModelViewer *viewer;

	//init components
	FileSystem::Init();
	FileSystem::userFiles.MakeDirectory(""); // ensure the config directory exists
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
		OS::Error("SDL initialization failed: %s\n", SDL_GetError());
	Lua::Init();

	// needed for the UI
	SDL_EnableUNICODE(1);

	//video
	Graphics::Settings videoSettings = {};
	videoSettings.width = config->Int("ScrWidth");
	videoSettings.height = config->Int("ScrHeight");
	videoSettings.fullscreen = (config->Int("StartFullscreen") != 0);
	videoSettings.shaders = (config->Int("DisableShaders") == 0);
	videoSettings.requestedSamples = config->Int("AntiAliasingMode");
	videoSettings.vsync = (config->Int("VSync") != 0);
	videoSettings.useTextureCompression = (config->Int("UseTextureCompression") != 0);
	renderer = Graphics::Init(videoSettings);

	OS::LoadWindowIcon();
	SDL_WM_SetCaption("Model viewer","Model viewer");

	//run main loop until quit
	viewer = new ModelViewer(renderer, Lua::manager);
	viewer->SetModel(modelName);
	viewer->MainLoop();

	//uninit components
	delete viewer;
	Lua::Uninit();
	delete renderer;
	Graphics::Uninit();
	FileSystem::Uninit();
	SDL_Quit();
}
int main(int argc, char** argv)
{
    GLUTBackendInit(argc, argv);

    if (!GLUTBackendCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 32, false, "Model Viewer")) {
        return 1;
    }
    
    ModelViewer* app = new ModelViewer();

    if (!app->init()) {
        return 1;
    }
    srand((unsigned)time(NULL));
    
    app->run();
    delete app;
    return 0;
}
Example #4
0
int main(int argc, char* argv[])
{

    Igor::startup();

    ModelViewer* example = new ModelViewer();
    if (argc >= 2)
    {
        example->run(argv[1]);
    }
    else
    {
        example->run("");
    }

    delete example;

    Igor::shutdown();

	return 0;
}
Example #5
0
    void main(int argc, const char *argv[]) 
    {
      // init ospray
      ospInit(&argc,argv);
      // init qt
      QApplication *app = new QApplication(argc, (char **)argv);
      
      Ref<sg::World> world = new sg::World;
      Ref<sg::Renderer> renderer = new sg::Renderer;
      bool fullscreen = false;

      for (int argID=1;argID<argc;argID++) {
        const std::string arg = argv[argID];
        if (arg[0] == '-') {
          if (arg == "-o" || arg == "--render-to-file") {
            outFileName = argv[++argID];
          } else if (arg == "--size") {
            frameResolution.x = atoi(argv[++argID]);
            frameResolution.y = atoi(argv[++argID]);
          } else if (arg == "-spp" || arg == "--spp" || arg == "--samples-per-pixel") {
            spp = atoi(argv[++argID]);
          } else if (arg == "--data-distributed" || arg == "--data-parallel") {
            sg::Volume::useDataDistributedVolume = true;
          } else if (arg == "--1k" || arg == "-1k") {
            frameResolution.x = 1024;
            frameResolution.y = 1024;
          } else if (arg == "--test-sphere") {
            world = sg::createTestSphere();
          } else if (arg == "--show-fps" || arg == "-fps" || arg == "--fps") {
            showFPS = true;
          } else if (arg == "--module") {
            sg::loadModule(argv[++argID]);
          } else if (arg == "--renderer") {
            integratorFromCommandLine = argv[++argID];
          } else if (arg == "-vi") {
            if (!cameraFromCommandLine) cameraFromCommandLine = new sg::PerspectiveCamera;
            assert(argID+3<argc);
            float x = atof(argv[++argID]);
            float y = atof(argv[++argID]);
            float z = atof(argv[++argID]);
            cameraFromCommandLine->setAt(vec3f(x,y,z));
          } else if (arg == "-vp") {
            if (!cameraFromCommandLine) cameraFromCommandLine = new sg::PerspectiveCamera;
            assert(argID+3<argc);
            float x = atof(argv[++argID]);
            float y = atof(argv[++argID]);
            float z = atof(argv[++argID]);
            cameraFromCommandLine->setFrom(vec3f(x,y,z));
          } else if (arg == "-vu") {
            assert(argID+3<argc);
            float x = atof(argv[++argID]);
            float y = atof(argv[++argID]);
            float z = atof(argv[++argID]);
            upFromCommandLine = vec3f(x,y,z);
            if (cameraFromCommandLine) cameraFromCommandLine->setUp(vec3f(x,y,z));
          } else if (arg == "--fullscreen" || arg == "-fs"){
            fullscreen = true;
          } else {
            throw std::runtime_error("#osp:qtv: unknown cmdline param '"+arg+"'");
          }
        } else {
          FileName fn = arg;
          if (fn.ext() == "osp" || fn.ext() == "pkd") {
            world = sg::loadOSP(fn.str());
            // } else if (fn.ext() == "atom") {
            //   world = sg::AlphaSpheres::importOspAtomFile(fn.str());
          } else if ((fn.ext() == "ply") || 
                     ((fn.ext() == "gz") && (fn.dropExt().ext() == "ply"))) {
            sg::importPLY(world,fn);
          } else if (fn.ext() == "obj") {
            sg::importOBJ(world,fn);
            // } else if (fn.ext() == "x3d") {
            //   sg::importX3D(world,fn);
          } else if (fn.ext() == "xml") {
            std::cout << "#osp:qtv: reading RIVL file " << arg << std::endl;
            world = sg::importRIVL(arg);
          } else 
            sg::importFile(world,fn);
            
          // throw std::runtime_error("unsupported file format in '"+fn.str()+"'");
          // std::cout << "#osp:qtv: reading RIVL file " << arg << std::endl;
          //world = sg::importRIVL(arg);
        }
      }

      if (!world) {
        std::cout << "#osp:qtv: no world defined. exiting." << std::endl;
        exit(1);
      }
      // set the current world ...
      std::cout << "#osp:qtv: setting world ..." << std::endl;
      renderer->setWorld(world);

      // -------------------------------------------------------
      // initialize renderer's integrator
      // -------------------------------------------------------
      {
        // first, check if one is specified in the scene file.
        Ref<sg::Integrator> integrator = renderer->getLastDefinedIntegrator();
        if (!integrator) {
          std::string integratorName = integratorFromCommandLine;
          if (integratorName == "")
            integratorName = DEFAULT_INTEGRATOR_NAME;
          integrator = new sg::Integrator(integratorName);
        }
        renderer->setIntegrator(integrator);
        integrator->setSPP(spp);
        integrator->commit();
      }

      // -------------------------------------------------------
      // initialize renderer's camera
      // -------------------------------------------------------
      {
        // activate the last camera defined in the scene graph (if set)
        if (cameraFromCommandLine) {
          renderer->setCamera(cameraFromCommandLine.cast<sg::Camera>());
        } else {
          renderer->setCamera(renderer->getLastDefinedCamera());
        }
        if (!renderer->camera) {
          renderer->setCamera(renderer->createDefaultCamera(upFromCommandLine));
        }
      }

      // -------------------------------------------------------
      // determine output method: offline to file, or interactive viewer
      // -------------------------------------------------------
      if (outFileName == "") {
        // create new modelviewer
        cout << "#osp:qtv: setting up to open QT viewer window" << endl;
        ModelViewer *modelViewer = new ModelViewer(renderer, fullscreen);
        // modelViewer->setFixedSize(frameResolution.x,frameResolution.y);
        modelViewer->showFrameRate(showFPS);
        std::cout << "#osp:qtv: Press 'f' to toggle fullscreen rendering mode" << endl;
        if (fullscreen){
          std::cout << "#osp:qtv: opening fullscreen viewer, press 'ESC' to quit" << endl;
          modelViewer->showFullScreen();
        } else {
          modelViewer->show();
        }

        if (frameResolution.x > 0) {
          cout << "#osp:qtv: trying to set render size to " << frameResolution.x << "x" << frameResolution.y << " pixels" << endl;
          
          float frame_width  = modelViewer->width() - modelViewer->renderWidget->width();
          float frame_height = modelViewer->height() - modelViewer->renderWidget->height();
          modelViewer->resize(frameResolution.x+frame_width,
                              frameResolution.y+frame_height);
          cout << "#osp:qtv: now rendering at " << modelViewer->renderWidget->width()
               << "x" << modelViewer->renderWidget->height() << " pixels." << endl;
        }

        // let qt run...
        app->exec();
        
        // done, closing down.
        delete modelViewer;
        delete app;
      } else {
        cout << "#osp:qtv: setting up in render-to-file mode" << endl;
        if (frameResolution == vec2i(-1, -1)) {
          cout << "#osp:qtv: Warning! no resolution specified, defaulting to 1280x720" << endl;
          frameResolution = vec2i(1280, 720);
        }
        if (!renderer->frameBuffer) {
          cout << "#osp:qtv: creating default framebuffer (" 
               << frameResolution.x << "x" << frameResolution.y << ")" << endl;
          renderer->frameBuffer = new sg::FrameBuffer(frameResolution);
        }
        renderer->frameBuffer->commit(); 
        renderer->frameBuffer->clear();

        // output file specified - render to file
        cout << "#osp:qtv: rendering frame" << endl;
        renderer->renderFrame();

        unsigned char *fbMem = renderer->frameBuffer->map();
        cout << "#osp:qtv: saving image" << endl;
        // PRINT((int*)fbMem);
        // PRINT(*(int**)fbMem);
        QImage image = QImage(fbMem,
                              renderer->frameBuffer->getSize().x,
                              renderer->frameBuffer->getSize().y,
                              QImage::Format_ARGB32).rgbSwapped().mirrored();
        // QImage fb = QImage(fbMem,size.x,size.y,QImage::Format_RGB32).rgbSwapped().mirrored();
        image.save(outFileName.c_str());
        renderer->frameBuffer->unmap(fbMem);
        cout << "#osp:qtv: rendered image saved to " << outFileName << endl;
        cout << "#osp:qtv: done... exiting." << endl;
        exit(0);
      }
    }
Example #6
0
File: rboot.cpp Project: skopp/rush
bool RBoot::Init( const CommandLine& cmd )
{
    import( rb_core         );

    JCore* m_pCore = new JCore();
    m_pCore->SetName( "core" );

    if (m_pCore != JCore::s_pInstance)
    {
        return false;
    }

    uint32_t hwnd = 0;
    const char* pHandle = cmd.GetValue( "window" );
    if (pHandle)
    {
        sscanf( pHandle, "%d", &hwnd );
    }

    import( rb_draw         );
    //import( rb_extui        );
    import( rb_particle     );
    ImportRenderLib();
    import( rb_scene        );
    import( rb_script_lua   );
    //import( rb_sound        );
    //import( rb_texture      );
    import( rb_ui           );
    //import( rb_video        );
    //import( rb_physics      );

    link_class( ModelViewer );
    link_class( TestDriver  );

    m_pCore->Init();

    AddCommonMediaPath();

    const char* scriptFile = cmd.GetValue( "script" );
    JObject* pRoot = NULL;
    if (scriptFile)
    {
        //  find script's media directory and add it
        AddScriptMediaPath( scriptFile );
        //  load script
        pRoot = g_pPersistServer->LoadObject( scriptFile );
    }
    else
    {
        AddModuleMediaPath();
    }

    const char* mediaDir = cmd.GetValue( "media" );
    g_pFileServer->AddMediaPath( mediaDir );

    m_pCore->AddServer( "animserver"      );
    m_pCore->AddServer( "stringserver"    );
    m_pCore->AddServer( "windowserver"    );
    m_pCore->AddServer( c_RenderServerName );
    m_pCore->AddServer( "drawserver"      );
    m_pCore->AddServer( "modelserver"     );
    m_pCore->AddServer( "particleserver"  );
    m_pCore->AddServer( "luaserver"       );
    m_pCore->AddServer( "soundserver"     );
    m_pCore->AddServer( "physicsserver"   );
    m_pCore->AddServer( "videoserver"     );

    g_pWindowServer->SetRootHandle( reinterpret_cast<void*>( hwnd ) );

    m_pCore->InitTree();

    if (!pRoot)
    {
        pRoot = g_pPersistServer->LoadObject( "rboot" );
    }
    if (!pRoot)
    {
        return false;
    }

    JString objPath;
    pRoot->GetPath( objPath );
    m_pCore->SetRootObject( objPath.c_str() );

    g_pWindowServer->AddWindow( pRoot );
    pRoot->InitTree();

    ModelViewer* pModelViewer = obj_cast<ModelViewer>( pRoot );
    Path animPath, modelPath;
    if (pModelViewer)
    {
        pModelViewer->SetAnim( cmd.GetValue( "anim" ) );
        pModelViewer->SetModel( cmd.GetValue( "model" ) );
    }

    JDialog* pRootDlg = obj_cast<JDialog>( pRoot );
    if (pRootDlg)
    {
        pRootDlg->Show();
    }

    return true;
}