Esempio n. 1
0
static void cput_handle_cmd(struct android_app* app, int32_t cmd)
{
    MySample *pSample = (MySample *)app->userData;

	switch (cmd)
    {
    case APP_CMD_SAVE_STATE:
        LOGI("APP_CMD_SAVE_STATE");
        break;
    case APP_CMD_INIT_WINDOW:
        LOGI("APP_CMD_INIT_WINDOW");
        if (!pSample->HasWindow())
        {
            LOGI("Creating window");
            CPUTResult result;

            // window and device parameters
            CPUTWindowCreationParams params;
            params.samples = 1;

            // create the window and device context
            result = pSample->CPUTCreateWindowAndContext(_L("CPUTWindow OpenGLES"), params);
            if (result != CPUT_SUCCESS)
                LOGI("Unable to create window");
        }
        else
        {
            LOGI("Window already created");
        }
        break;
    case APP_CMD_TERM_WINDOW:
        LOGI("APP_CMD_TERM_WINDOW");
		exit(0);
        // Need clear window create and destroy calls
        // The window is being hidden or closed, clean it up.
        if (pSample->HasWindow())
        {
            pSample->DeviceShutdown();
        }
        break;
    case APP_CMD_GAINED_FOCUS:
        LOGI("APP_CMD_GAINED_FOCUS");
        break;
    case APP_CMD_LOST_FOCUS:
		exit(0);
        LOGI("APP_CMD_LOST_FOCUS");
        break;
	case APP_CMD_WINDOW_RESIZED:
        LOGI("APP_CMD_WINDOW_RESIZED");
        break;
    }
}
// Application entry point.  Execution begins here.
//-----------------------------------------------------------------------------
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
    // Prevent unused parameter compiler warnings
    UNREFERENCED_PARAMETER(hInstance);
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(nCmdShow);

#ifdef DEBUG
    // tell VS to report leaks at any exit of the program
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
    CPUTResult result=CPUT_SUCCESS;
    int returnCode=0;

    // create an instance of my sample
    MySample *pSample = new MySample();
    
    // We make the assumption we are running from the executable's dir in
    // the CPUT SampleStart directory or it won't be able to use the relative paths to find the default
    // resources    
    cString ResourceDirectory;
    CPUTOSServices::GetOSServices()->GetExecutableDirectory(&ResourceDirectory);
    ResourceDirectory.append(_L(".\\CPUT\\resources\\"));
    
    // Initialize the system and give it the base CPUT resource directory (location of GUI images/etc)
    // For now, we assume it's a relative directory from the executable directory.  Might make that resource
    // directory location an env variable/hardcoded later
    pSample->CPUTInitialize(ResourceDirectory); 

    // window and device parameters
    CPUTWindowCreationParams params;
    params.deviceParams.refreshRate         = 60;
    params.deviceParams.swapChainBufferCount= 1;
    params.deviceParams.swapChainFormat     = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
    params.deviceParams.swapChainUsage      = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;

    // parse out the parameter settings or reset them to defaults if not specified
    cString AssetFilename;
    cString CommandLine(lpCmdLine);
    pSample->CPUTParseCommandLine(CommandLine, &params, &AssetFilename);       

    // create the window and device context
    result = pSample->CPUTCreateWindowAndContext(_L("CPUTWindow DirectX 11"), params);
    ASSERT( CPUTSUCCESS(result), _L("CPUT Error creating window and context.") );
    
	// initialize the task manager
    gTaskMgr.Init();

    // start the main message loop
    returnCode = pSample->CPUTMessageLoop();

	pSample->DeviceShutdown();

	// shutdown task manage
	gTaskMgr.Shutdown();

    // cleanup resources
    delete pSample;

    return returnCode;
}