/** * This is the main entry point of a native application that is using * android_native_app_glue. It runs in its own thread, with its own * event loop for receiving input events and doing other things. */ void android_main(struct android_app* state) { // Make sure glue isn't stripped. app_dummy(); LOGI("\n\n********************************"); LOGI(" STARTING SAMPLE"); LOGI("********************************\n\n"); // create an instance of my sample MySample *pSample = new MySample(); if (!pSample) { LOGI("Failed to allocate MySample"); return; } // Assign the sample back into the app state state->userData = pSample; state->onAppCmd = cput_handle_cmd; state->onInputEvent = CPUT_OGL::cput_handle_input; // 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; CPUTFileSystem::GetExecutableDirectory(&ResourceDirectory); // Different executable and assets locations on different OS'es. // Consistency should be maintained in all OS'es and API's. ResourceDirectory.append(GUI_LOCATION); // 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 CPUTWindowAndroid::SetAppState(state); pSample->CPUTInitialize(ResourceDirectory); CPUTFileSystem::GetExecutableDirectory(&ResourceDirectory); // Different executable and assets locations on different OS'es. // Consistency should be maintained in all OS'es and API's. ResourceDirectory.append(SYSTEM_LOCATION); CPUTAssetLibrary *pAssetLibrary = CPUTAssetLibrary::GetAssetLibrary(); pAssetLibrary->SetSystemDirectoryName(ResourceDirectory); // start the main message loop pSample->CPUTMessageLoop(); // cleanup resources SAFE_DELETE(pSample); pSample = NULL; state->userData = NULL; }
// 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, ¶ms, &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; }