void MySample::ReleaseResources() { ImGui_ImplDX11_Shutdown(); // Note: these two are defined in the base. We release them because we addref them. SAFE_RELEASE(mpCamera); SAFE_RELEASE(mpShadowCamera); SAFE_DELETE(mpCameraController); SAFE_DELETE(mpDebugSprite); SAFE_DELETE(mpShadowRenderTarget); CPUTAssetLibrary::GetAssetLibrary()->ReleaseAllLibraryLists(); CPUT_DX11::ReleaseResources(); }
int main(int, char**) { // Create application window WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL }; RegisterClassEx(&wc); HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX11 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); // Initialize Direct3D if (CreateDeviceD3D(hwnd) < 0) { CleanupDeviceD3D(); UnregisterClass(wc.lpszClassName, wc.hInstance); return 1; } // Show the window ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls // Setup Dear ImGui style ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); // Setup Platform/Renderer bindings ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. // - Read 'misc/fonts/README.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Main loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT) { // Poll and handle messages (inputs, window resize, etc.) // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } // Start the Dear ImGui frame ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. { static float f = 0.0f; static int counter = 0; ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state ImGui::Checkbox("Another Window", &show_another_window); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) counter++; ImGui::SameLine(); ImGui::Text("counter = %d", counter); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); } // 3. Show another simple window. if (show_another_window) { ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) ImGui::Text("Hello from another window!"); if (ImGui::Button("Close Me")) show_another_window = false; ImGui::End(); } // Rendering ImGui::Render(); g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); g_pSwapChain->Present(1, 0); // Present with vsync //g_pSwapChain->Present(0, 0); // Present without vsync } ImGui_ImplDX11_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); CleanupDeviceD3D(); DestroyWindow(hwnd); UnregisterClass(wc.lpszClassName, wc.hInstance); return 0; }
int main(int ac, const char **av) { // Create application window WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("Douceur"), NULL }; RegisterClassEx(&wc); HWND hwnd = CreateWindow(_T("Douceur"), _T("Douceur"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); // Initialize Direct3D if (CreateDeviceD3D(hwnd) < 0) { CleanupDeviceD3D(); UnregisterClass(_T("Douceur"), wc.hInstance); return 1; } // Show the window ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); // Setup ImGui binding ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details) //ImGuiIO& io = ImGui::GetIO(); //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); bool show_test_window = true; ImVec4 clear_col = ImColor(114, 144, 154); // Main loop MSG msg; ZeroMemory(&msg, sizeof(msg)); std::string arduinoMsg; std::string arduinoDisplayMsg; bool messageEnded = true; FMOD::System *fmodSystem; FMOD::System_Create(&fmodSystem); FMOD::Sound *sound = 0; FMOD::Channel *channel = 0; FMOD::ChannelGroup *mastergroup = 0; fmodSystem->init(128, FMOD_INIT_NORMAL, 0); fmodSystem->getMasterChannelGroup(&mastergroup); fmodSystem->createSound("../DouceurExternal/audio-samples/Yamaha-1.wav", FMOD_LOOP_NORMAL, 0, &sound); unsigned int soundLength = 0; sound->getLength(&soundLength, FMOD_TIMEUNIT_MS); Serial arduino("COM6"); Board board(fmodSystem); while (msg.message != WM_QUIT) { fmodSystem->update(); if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } ImGui_ImplDX11_NewFrame(); static bool first = true; static int from = 0; static int to = 400; static float freq = 1.f; static float pan = 0.f; static float pitch = 0.f; if (!first) { fmodSystem->playSound(sound, mastergroup, false, &channel); first = true; to = soundLength; channel->getFrequency(&freq); channel->getPitch(&pitch); } { ImGui::SetNextWindowPos(ImVec2(10, 10)); ImGui::Begin("FPS", nullptr, ImVec2(0, 0), 0.3f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); } if (false) { ImGui::Begin("SoloudTest"); bool changed = ImGui::SliderInt("from", (int*)&from, 0, soundLength - 1); changed |= ImGui::SliderInt("to", (int*)&to, 1, soundLength); changed |= ImGui::SliderFloat("freq", &freq, 0, 500000.f); changed |= ImGui::SliderFloat("pan", &pan, -1.f, 1.f); changed |= ImGui::SliderFloat("pitch", &pitch, 0.f, 10.f); if (changed) { if (from >= to) { from = to - 1; } channel->setLoopPoints(from, FMOD_TIMEUNIT_MS, to, FMOD_TIMEUNIT_MS); channel->setFrequency(freq); channel->setPan(pan); } ImGui::End(); } if (false) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! ImGui::ShowTestWindow(nullptr); } board.updateGui(); //Arduino test { if (arduino.IsConnected()) { if (ImGui::Begin("Arduino test")) { char buffer[2048]; if (messageEnded) { arduino.WriteData("A", 1); messageEnded = false; } while (!messageEnded) { int count = arduino.ReadData(buffer, 2047); if (count) { buffer[count] = '\0'; if (buffer[count - 1] == '@') { buffer[count - 1] = '\0'; messageEnded = true; } arduinoMsg += buffer; } else { break; } } if (messageEnded) { board.updatePadsVoltage(arduinoMsg); arduinoDisplayMsg = arduinoMsg; arduinoMsg.clear(); } ImGui::TextWrapped(arduinoDisplayMsg.c_str()); ImGui::Text("Message size : %i", arduinoDisplayMsg.size()); } ImGui::End(); board.displayPadsVoltage(); } } // Rendering g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col); ImGui::Render(); g_pSwapChain->Present(0, 0); } ImGui_ImplDX11_Shutdown(); CleanupDeviceD3D(); UnregisterClass(_T("Douceur"), wc.hInstance); return EXIT_SUCCESS; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //DX初期化にはデバイス、コンテキスト、スワップチェインの3つ、加えてレンダリングターゲット WindowDevice &window = WindowDevice::getInstance(); DX11Device &device = DX11Device::getInstance(); window.Init(hInstance, nCmdShow, TEXT("test window"), 1280, 720, true); device.Init(window.getHandle(), window.getWidth(), window.getHeight(), window.getWindowMode()); // IMGUIの初期化 ImGui_ImplDX11_Init(window.getHandle(), device.getDevice(), device.getContext()); GraphicsPipeLine deferredGPL; //=====================================================// // 頂点データ情報(FarstPass & FinalPass) 1.CreateBufferで生成 2.IASetVertexBuffersで設定 3.Drawで実行(描画) //=====================================================// //***************宣言********************// ID3D11Buffer *vertexbuffer = nullptr; // FirstPassBuffer ID3D11Buffer *finalvertexbuffer = nullptr; // FinalPassBuffer D3D11_BUFFER_DESC bd; // 生成方法(バッファー リソース) //***************頂点生成********************// // 最初描画用 (FarstPass) Vertex4UV vertex[4] = { { 100.f, 100.f, 1.0f, 1.0f, 1.0f, 0.0f }, { -100.f, 100.f, 1.0f, 1.0f, 0.0f, 0.0f }, { 100.f, -100.f, 1.0f, 1.0f, 1.0f, 1.0f }, { -100.f, -100.f, 1.0f, 1.0f, 0.0f, 1.0f }, }; // 最終描画用 (FinalPass) Vertex4UV finalvertex[4] = { { 1.f, 1.f, 1.0f, 1.0f, 1.0f, 0.0f }, { -1.f, 1.f, 1.0f, 1.0f, 0.0f, 0.0f }, { 1.f, -1.f, 1.0f, 1.0f, 1.0f, 1.0f }, { -1.f, -1.f, 1.0f, 1.0f, 0.0f, 1.0f }, }; //***************頂点バッファ設定********************//(BufferDESCに生成方法を格納&CreateBufferで生成まで) // FirstPass設定 ZeroMemory(&bd, sizeof(bd)); // 中身をゼロクリア bd.Usage = D3D11_USAGE_DYNAMIC; // バッファーで想定されている読み込みおよび書き込みの方法を識別 bd.ByteWidth = sizeof(vertex); // バッファーのサイズ(バイト単位) bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; // なんのバッファですか? bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // CPUからは書き込みのみ行います device.getDevice()->CreateBuffer(&bd, nullptr, &vertexbuffer); // 設定したBufferを生成 // FinalPass設定 ZeroMemory(&bd, sizeof(bd)); // 中身をゼロクリア bd.Usage = D3D11_USAGE_DYNAMIC; // バッファーで想定されている読み込みおよび書き込みの方法を識別 bd.ByteWidth = sizeof(finalvertex); // バッファーのサイズ(バイト単位) bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; // なんのバッファですか? bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // CPUからは書き込みのみ行います device.getDevice()->CreateBuffer(&bd, nullptr, &finalvertexbuffer); // 設定したBufferを生成 //***************頂点情報を格納していく********************//(BufferDESCに生成方法を格納&CreateBufferで生成まで) // FirstPass格納 D3D11_MAPPED_SUBRESOURCE ms; // Bufferを格納する為にとりあえずロックをかけないといけない。どこまでロックをかける?サブリソース データにアクセスできるようにする device.getContext()->Map(vertexbuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms); // アクセス先ms memcpy(ms.pData, vertex, sizeof(vertex));// pData = vetexコピー 書き込み device.getContext()->Unmap(vertexbuffer, NULL); // ロック解除 // FinalPass格納 device.getContext()->Map(finalvertexbuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms); // アクセス先ms memcpy(ms.pData, finalvertex, sizeof(finalvertex));// pData = vetexコピー 書き込み device.getContext()->Unmap(finalvertexbuffer, NULL); // ロック解除 //=====================================================// // シェーダー情報(VertexShader&PixelShader) 1.Create(Vertex & Pixel)Shaderで生成 2.(VS & PS)SetShaderで実行 //=====================================================// //***************宣言********************// ID3D11VertexShader *vs_buf = nullptr; // (first) shaderのbuffer コンパイルしたシェーダーの格納先 ID3D11PixelShader *ps_buf = nullptr; // (first) shaderのbuffer コンパイルしたシェーダーの格納先 ID3D11VertexShader *vsfinal_buf = nullptr; // (final) shaderのbuffer コンパイルしたシェーダーの格納先 ID3D11PixelShader *psfinal_buf = nullptr; // (final) shaderのbuffer コンパイルしたシェーダーの格納先 ID3D10Blob *vsblob, *psblob, *vsblobfinal, *psblobfinal; // 任意長のデータを返す際に使用 //***************シェーダーコード格納ファイルコンパイル********************// D3DX11CompileFromFile(TEXT("./Shader/VSDeferred.hlsl"), 0, 0, "main", "vs_5_0", 0, 0, 0, &vsblob, 0, 0); D3DX11CompileFromFile(TEXT("./Shader/PSDeferred.hlsl"), 0, 0, "main", "ps_5_0", 0, 0, 0, &psblob, 0, 0); D3DX11CompileFromFile(TEXT("./Shader/VSDeferredFinal.hlsl"), 0, 0, "main", "vs_5_0", 0, 0, 0, &vsblobfinal, 0, 0); D3DX11CompileFromFile(TEXT("./Shader/PSDeferredFinal.hlsl"), 0, 0, "main", "ps_5_0", 0, 0, 0, &psblobfinal, 0, 0); //***************シェーダーの設定(VS&PS)**********************************// device.getDevice()->CreateVertexShader(vsblob->GetBufferPointer(), vsblob->GetBufferSize(), nullptr, &vs_buf); // コンパイル済みシェーダーから、頂点シェーダー オブジェクトを作成 device.getDevice()->CreatePixelShader(psblob->GetBufferPointer(), psblob->GetBufferSize(), nullptr, &ps_buf); // ピクセル シェーダーを作成 device.getDevice()->CreateVertexShader(vsblobfinal->GetBufferPointer(), vsblobfinal->GetBufferSize(), nullptr, &vsfinal_buf); // コンパイル済みシェーダーから、頂点シェーダー オブジェクトを作成 device.getDevice()->CreatePixelShader(psblobfinal->GetBufferPointer(), psblobfinal->GetBufferSize(), nullptr, &psfinal_buf); // ピクセル シェーダーを作成 // 頂点シェーダーをデバイスに設定(実行) device.getContext()->VSSetShader(vsfinal_buf, nullptr, 0); // 頂点シェーダーをデバイスに設定 device.getContext()->PSSetShader(psfinal_buf, nullptr, 0); // ピクセル シェーダーをデバイスに設定 //=====================================================// /// 頂点レイアウト情報 //=====================================================// // 入力レイアウト(レイアウト情報をコンパイル済みVertexShaderから動的に構築) D3D11_INPUT_ELEMENT_DESC element[] = { // 入力アセンブラー ステージの単一の要素( HLSL セマンティクス,要素のセマンティクス インデックス,要素データのデータ型,入力アセンブラーを識別する整数値,各要素間のオフセット (バイト単位),単一の入力スロットの入力データ クラスを識別,インスタンス単位の同じデータを使用して描画するインスタンスの数) { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },// 位置情報 { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 } // UV情報 }; ID3D11InputLayout *inputlayout; // 入力アセンブラー ステージの入力データにアクセス device.getDevice()->CreateInputLayout(element, ARRAYSIZE(element), vsblobfinal->GetBufferPointer(), vsblobfinal->GetBufferSize(), &inputlayout); // 格納(入力アセンブラー ステージで使用される入力バッファー データ) device.getContext()->IASetInputLayout(inputlayout); //インプットレイアウトの設定 入力アセンブラー ステージに入力レイアウト オブジェクトをバインド device.getContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // 頂点の並び方の設定(プリミティブ タイプおよびデータの順序に関する情報をバインド) // 通常描画用のパイプライン CrateDeferredPipeLine(deferredGPL); //=====================================================// // カメラ情報 //=====================================================// ConstantBuffer mtx; // Shaderに送る行列の生成 XMVECTOR hEye = XMVectorSet(0.0f, 0.0f, -2.0f, 0.0f); XMVECTOR hAt = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); XMVECTOR hUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); mtx.mView = XMMatrixLookAtLH(hEye, hAt, hUp); mtx.mWorld = XMMatrixIdentity(); mtx.mProjection = XMMatrixOrthographicLH((float) window.getWidth(), (float) window.getHeight(), 1, 5000); //=====================================================// // コンスタント情報 //=====================================================// //コンテキストバッファ:シェーダーで宣言した定数をプログラム側から変更する(主に生成、更新、シェーダーステージへのセットという3つのアクション) // constantバッファ生成 ID3D11Buffer *constantbuffer = nullptr; ZeroMemory(&bd, sizeof(bd)); // 中身をクリア // Bufferの生成方法の格納 bd.ByteWidth = sizeof(ConstantBuffer); // sizeの指定 bd.Usage = D3D11_USAGE_DEFAULT; bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; // なんのバッファですか? bd.CPUAccessFlags = 0; // CPUからは書き込みのみ行います bd.MiscFlags = 0; bd.StructureByteStride = sizeof(float); device.getDevice()->CreateBuffer(&bd, NULL, &constantbuffer); // バッファの生成 //=====================================================// // バッファ情報 //=====================================================// // テクスチャの読み込み Texture2D tex,tex2; tex.LoadFile("./Resource/Lenna.png"); tex2.LoadFile("./Resource/lenna_normal.png"); ID3D11ShaderResourceView *srv[] = { tex.getSRV(), tex2.getSRV() }; device.getContext()->PSSetShaderResources(0, 2, srv); // ピクセル シェーダー ステージにシェーダー リソースの配列をバインド // MRT(マルチレンダーターゲット) //Gバッファの生成 ジオメトリバッファ(1pass 複数描画 2次元情報として保存:頂点シェーダとピクセルシェーダの間に実行) Texture2D GBuffer[4]; UINT bindflg = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; // リソースをパイプラインにバインドする方法を識別(、バインド フラグは論理和を使って組み合わせることができる) GBuffer[0].Create(window.getWidth(), window.getHeight(), D3D11_USAGE_DEFAULT, DXGI_FORMAT_R32G32B32A32_FLOAT, bindflg); //Albed GBuffer[1].Create(window.getWidth(), window.getHeight(), D3D11_USAGE_DEFAULT, DXGI_FORMAT_R32G32B32A32_FLOAT, bindflg); //Normal GBuffer[2].Create(window.getWidth(), window.getHeight(), D3D11_USAGE_DEFAULT, DXGI_FORMAT_R32_FLOAT, bindflg); //Depth GBuffer[3].Create(window.getWidth(), window.getHeight(), D3D11_USAGE_DEFAULT, DXGI_FORMAT_R32G32B32A32_FLOAT, bindflg); //Diffuse // レンダリング時にシェーダーがアクセス可能なサブリソースを指定(ShaderResourceView) ID3D11ShaderResourceView *GBufferSRV [] = { GBuffer[0].getSRV(), // Albed GBuffer[1].getSRV(), // Normal GBuffer[2].getSRV(), // Depth GBuffer[3].getSRV(), // Diffuse }; // レンダリング時にアクセス可能なレンダー ターゲットのサブリソースを識別(Render Target View) ID3D11RenderTargetView *GBufferRTV [] = { GBuffer[0].getRTV(), // Albed GBuffer[1].getRTV(), // Normal GBuffer[2].getRTV(), // Depth GBuffer[3].getRTV(), // Diffuse }; // クリアの際に使用する ID3D11ShaderResourceView *NULLSRV[] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }; ID3D11RenderTargetView *NULLRTV[] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }; // パイプラインの構築 deferredGPL.setStatus(); //=====================================================// // ループ処理 //=====================================================// int ret = 0; while (ret != WM_QUIT){ ret = window.MessageLoop(); float clear [] = { 0.0f, 0.0f, 0.0f, 0.0f }; // パイプラインのクリア device.getContext()->OMSetRenderTargets(8, NULLRTV, nullptr); // レンダーターゲットのクリア device.getContext()->PSSetShaderResources(0,8, NULLSRV); // シェーダーリソースのクリア //バックバッファのクリア DEBUG(device.getAnotation()->BeginEvent(L"バッファのクリア")); device.getContext()->ClearRenderTargetView(device.getRTV(), clear); device.getContext()->ClearDepthStencilView(device.getDSV(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); //GBufferのクリア for (auto v : GBufferRTV) { device.getContext()->ClearRenderTargetView(v, clear); } DEBUG(device.getAnotation()->EndEvent()); //GUIのクリア ImGui_ImplDX11_NewFrame(); // デバッグ情報の出力 ImGui::Text("Debug Text"); ImGui::Text("Application.average %.3f ms/frame(%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); // FPS //通常描画で使うバッファの更新 // Bufferに更新をかける (コンスタントバッファを更新) device.getContext()->UpdateSubresource(constantbuffer, 0, NULL, &mtx, 0, 0); // CPU によって、マッピング不可能なメモリー内に作成されたサブリソースにメモリーからデータがコピーされる // Bufferをパイプラインにセット (シェーダーステージへのセット) device.getContext()->VSSetConstantBuffers(0, 1, &constantbuffer); // 頂点シェーダーのパイプライン ステージで使用される定数バッファーを設定 //通常描画の設定 device.getContext()->OMSetRenderTargets(4, GBufferRTV, nullptr); // 出力結合ステージに深度ステンシル バッファーをバインド UINT stride = sizeof(Vertex4UV); // 頂点のサイズ UINT offset = 0; // ずれの調整 device.getContext()->IASetVertexBuffers(0, 1, &vertexbuffer, &stride, &offset); // 入力アセンブラー ステージに頂点バッファーの配列をバインド device.getContext()->VSSetShader(vs_buf, nullptr, 0); // 頂点シェーダーをデバイスに設定 device.getContext()->PSSetShader(ps_buf, nullptr, 0); // ピクセル シェーダーをデバイスに設定 device.getContext()->IASetInputLayout(inputlayout); // 入力アセンブラー ステージに入力レイアウト オブジェクトをバインド //テクスチャの設定 ID3D11ShaderResourceView *srv [] = { // レンダリング時にシェーダーがアクセス可能なサブリソースを指定 tex.getSRV(), tex2.getSRV() }; device.getContext()->PSSetShaderResources(0, 2, srv); // ピクセル シェーダー ステージにシェーダー リソースの配列をバインド device.getContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // プリミティブ タイプおよびデータの順序に関する情報をバインド //通常描画 device.getContext()->Draw(4, 0);// 頂点数:何番目の頂点からやるか //ディファードの最終描画の設定 DEBUG(device.getAnotation()->BeginEvent(L"ディファードの最終合成")); ID3D11RenderTargetView *finalrtv [] = { device.getRTV(), }; device.getContext()->OMSetRenderTargets(1, finalrtv, nullptr); // // 出力結合ステージに深度ステンシル バッファーをバインド device.getContext()->IASetVertexBuffers(0, 1, &finalvertexbuffer, &stride, &offset); device.getContext()->VSSetShader(vsfinal_buf, nullptr, 0); // 頂点シェーダーをデバイスに設定 device.getContext()->PSSetShader(psfinal_buf, nullptr, 0); // ピクセル シェーダーをデバイスに設定 device.getContext()->IASetInputLayout(inputlayout); // // 入力アセンブラー ステージに入力レイアウト オブジェクトをバインド device.getContext()->PSSetShaderResources(0, 4, GBufferSRV); // ピクセル シェーダー ステージにシェーダー リソースの配列をバインド device.getContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // // プリミティブ タイプおよびデータの順序に関する情報をバインド //ディファードの最終描画 device.getContext()->Draw(4, 0);// 頂点数:何番目の頂点からやるか DEBUG(device.getAnotation()->EndEvent()); //Guiの描画 ImGui::Render(); //バックバッファとフロントバッファの切り替え device.getSwapChain()->Present(0, 0); } //=====================================================// // 解放処理 //=====================================================// //ImGuiの終了処理 ImGui_ImplDX11_Shutdown(); // マクロリリース SAFE_RELEASE(vertexbuffer); SAFE_RELEASE(finalvertexbuffer); SAFE_RELEASE(vs_buf); SAFE_RELEASE(ps_buf); SAFE_RELEASE(vsfinal_buf); SAFE_RELEASE(psfinal_buf); SAFE_RELEASE(inputlayout); SAFE_RELEASE(constantbuffer); deferredGPL.Release(); return ret; }
int main(int, char**) { // Create application window WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL }; RegisterClassEx(&wc); HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX11 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); // Initialize Direct3D if (CreateDeviceD3D(hwnd) < 0) { CleanupDeviceD3D(); UnregisterClass(_T("ImGui Example"), wc.hInstance); return 1; } // Show the window ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); // Setup ImGui binding ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); // Setup style ImGui::StyleColorsClassic(); //ImGui::StyleColorsDark(); // Load Fonts // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. // - Read 'extra_fonts/README.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //ImGuiIO& io = ImGui::GetIO(); //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Main loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT) { // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } ImGui_ImplDX11_NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". { static float f = 0.0f; ImGui::Text("Hello, world!"); // Some text (you can use a format string too) ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float as a slider from 0.0f to 1.0f ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats as a color if (ImGui::Button("Demo Window")) // Use buttons to toggle our bools. We could use Checkbox() as well. show_demo_window ^= 1; if (ImGui::Button("Another Window")) show_another_window ^= 1; ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); } // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name the window. if (show_another_window) { ImGui::Begin("Another Window", &show_another_window); ImGui::Text("Hello from another window!"); ImGui::End(); } // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). if (show_demo_window) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! ImGui::ShowDemoWindow(&show_demo_window); } // Rendering g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); ImGui::Render(); g_pSwapChain->Present(1, 0); // Present with vsync //g_pSwapChain->Present(0, 0); // Present without vsync } ImGui_ImplDX11_Shutdown(); CleanupDeviceD3D(); UnregisterClass(_T("ImGui Example"), wc.hInstance); return 0; }
void CImGuiModule::stop() { delete m_pLights_editor; delete m_pMessages_editor; ImGui_ImplDX11_Shutdown(); }
int main(int, char**) { // Create application window WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, L"ImGui Example", NULL }; RegisterClassEx(&wc); HWND hwnd = CreateWindow(L"ImGui Example", L"ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); // Initialize Direct3D if (CreateDeviceD3D(hwnd) < 0) { CleanupDeviceD3D(); UnregisterClass(L"ImGui Example", wc.hInstance); return 1; } // Show the window ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); // Setup ImGui binding ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts // (see extra_fonts/README.txt for more details) //ImGuiIO& io = ImGui::GetIO(); //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons) //static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope. //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true; //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges); bool show_test_window = true; bool show_another_window = false; ImVec4 clear_col = ImColor(114, 144, 154); // Main loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } ImGui_ImplDX11_NewFrame(); // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f = 0.0f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ImGui::ColorEdit3("clear color", (float*)&clear_col); if (ImGui::Button("Test Window")) show_test_window ^= 1; if (ImGui::Button("Another Window")) show_another_window ^= 1; ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); } // 2. Show another simple window, this time using an explicit Begin/End pair if (show_another_window) { ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver); ImGui::Begin("Another Window", &show_another_window); ImGui::Text("Hello"); ImGui::End(); } // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! ImGui::ShowTestWindow(&show_test_window); } // Rendering g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col); ImGui::Render(); g_pSwapChain->Present(0, 0); } ImGui_ImplDX11_Shutdown(); CleanupDeviceD3D(); UnregisterClass(L"ImGui Example", wc.hInstance); return 0; }
int WINAPI wWinMain(HINSTANCE /*instance*/, HINSTANCE /*prev_instance*/, PWSTR /*cmd_line*/, int /*cmd_show*/) { WNDCLASSEX wc = {}; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_CLASSDC; wc.lpfnWndProc = WndProc; wc.hInstance = GetModuleHandleW(nullptr); wc.hCursor = LoadCursorW(nullptr, IDC_ARROW); wc.lpszClassName = L"ImGui Sandbox"; ::RegisterClassExW(&wc); HWND hwnd = ::CreateWindowExW(0, L"ImGui Sandbox", L"ImGui DirectX11 Sandbox", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr); if (FAILED(CreateDeviceD3D(hwnd))) { CleanupDeviceD3D(); ::UnregisterClassW(L"ImGui Sandbox", wc.hInstance); return 1; } ::ShowWindow(hwnd, SW_SHOWDEFAULT); ::UpdateWindow(hwnd); ImGui_ImplDX11_Init(hwnd, g_device, g_device_context); MSG msg = {}; while (msg.message != WM_QUIT) { if (::PeekMessageW(&msg, nullptr, 0U, 0U, PM_REMOVE)) { ::TranslateMessage(&msg); ::DispatchMessageW(&msg); continue; } ImGui_ImplDX11_NewFrame(); ImGui::SetNextWindowSize(ImVec2(320, 250), ImGuiSetCond_FirstUseEver); ImGui::SetNextWindowPos(ImVec2(15, 15), ImGuiSetCond_FirstUseEver); if (ImGui::Begin("Sandbox")) { ImGui::Text("Test"); ImGui::Text("FPS: %.1f.", ImGui::GetIO().Framerate); } ImGui::End(); ImVec4 clear_col = ImColor(114, 144, 154); g_device_context->ClearRenderTargetView(g_main_rtv, &clear_col.x); ImGui::Render(); g_swap_chain->Present(0, 0); } ImGui_ImplDX11_Shutdown(); CleanupDeviceD3D(); ::UnregisterClassW(L"ImGui Sandbox", wc.hInstance); return 0; }