/*-------------------------------------------- メイン ---------------------------------------------*/ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) { // デバッグ ヒープ マネージャによるメモリ割り当ての追跡方法を設定 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // XNA Mathライブラリのサポート チェック if (XMVerifyCPUSupport() != TRUE) { DXTRACE_MSG(L"WinMain XMVerifyCPUSupport"); return 0; } // アプリケーションに関する初期化 HRESULT hr = InitApp(hInst); if (FAILED(hr)) { DXTRACE_ERR(L"WinMain InitApp", hr); return 0; } // Direct3Dの初期化 hr = InitDirect3D(); if (FAILED(hr)) { DXTRACE_ERR(L"WinMain InitDirect3D", hr); CleanupDirect3D(); CleanupApp(); return 0; } // メッセージ ループ MSG msg; do { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { // アイドル処理 if (!AppIdle()) // エラーがある場合,アプリケーションを終了する DestroyWindow(g_hWindow); } } while (msg.message != WM_QUIT); // アプリケーションの終了処理 CleanupApp(); return (int)msg.wParam; }
bool UGraphicsDevice::Init(int inClientHeight, int inClientWidth) { LOG(LogGraphicsDevice, Log, "Graphics Device initialization begin...\n"); if (!XMVerifyCPUSupport()) { LOG(LogGraphicsDevice, Error, "Init() Failed to verify DirectX Math library support\n"); return false; } DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); swapChainDesc.BufferCount = 1; swapChainDesc.BufferDesc.Width = inClientWidth; swapChainDesc.BufferDesc.Height = inClientHeight; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.OutputWindow = UGameWindow::GetHWnd(); swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Windowed = true; UINT createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags = D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; D3D_FEATURE_LEVEL featureLevel; HRESULT hr = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevels, _countof(featureLevels), D3D11_SDK_VERSION, &swapChainDesc, &mD3dSwapChain, &mD3dDevice, &featureLevel, &mD3dDeviceCtx); if (hr == E_INVALIDARG) { hr = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, &featureLevels[1], _countof(featureLevels) - 1, D3D11_SDK_VERSION, &swapChainDesc, &mD3dSwapChain, &mD3dDevice, &featureLevel, &mD3dDeviceCtx); } if (FAILED(hr)) { LOG(LogGraphicsDevice, Error, "Init() Failed to create graphics device and swap chain\n"); return false; } if (!CreateBackBuffer()) { LOG(LogGraphicsDevice, Error, "Init() Failed to create the application back buffer render target view\n"); return false; } SetViewport(inClientHeight, inClientWidth); LOG(LogGraphicsDevice, Log, "Graphics Device initialization successful\n"); return true; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif //Logger object, currently logging everything ee::Logger *logger = new ee::Logger("EagleEngine.log", ee::LEVEL_SEVERE); if(!logger->Init()) { ERROR_BOX(L"Could not load logger!"); return -1; } //Config for creating window ee::Config *config = new ee::Config("config.txt"); if (!config->Init()) { logger->Log("Could not load config file for reading!", ee::LEVEL_WARNING); } //Write all info to log file if (config->GetFullScreen()) logger->Log("Full Screen = TRUE", ee::LEVEL_INFO); else logger->Log("Full Screen = FALSE", ee::LEVEL_INFO); if (config->GetVSync()) logger->Log("V Sync = TRUE", ee::LEVEL_INFO); else logger->Log("V Sync = FALSE", ee::LEVEL_INFO); if (config->GetShowFPS()) logger->Log("Show FPS = TRUE", ee::LEVEL_INFO); else logger->Log("Show FPS = FALSE", ee::LEVEL_INFO); char buffer[10]; _itoa_s(config->GetScreenWidth(), buffer, 10); logger->Log(buffer, ee::LEVEL_INFO); _itoa_s(config->GetScreenHeight(), buffer, 10); logger->Log(buffer, ee::LEVEL_INFO); //Verify XNAMath CPU support if (!XMVerifyCPUSupport()) { ERROR_BOX(L"XNA Maths is not supported on this CPU!"); logger->Log("XNA Maths is not supported on this CPU!", ee::LEVEL_SEVERE); return -1; } //The window the game will run in ee::Window *window = new ee::Window(hInstance, L"Eagle Engine", config, logger);; if (!window->Init(nCmdShow)) return -1; //OutputDebugString(L"Window creation success!\n"); logger->Log("Window creation success", ee::LEVEL_INFO); window->Run(); //Free window window->Release(); delete window; window = NULL; //Free config config->Release(); delete config; config = NULL; logger->CloseLogger(); delete logger; logger = NULL; return 0; }