mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-03 17:24:24 +00:00 
			
		
		
		
	Examples: DirectX9: Minor changes to match the other DirectX examples more closely. (#2394)
This commit is contained in:
		@@ -84,6 +84,7 @@ Other Changes:
 | 
				
			|||||||
- Examples: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN
 | 
					- Examples: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN
 | 
				
			||||||
  even if the OpenGL headers/loader happens to define the value. (#2366, #2186)
 | 
					  even if the OpenGL headers/loader happens to define the value. (#2366, #2186)
 | 
				
			||||||
- Examples: Allegro: Added support for touch events (emulating mouse). (#2219) [@dos1]
 | 
					- Examples: Allegro: Added support for touch events (emulating mouse). (#2219) [@dos1]
 | 
				
			||||||
 | 
					- Examples: DirectX9: Minor changes to match the other DirectX examples more closely. (#2394)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-----------------------------------------------------------------------
 | 
					-----------------------------------------------------------------------
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ static ID3D10RenderTargetView*  g_mainRenderTargetView = NULL;
 | 
				
			|||||||
void CreateRenderTarget()
 | 
					void CreateRenderTarget()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ID3D10Texture2D* pBackBuffer;
 | 
					    ID3D10Texture2D* pBackBuffer;
 | 
				
			||||||
    g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
 | 
					    g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
 | 
				
			||||||
    g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
 | 
					    g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
 | 
				
			||||||
    pBackBuffer->Release();
 | 
					    pBackBuffer->Release();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ static ID3D11RenderTargetView*  g_mainRenderTargetView = NULL;
 | 
				
			|||||||
void CreateRenderTarget()
 | 
					void CreateRenderTarget()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ID3D11Texture2D* pBackBuffer;
 | 
					    ID3D11Texture2D* pBackBuffer;
 | 
				
			||||||
    g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
 | 
					    g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
 | 
				
			||||||
    g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
 | 
					    g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
 | 
				
			||||||
    pBackBuffer->Release();
 | 
					    pBackBuffer->Release();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,8 +10,44 @@
 | 
				
			|||||||
#include <tchar.h>
 | 
					#include <tchar.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Data
 | 
					// Data
 | 
				
			||||||
 | 
					static LPDIRECT3D9              g_pD3D = NULL;
 | 
				
			||||||
static LPDIRECT3DDEVICE9        g_pd3dDevice = NULL;
 | 
					static LPDIRECT3DDEVICE9        g_pd3dDevice = NULL;
 | 
				
			||||||
static D3DPRESENT_PARAMETERS    g_d3dpp;
 | 
					static D3DPRESENT_PARAMETERS    g_d3dpp = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					HRESULT CreateDeviceD3D(HWND hWnd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
 | 
				
			||||||
 | 
					        return E_FAIL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Create the D3DDevice
 | 
				
			||||||
 | 
					    ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
 | 
				
			||||||
 | 
					    g_d3dpp.Windowed = TRUE;
 | 
				
			||||||
 | 
					    g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
 | 
				
			||||||
 | 
					    g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
 | 
				
			||||||
 | 
					    g_d3dpp.EnableAutoDepthStencil = TRUE;
 | 
				
			||||||
 | 
					    g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
 | 
				
			||||||
 | 
					    g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;           // Present with vsync
 | 
				
			||||||
 | 
					    //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;   // Present without vsync, maximum unthrottled framerate
 | 
				
			||||||
 | 
					    if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
 | 
				
			||||||
 | 
					        return E_FAIL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return S_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void CleanupDeviceD3D()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
 | 
				
			||||||
 | 
					    if (g_pD3D) { g_pD3D->Release(); g_pD3D = NULL; }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ResetDevice()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ImGui_ImplDX9_InvalidateDeviceObjects();
 | 
				
			||||||
 | 
					    HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
 | 
				
			||||||
 | 
					    if (hr == D3DERR_INVALIDCALL)
 | 
				
			||||||
 | 
					        IM_ASSERT(0);
 | 
				
			||||||
 | 
					    ImGui_ImplDX9_CreateDeviceObjects();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 | 
					extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 | 
				
			||||||
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 | 
					LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 | 
				
			||||||
@@ -24,13 +60,9 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 | 
				
			|||||||
    case WM_SIZE:
 | 
					    case WM_SIZE:
 | 
				
			||||||
        if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
 | 
					        if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ImGui_ImplDX9_InvalidateDeviceObjects();
 | 
					            g_d3dpp.BackBufferWidth = LOWORD(lParam);
 | 
				
			||||||
            g_d3dpp.BackBufferWidth  = LOWORD(lParam);
 | 
					 | 
				
			||||||
            g_d3dpp.BackBufferHeight = HIWORD(lParam);
 | 
					            g_d3dpp.BackBufferHeight = HIWORD(lParam);
 | 
				
			||||||
            HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
 | 
					            ResetDevice();
 | 
				
			||||||
            if (hr == D3DERR_INVALIDCALL)
 | 
					 | 
				
			||||||
                IM_ASSERT(0);
 | 
					 | 
				
			||||||
            ImGui_ImplDX9_CreateDeviceObjects();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    case WM_SYSCOMMAND:
 | 
					    case WM_SYSCOMMAND:
 | 
				
			||||||
@@ -52,28 +84,16 @@ int main(int, char**)
 | 
				
			|||||||
    HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX9 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
 | 
					    HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX9 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Initialize Direct3D
 | 
					    // Initialize Direct3D
 | 
				
			||||||
    LPDIRECT3D9 pD3D;
 | 
					    if (CreateDeviceD3D(hwnd) < 0)
 | 
				
			||||||
    if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        CleanupDeviceD3D();
 | 
				
			||||||
        UnregisterClass(wc.lpszClassName, wc.hInstance);
 | 
					        UnregisterClass(wc.lpszClassName, wc.hInstance);
 | 
				
			||||||
        return 0;
 | 
					        return 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
 | 
					 | 
				
			||||||
    g_d3dpp.Windowed = TRUE;
 | 
					 | 
				
			||||||
    g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
 | 
					 | 
				
			||||||
    g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
 | 
					 | 
				
			||||||
    g_d3dpp.EnableAutoDepthStencil = TRUE;
 | 
					 | 
				
			||||||
    g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
 | 
					 | 
				
			||||||
    g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync
 | 
					 | 
				
			||||||
    //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Create the D3DDevice
 | 
					    // Show the window
 | 
				
			||||||
    if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
 | 
					    ShowWindow(hwnd, SW_SHOWDEFAULT);
 | 
				
			||||||
    {
 | 
					    UpdateWindow(hwnd);
 | 
				
			||||||
        pD3D->Release();
 | 
					 | 
				
			||||||
        UnregisterClass(wc.lpszClassName, wc.hInstance);
 | 
					 | 
				
			||||||
        return 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Setup Dear ImGui context
 | 
					    // Setup Dear ImGui context
 | 
				
			||||||
    IMGUI_CHECKVERSION();
 | 
					    IMGUI_CHECKVERSION();
 | 
				
			||||||
@@ -104,6 +124,7 @@ int main(int, char**)
 | 
				
			|||||||
    //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
 | 
					    //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
 | 
				
			||||||
    //IM_ASSERT(font != NULL);
 | 
					    //IM_ASSERT(font != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Our state
 | 
				
			||||||
    bool show_demo_window = true;
 | 
					    bool show_demo_window = true;
 | 
				
			||||||
    bool show_another_window = false;
 | 
					    bool show_another_window = false;
 | 
				
			||||||
    ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
 | 
					    ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
 | 
				
			||||||
@@ -111,8 +132,6 @@ int main(int, char**)
 | 
				
			|||||||
    // Main loop
 | 
					    // Main loop
 | 
				
			||||||
    MSG msg;
 | 
					    MSG msg;
 | 
				
			||||||
    ZeroMemory(&msg, sizeof(msg));
 | 
					    ZeroMemory(&msg, sizeof(msg));
 | 
				
			||||||
    ShowWindow(hwnd, SW_SHOWDEFAULT);
 | 
					 | 
				
			||||||
    UpdateWindow(hwnd);
 | 
					 | 
				
			||||||
    while (msg.message != WM_QUIT)
 | 
					    while (msg.message != WM_QUIT)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // Poll and handle messages (inputs, window resize, etc.)
 | 
					        // Poll and handle messages (inputs, window resize, etc.)
 | 
				
			||||||
@@ -186,19 +205,14 @@ int main(int, char**)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Handle loss of D3D9 device
 | 
					        // Handle loss of D3D9 device
 | 
				
			||||||
        if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
 | 
					        if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
 | 
				
			||||||
        {
 | 
					            ResetDevice();
 | 
				
			||||||
            ImGui_ImplDX9_InvalidateDeviceObjects();
 | 
					 | 
				
			||||||
            g_pd3dDevice->Reset(&g_d3dpp);
 | 
					 | 
				
			||||||
            ImGui_ImplDX9_CreateDeviceObjects();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ImGui_ImplDX9_Shutdown();
 | 
					    ImGui_ImplDX9_Shutdown();
 | 
				
			||||||
    ImGui_ImplWin32_Shutdown();
 | 
					    ImGui_ImplWin32_Shutdown();
 | 
				
			||||||
    ImGui::DestroyContext();
 | 
					    ImGui::DestroyContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_pd3dDevice) g_pd3dDevice->Release();
 | 
					    CleanupDeviceD3D();
 | 
				
			||||||
    if (pD3D) pD3D->Release();
 | 
					 | 
				
			||||||
    DestroyWindow(hwnd);
 | 
					    DestroyWindow(hwnd);
 | 
				
			||||||
    UnregisterClass(wc.lpszClassName, wc.hInstance);
 | 
					    UnregisterClass(wc.lpszClassName, wc.hInstance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user