コード例 #1
0
ファイル: graphics2_win.cpp プロジェクト: AltroCoin/altrocoin
void boinc_graphics_loop(int argc, char** argv, const char* title) {
    char buf[256];
    if (!diagnostics_is_initialized()) {
        boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS);
    }

    fprintf(stderr,
        "%s Starting graphics application.\n",
        boinc_msg_prefix(buf, sizeof(buf))
    );

    for (int i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--fullscreen")) {
            fullscreen = true;
            fprintf(stderr, "%s fullscreen mode requested.\n",
                boinc_msg_prefix(buf, sizeof(buf))
            );
        }
    }

    // Register the BOINC App window class
    //
    reg_win_class();

    wglMakeCurrent(NULL,NULL); 
    make_window(title);

    // Create a timer thread to do rendering
    //
    gfx_timer_id = SetTimer(NULL, 1, 30, (TIMERPROC)&timer_handler);

    // Process the window message pump
    //
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    // Unregister the BOINC App window class
    unreg_win_class();

    fprintf(stderr, "%s Shutting down graphics application.\n",
        boinc_msg_prefix(buf, sizeof(buf))
    );
}
コード例 #2
0
int main(int argc, char **argv)
{
    // print version info
    if(argc == 2) {
        string param(argv[1]);
        if(param == "--version" || param == "-v") {
            cout << "Version information:" << endl;
            cout << "Graphics Application Revision: " << ERP_GIT_VERSION << endl;
            cout << "BOINC Revision: " << SVN_VERSION << endl;
            exit(0);
        }
    }

    // enable BOINC diagnostics
	// TODO: we might want to optimize this for glibc- and mingw-based stacktraces!
	boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS);

#ifdef __APPLE__
  setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData));
#endif

	// choose application to be build/used
	GraphicsEngineFactory::Applications scienceApplication;
#ifdef SCIENCE_APP
	scienceApplication = GraphicsEngineFactory::SCIENCE_APP;
#else
	scienceApplication = GraphicsEngineFactory::EinsteinS5R3;
#endif

	// prepare main objects
	WindowManager window;
	ResourceFactory factory;
	AbstractGraphicsEngine *graphics = GraphicsEngineFactory::createInstance(
											GraphicsEngineFactory::Starsphere,
											scienceApplication);

	if(!graphics) {
		cerr << "Requested graphics engine could not be found/instantiated!" << endl;
		exit(1);
	}

    // initialize window manager
    if(!window.initialize()) {
    	cerr << "Window manager could not be initialized!" << endl;
    	delete graphics;
        exit(1);
    }

	// create font and icon resource instances
	const Resource *fontResource = factory.createInstance("FontSansSerif");
	const Resource *iconResource = factory.createInstance("AppIconBMP");

	if(fontResource == NULL) {
		cerr << "Font resource could not be loaded!" << endl;
		delete graphics;
		exit(1);
	}

	if(fontResource->data()->size() <= 0) {
		cerr << "Font resource could not be loaded!" << endl;
		delete graphics;
		delete fontResource;
		exit(1);
	}

	if(iconResource != NULL && iconResource->data()->size() > 0) {
		window.setWindowIcon(&iconResource->data()->at(0), iconResource->data()->size());
		delete iconResource;
	}
	else {
		cerr << "Icon resource could not be loaded! Continuing anyway..." << endl;
	}

    window.setWindowCaption("Einstein@Home");

    // register starsphere as event observer
    window.registerEventObserver(graphics);

	// pepare rendering
	graphics->initialize(window.windowWidth(), window.windowHeight(), fontResource);
	graphics->refreshBOINCInformation();

	// check optional command line parameters
	if(argc == 2) {
		string param(argv[1]);
		if(param == "--fullscreen") {
			// set non-interactive mode (must do this first on Apple)
			window.setScreensaverMode(true);
		}
		if(param == "--fullscreen" || param == "--demo") {
			// switch to fullscreen (on windoze: after init!)
			window.toggleFullscreen();
#ifdef __APPLE__
			SetMacSSLevel();
#endif
		}
	}

	// enter main event loop
	window.eventLoop();

	// clean up end exit
	window.unregisterEventObserver(graphics);
	delete graphics;
	delete fontResource;

	exit(0);
}