예제 #1
0
void AppMain()
{
    AppInit(1280, 720, "silver-winner");

    for (;;)
    {
        MSG msg;
        while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }

        if (g_App.bShouldClose)
        {
            break;
        }

        ImGui_ImplDX11_NewFrame();

        RendererPaint();
    }

    AppExit();
}
예제 #2
0
//-----------------------------------------------------------------------------
void MySample::Update(double deltaSeconds)
{
	ImGui_ImplDX11_NewFrame();
	if (mpWindow->DoesWindowHaveFocus())
	{
		mpCameraController->SetCamera(mpCamera);
		if (mpCameraController)
			mpCameraController->Update((float)deltaSeconds);
	}

	MenuController_Update((float)deltaSeconds);

    CPUTGetGuiController()->ControlModified();
    CPUTGetGuiController()->Update();
}
예제 #3
0
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;
}
예제 #4
0
파일: main.cpp 프로젝트: cesarl/Douceur
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;
}
예제 #5
0
void Pyx::Graphics::Gui::ImGuiImpl::OnFrame()
{
    if (m_isInitialized)
    {

        if (!m_isResourcesCreated)
            CreateResources();

        if (m_isResourcesCreated)
        {
            auto* pRenderer = GraphicsContext::GetInstance().GetMainRenderer();

            if (pRenderer)
            {

                auto& io = ImGui::GetIO();

                if (Input::InputContext::GetInstance().CursorIsVisible() && pRenderer->GetAttachedWindow() == GetForegroundWindow())
                {
                    auto cursorPos = Input::InputContext::GetInstance().GetCursorPosition();
                    ScreenToClient(pRenderer->GetAttachedWindow(), &cursorPos);
                    io.MousePos.x = cursorPos.x;
                    io.MousePos.y = cursorPos.y;
                    io.MouseDown[0] = GetAsyncKeyState(VK_LBUTTON) != 0;
                    io.MouseDown[1] = GetAsyncKeyState(VK_RBUTTON) != 0;
                    io.MouseDown[2] = GetAsyncKeyState(VK_MBUTTON) != 0;
                    io.KeyCtrl = GetAsyncKeyState(VK_CONTROL) != 0;
                    io.KeyShift = GetAsyncKeyState(VK_SHIFT) != 0;
                    io.KeyAlt = GetAsyncKeyState(VK_MENU) != 0;
                }

                switch (pRenderer->GetRendererType())
                {
                case RendererType::D3D9:
                {
                    ImGui_ImplDX9_NewFrame();
                    break;
                }
                case RendererType::D3D11:
                {
                    ImGui_ImplDX11_NewFrame();
                    break;
                }
                default:
                    return;
                }

				if (m_isVisible)
				{

					BuildMainMenuBar();

					if (m_showConsole)
						BuildLogsWindow();

					if (m_showDebugWindow)
						BuildDebugWindow();

					GetOnRenderCallbacks().Run(this);
					Scripting::ScriptingContext::GetInstance().FireCallbacks(XorStringW(L"ImGui.OnRender"));

					ImGui::Render();

				}

            }

			static int lastToggleVisibilityTick = 0;
			if (GetTickCount() - lastToggleVisibilityTick > 250)
			{

				bool shouldToggleGui = true;
				for (auto vKey : PyxContext::GetInstance().GetSettings().GuiToggleVisibilityHotkeys)
				{
					if (GetAsyncKeyState(vKey) == NULL)
					{
						shouldToggleGui = false;
						break;
					}
				}

				if (shouldToggleGui)
				{
					ToggleVisibility(!IsVisible());
					lastToggleVisibilityTick = GetTickCount();
				}

			}

            static int lastToggleConsoleVisibilityTick = 0;
            if (GetTickCount() - lastToggleConsoleVisibilityTick > 250)
            {

                bool shouldToggleConsole = true;
                for (auto vKey : PyxContext::GetInstance().GetSettings().ImGuiToggleConsoleHotkeys)
                {
                    if (GetAsyncKeyState(vKey) == NULL)
                    {
                        shouldToggleConsole = false;
                        break;
                    }
                }

                if (shouldToggleConsole)
                {
                    m_showConsole = !m_showConsole;
                    lastToggleConsoleVisibilityTick = GetTickCount();
                }

            }

        }

    }

}
예제 #6
0
INDICIUM_EXPORT Present(IID guid, LPVOID unknown)
{
	static auto bIsImGuiInitialized = false;

	if (guid == IID_IDirect3DDevice9)
	{
		if (!bIsImGuiInitialized)
		{
			if (g_hWnd)
			{
				ImGui_ImplDX9_Init(g_hWnd, static_cast<IDirect3DDevice9*>(unknown));

				BOOST_LOG_TRIVIAL(info) << "ImGui (DX9) initialized";

				bIsImGuiInitialized = true;
			}
		}
		else
		{
			ImGui_ImplDX9_NewFrame();
			RenderScene();
		}
	}
	else if (guid == IID_IDirect3DDevice9Ex)
	{
		if (!bIsImGuiInitialized)
		{
			if (g_hWnd)
			{
				ImGui_ImplDX9_Init(g_hWnd, static_cast<IDirect3DDevice9Ex*>(unknown));

				BOOST_LOG_TRIVIAL(info) << "ImGui (DX9Ex) initialized";

				bIsImGuiInitialized = true;
			}
		}
		else
		{
			ImGui_ImplDX9_NewFrame();
			RenderScene();
		}
	}
	else if (guid == IID_IDXGISwapChain)
	{
		auto chain = static_cast<IDXGISwapChain*>(unknown);

		static ID3D11DeviceContext* ctx = nullptr;
		static ID3D11RenderTargetView* view = nullptr;
		static ID3D11Device* dev = nullptr;

		if (!bIsImGuiInitialized)
		{
			// window handle available, initialize
			if (g_hWnd)
			{
				// get device
				chain->GetDevice(__uuidof(dev), reinterpret_cast<void**>(&dev));

				// get device context
				dev->GetImmediateContext(&ctx);

				// initialize ImGui
				ImGui_ImplDX11_Init(g_hWnd, dev, ctx);

				BOOST_LOG_TRIVIAL(info) << "ImGui (DX11) initialized";

				bIsImGuiInitialized = true;
			}
		}
		else
		{
			DXGI_SWAP_CHAIN_DESC sd;
			chain->GetDesc(&sd);

			if (view)
				view->Release();

			// Create the render target
			ID3D11Texture2D* pBackBuffer;
			D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc;
			ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc));
			render_target_view_desc.Format = sd.BufferDesc.Format;
			render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
			chain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer));
			dev->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &view);
			ctx->OMSetRenderTargets(1, &view, nullptr);
			pBackBuffer->Release();

			ImGui_ImplDX11_NewFrame();

			RenderScene();
		}
	}
}
예제 #7
0
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;
}
예제 #8
0
파일: main.cpp 프로젝트: fdkz/aniplot
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;
}
예제 #9
0
void CImGuiModule::update(float dt) {
	ImGui_ImplDX11_NewFrame();

	ImGuiWindowFlags window_flags = 0;
	window_flags |= ImGuiWindowFlags_MenuBar;
	bool menu = true;
#ifndef FINAL_BUILD
	if (controller->IsToogleDebugUIPressed()) show_imgui = !show_imgui;
	if (!show_imgui) return;
	ImGui::Begin("Debug UI", &menu, ImVec2(800, 512), -1.0f, window_flags);
	ImGui::PushItemWidth(-140);                                 // Right align, keep 140 pixels for labels

	m_pLights_editor->update(dt);
	m_pMessages_editor->update(dt);

	//Engine Apps
	//---------------------------------------
	if (ImGui::BeginMenuBar())
	{
		if (ImGui::BeginMenu("Apps"))
		{
			ImGui::MenuItem("Log (L)", NULL, Debug->getStatus());
			ImGui::MenuItem("Commands (O)", NULL, Debug->GetCommandsConsoleState());

			ImGui::MenuItem("Particle editor (F8)", NULL, g_particlesManager->GetParticleEditorState());
			ImGui::MenuItem("Lights editor (F9)", NULL, m_pLights_editor->GetLightsEditorState());
			ImGui::MenuItem("Messages editor (F10)", NULL, m_pMessages_editor->GetEditorState());

			//Debug->OpenConsole();
			ImGui::EndMenu();
		}
		ImGui::EndMenuBar();
	}
	//---------------------------------------
	//Current Level
	IMGUI_SHOW_INT(CApp::get().GetLevelNumber());

	//Language
	IMGUI_SHOW_STRING(lang_manager->GetLanguage());

	//Difficulty
	IMGUI_SHOW_INT(GameController->GetDifficulty());

	//Extra wait end frame
	if (ImGui::TreeNode("Physx Timing")) {
		float tmax_update = g_PhysxManager->GetTMaxUpdate();
		ImGui::PushItemWidth(100);
		if (ImGui::DragFloat("tmax_update", &tmax_update, 0.01f)) {
			g_PhysxManager->SetTMaxUpdate(tmax_update);
		}
		ImGui::DragFloat("Wait end frame", CApp::get().GetWaitEnd());
		if (ImGui::Checkbox("Multi simulate", g_PhysxManager->GetMultiSimulatePointer())) {
			dbg("Changed Multisimulate\n");
		}
		ImGui::PopItemWidth();
		ImGui::TreePop();
	}

	//Last Input
	ImGui::Checkbox("Gamepad Mode", io->IsGamePadModePointer());

	//Buttons game
	//---------------------------------------
	if (GameController->GetGameState() == CGameController::RUNNING) {
		IMGUI_SHOW_INT(CGameController::RUNNING);
		if (ImGui::Button("PAUSE BUTTON"))
			GameController->SetGameState(CGameController::STOPPED);

		ImGui::SameLine();
		ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 1, 0, 1));
		if (ImGui::Button("RESUME BUTTON"))
			GameController->SetGameState(CGameController::RUNNING);

		ImGui::PopStyleColor();
	}
	else if (GameController->GetGameState() == CGameController::STOPPED) {
		IMGUI_SHOW_INT(CGameController::STOPPED);
		ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 1, 0, 1));
		if (ImGui::Button("PAUSE BUTTON"))
			GameController->SetGameState(CGameController::STOPPED);

		ImGui::PopStyleColor();

		ImGui::SameLine();

		if (ImGui::Button("RESUME BUTTON"))
			GameController->SetGameState(CGameController::RUNNING);
	}
	ImGui::SameLine();
	if (ImGui::Button("SKIP Cine.")) {
		logic_manager->throwUserEvent("cam:skip_cinematic();");
	}
	//Select Level
	{
		ImGui::PushItemWidth(80);
		static int level_selected = 1;
		if (ImGui::InputInt("", &level_selected)) {
			if (level_selected > 4) level_selected = 0;
			if (level_selected < 0) level_selected = 4;
		}
		ImGui::SameLine();
		auto name_scenes = CApp::get().GetNameScenes();
		char logic_level[] = "level_X";
		logic_level[6] = '0' + (unsigned char)(level_selected);
		ImGui::SameLine();
		ImGui::Text("%s", name_scenes[logic_level].c_str());
		ImGui::SameLine();
		if (ImGui::Button("Load Level")) {
			char lua_code[256];
			sprintf(lua_code, "p:stop_music(); p:setup_game(); LoadLevel(\"level_%d\")", level_selected);
			logic_manager->throwUserEvent(lua_code);
		}
		ImGui::PopItemWidth();
	}

	if (ImGui::Button("SAVE GAME")) CApp::get().saveLevel();
	if (ImGui::Button("LOAD GAME")) CApp::get().restartLevelNotify();

	ImGui::Checkbox("Free camera (K)", GameController->GetFreeCameraPointer());
	ImGui::Checkbox("Ui control", Gui->IsUiControlPointer());
	//ImGui::Checkbox("Continous Collision Detection", &(g_PhysxManager->ccdActive));

	if (ImGui::TreeNode("LUA Test")) {
		static char test_lua_txt[256] = "OnTest();";
		ImGui::InputTextMultiline("Test Lua", test_lua_txt, 256);
		if (ImGui::Button("Execute")) {
			logic_manager->throwUserEvent(test_lua_txt);
		}
		ImGui::TreePop();
	}

	if (ImGui::TreeNode("Gui create elements")) {
		static VEC3 pos_new_ui = VEC3(0.5f, 0.5f, 0.9f);
		static char gui_prebab_name[64] = "Fading_Letter";
		static char gui_prebab_entity_name[64] = "TEST";

		ImGui::DragFloat3("Pos", &pos_new_ui.x, 0.1f, -1.f, 2.f);
		ImGui::InputText("Prefab name", gui_prebab_name, 64);
		ImGui::InputText("Entity name", gui_prebab_entity_name, 64);
		if (ImGui::Button("Create")) {
			CHandle gui_elem = Gui->addGuiElement(std::string("ui/") + std::string(gui_prebab_name), pos_new_ui);
			GET_COMP(name, gui_elem, TCompName);
			name->setName(gui_prebab_entity_name);
		}

		ImGui::TreePop();
	}
	if (ImGui::TreeNode("TestMessages")) {
		static char test_msg_txt[256] = "*MOUSE* *LMOUSE* *RMOUSE*\n*LB* *RB* *BACK* *START* *LSTICK* *RSTICK* *APAD* *BPAD* *XPAD* *YPAD*\n*SHIFT* *ENTER* *SPACE* *ESC* *WKEY* *AKEY* *SKEY* *DKEY*";
		ImGui::InputTextMultiline("Test Message", test_msg_txt, 256);
		if (ImGui::Button("Create Message")) {
			std::string text = test_msg_txt;
			getHandleManager<TCompFadingMessage>()->each([text](TCompFadingMessage * mess) {
				TCompFadingMessage::ReloadInfo atts;
				atts.text = text;
				mess->reload(atts);
			}
			);
		}
		ImGui::TreePop();
	}

	if (ImGui::TreeNode("Free camera instructions")) {
		ImGui::Text("w/a/s/d - normal move\nq/e - up/down\nmouse wheel - speed up/down\n");

		ImGui::TreePop();
	}

	ImGui::Separator();
	//---------------------------------------
#ifdef CALIBRATE_GAME
	if (ImGui::TreeNode("CALIBRATE")) {
		if (ImGui::TreeNode("Bomb sci")) {
			ImGui::Checkbox("Calibrate", &CThrowBomb::calibrate);
			IMGUI_DRAG_FLOAT(CThrowBomb::lmax_st, 0.01f, 0.1f, 10.f);
			IMGUI_DRAG_FLOAT(CThrowBomb::hmax_st, 0.01f, 0.1f, 10.f);
			IMGUI_DRAG_FLOAT(CThrowBomb::speed_st, 0.01f, 0.1f, 10.f);
			IMGUI_DRAG_FLOAT(CThrowBomb::radius_st, 0.01f, 0.1f, 10.f);
			ImGui::DragFloat3("offset start throw", &CThrowBomb::offset_init_throw.x, 0.01f, -1.f, 1.f);
			ImGui::TreePop();
}
		ImGui::TreePop();
}
#endif
	//Profiling
	//---------------------------------------
#ifdef PROFILING_ENABLED
  //header for filtering instructions
	if (ImGui::TreeNode("PROFILING"))
	{
		static int nframes = 5;
		static float time_threshold = 5;
		ImGui::InputInt("NFrames", &nframes, 1, 5);
		ImGui::Separator();
		if (ImGui::Button("Start Capture Profiling"))
			profiler->setNFramesToCapture(nframes);
#ifndef PROFILING_JOHN
		ImGui::Separator();
		ImGui::InputFloat("Time Threshold", &time_threshold, 1, 5);
		if (profiler->isAutoCapture()) {
			ImGui::Text("Waiting auto capture...");
		}
		else {
			if (ImGui::Button("Auto Capture Profiling"))
				profiler->setAutoCapture(nframes, time_threshold);
		}
#endif
		ImGui::TreePop();
	}
#endif
	//---------------------------------------

	//Filter options
	//---------------------------------------
	ImGui::Text("Filtering");

	//header for filtering instructions
	if (ImGui::TreeNode("instructions filtering"))
	{
		ImGui::Text("Filter usage:\n"
			"  \"\"         display all lines\n"
			"  \"xxx\"      display lines containing \"xxx\"\n"
			"  \"xxx,yyy\"  display lines containing \"xxx\" or \"yyy\"\n"
			"  \"-xxx\"     hide lines containing \"xxx\"");
		ImGui::TreePop();
	}
	//end header instructions

	//static ImGuiTextFilter filter;
	filter.Draw(); //filter text draw
	//---------------------------------------

	if (ImGui::CollapsingHeader("General Info")) {
		ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
	}
	if (ImGui::CollapsingHeader("Resources")) {
		Resources.renderUIDebug(&filter);
	}

	if (ImGui::CollapsingHeader("Entities")) {
		getHandleManager<CEntity>()->onAll(&CEntity::renderInMenu);
	}

	if (ImGui::CollapsingHeader("PostProcess")) {
		render_fx->renderInMenu();
	}

	if (ImGui::CollapsingHeader("SELECTED ENTITY")) {
		ImGui::Text("Application SELECTED ENTITY - TODO");
	}if (ImGui::CollapsingHeader("Entity by Tag")) {
		ImGui::Text("Application ENTITY TAG - TODO");
		tags_manager.renderInMenu();
	}
	if (ImGui::CollapsingHeader("Game Options")) {
		ImGui::Checkbox("god mode", GameController->GetCheatGodmodePointer());
	}if (ImGui::CollapsingHeader("Graficos")) {
		if (ImGui::TreeNode("polarize")) {
			//ImGui::SliderFloat("Polarize strength", &shader_ctes_globals.strenght_polarize, 0.0f, 2.0f);

			ImGui::TreePop();
		}

		if (ImGui::TreeNode("Dream shader options")) {
			if (ImGui::DragFloat4("color influence", &shader_ctes_dream.color_influence.x, 0.01f)) {
				shader_ctes_dream.uploadToGPU();
			}
			if (ImGui::DragFloat("waves size", &shader_ctes_dream.dream_waves_size, 0.01f)) {
				shader_ctes_dream.uploadToGPU();
			}
			if (ImGui::DragFloat("waves speed", &shader_ctes_dream.dream_speed, 0.01f)) {
				shader_ctes_dream.uploadToGPU();
			}
			if (ImGui::DragFloat("waves intensity", &shader_ctes_dream.dream_wave_amplitude, 0.01f)) {
				shader_ctes_dream.uploadToGPU();
			}
			if (ImGui::DragFloat("distorsion strenght", &shader_ctes_dream.dream_distorsion_strenght, 0.01f)) {
				shader_ctes_dream.uploadToGPU();
			}
			if (ImGui::DragFloat("distorsion expansion", &shader_ctes_dream.dream_distorsion_expansion, 0.01f)) {
				shader_ctes_dream.uploadToGPU();
			}

			if (ImGui::SmallButton("Load defaults")) {
				shader_ctes_dream.color_influence = VEC4(0.5, 0.5, 0.8, 1);
				shader_ctes_dream.dream_speed = 1;
				shader_ctes_dream.dream_waves_size = 0.5;
				shader_ctes_dream.dream_wave_amplitude = 8;

				shader_ctes_dream.dream_distorsion_expansion = 0.85;
				shader_ctes_dream.dream_distorsion_strenght = 55;
			}

			ImGui::TreePop();
		}

		if (ImGui::TreeNode("Shadow options")) {
			if (ImGui::DragFloat("Environment diffuse factor", &shader_ctes_globals.env_factor, 0.01f)) {
				shader_ctes_globals.uploadToGPU();
			}

			if (ImGui::DragFloat("Shadow intensity", &shader_ctes_globals.shadow_intensity, 0.01f)) {
				shader_ctes_globals.uploadToGPU();
			}

			if (ImGui::TreeNode("ssao")) {
				if (ImGui::DragFloat("ssao intensity", &shader_ctes_blur.ssao_intensity)) {
					shader_ctes_blur.uploadToGPU();
				}

				if (ImGui::DragFloat("ssao iterations", &shader_ctes_blur.ssao_iterations)) {
					shader_ctes_blur.uploadToGPU();
				}

				ImGui::Separator();

				if (ImGui::DragFloat("ssao intensity test", &shader_ctes_blur.ssao_test_intensity, 0.01f)) {
					shader_ctes_blur.uploadToGPU();
				}

				if (ImGui::DragFloat("ssao bias test", &shader_ctes_blur.ssao_bias, 0.01f)) {
					shader_ctes_blur.uploadToGPU();
				}

				if (ImGui::DragFloat("ssao scale test", &shader_ctes_blur.ssao_scale, 0.01f)) {
					shader_ctes_blur.uploadToGPU();
				}

				if (ImGui::DragFloat("ssao rad test", &shader_ctes_blur.ssao_sample_rad, 0.01f)) {
					shader_ctes_blur.uploadToGPU();
				}

				ImGui::TreePop();
			}

			ImGui::TreePop();
		}

		if (ImGui::TreeNode("Grafic options")) {
			ImGui::Checkbox("polarize effects(disabled)", GameController->GetFxPolarizePointer());

			ImGui::Checkbox("glow effect(disabled)", GameController->GetFxGlowPointer());

			if (ImGui::DragFloat("Specular force", &shader_ctes_hatching.specular_force)) {
				shader_ctes_hatching.uploadToGPU();
			}

			static bool use_ramp = shader_ctes_globals.use_ramp;
			if (ImGui::Checkbox("use ramp", &use_ramp)) {
				shader_ctes_globals.use_ramp = use_ramp;
			}

			static bool use_ramp_color = shader_ctes_globals.use_ramp_color;
			if (ImGui::Checkbox("use ramp color", &use_ramp_color)) {
				shader_ctes_globals.use_ramp_color = use_ramp_color;
			}

			ImGui::TreePop();
		}

		if (ImGui::TreeNode("Hatching test")) {
			ImGui::Text("Limit lines hatching (DISABLED, not working)");
			if (ImGui::DragFloat("Rim strength", &shader_ctes_hatching.rim_strenght, 0.1f)) {
				shader_ctes_hatching.uploadToGPU();
			}
			if (ImGui::DragFloat("Specular strength", &shader_ctes_hatching.specular_strenght, 0.1f)) {
				shader_ctes_hatching.uploadToGPU();
			}
			if (ImGui::DragFloat("Diffuse strength", &shader_ctes_hatching.diffuse_strenght, 0.1f)) {
				shader_ctes_hatching.uploadToGPU();
			}

			ImGui::Separator();
			ImGui::Text("Lines hatching options");
			if (ImGui::DragFloat("Size hatching lines", &shader_ctes_hatching.frequency_texture, 0.1f)) {
				shader_ctes_hatching.uploadToGPU();
			}
			if (ImGui::DragFloat("Intensity transparency lines", &shader_ctes_hatching.intensity_sketch, 0.1f)) {
				shader_ctes_hatching.uploadToGPU();
			}
			if (ImGui::DragFloat("Frequency change offset", &shader_ctes_hatching.frequency_offset, 0.1f)) {
				shader_ctes_hatching.uploadToGPU();
			}

			ImGui::Separator();
			ImGui::Text("Outline options");
			ImGui::Text("Quantity lines: more low to more lines. Will do strange things");
			if (ImGui::DragFloat("Quantity lines found", &shader_ctes_hatching.edge_lines_detection, 0.0001f, 0.0000000001f)) {
				shader_ctes_hatching.uploadToGPU();
			}

			ImGui::TreePop();
		}

		if (ImGui::TreeNode("Ramp shading options")) {
			ImGui::Text("Color influence from ramp, will work better with white lights, will mix lights");

			bool color_ramp = false;

			if (shader_ctes_hatching.color_ramp == 0.0f)
				color_ramp = false;
			else
				color_ramp = true;

			if (ImGui::Checkbox("color from ramp", &color_ramp)) {
				if (color_ramp) {
					shader_ctes_hatching.color_ramp = 1.0f;
					shader_ctes_hatching.uploadToGPU();
				}
				else {
					shader_ctes_hatching.color_ramp = 0.0f;
					shader_ctes_hatching.uploadToGPU();
				}
			}

			ImGui::TreePop();
		}
	}if (ImGui::CollapsingHeader("Culling")) {
		RenderManager.renderUICulling(SBB::readSala());
		TCompSkeleton::renderUICulling();
		ImGui::Checkbox("show culling collider", GameController->GetCullingRenderPointer());
	}

	if (ImGui::CollapsingHeader("Particles")) {
		g_particlesManager->renderInMenu();
	}

	ImGui::End();
#endif
	//TESTS DEBUG:
	//TestGameLog();
	//testLines();
	//bool open = true;
	//ShowExampleAppConsole(&open);		//test console commands

	//Debug->update();		//update log
	m_pLights_editor->RenderInMenu();
	m_pMessages_editor->RenderInMenu();
}
예제 #10
0
파일: main.cpp 프로젝트: Atomizer74/AIEMath
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;
}
예제 #11
0
파일: main.cpp 프로젝트: Bia10/hadesmem
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;
}