From 4f91b8081d3fa9f97cdcdfc4be5466f4ec1ed0fb Mon Sep 17 00:00:00 2001 From: David Hackbarth Date: Mon, 9 Nov 2026 15:50:06 +0100 Subject: [PATCH] Add D3D --- GDP/D3D9/Direct3D.cpp | 38 ++++++++++++++++++++++++++++++++++++++ GDP/D3D9/main.cpp | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/GDP/D3D9/Direct3D.cpp b/GDP/D3D9/Direct3D.cpp index fd7e02f..1bc4d0c 100644 --- a/GDP/D3D9/Direct3D.cpp +++ b/GDP/D3D9/Direct3D.cpp @@ -1,28 +1,66 @@ #include "Direct3D.h" +#include "Utilities.h" INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen) { + HRESULT hr = {}; + // 1. create connection to Direct3D API + IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION); + if (pD3D == nullptr) return 200; // 2. check compatibility + D3DCAPS9 caps = {}; + UINT adapter = D3DADAPTER_DEFAULT; // graphic card index, 0 -> primary + D3DDEVTYPE devType = D3DDEVTYPE_HAL; // hardware or software renderer, here hardware + hr = pD3D->GetDeviceCaps(adapter, devType, &caps); + CheckFailed(hr, 210); + + DWORD vertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // fallback if hardware processing is not available + if (caps.VertexProcessingCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) + vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING; // hardware processing is available // 3. define presentation parameters + D3DPRESENT_PARAMETERS pp = {}; + pp.hDeviceWindow = hWnd; // target window + pp.Windowed = !isFullscreen; // window mode yes or no + pp.BackBufferCount = 1; + pp.BackBufferWidth = width; + pp.BackBufferHeight = height; + pp.BackBufferFormat = D3DFMT_A8R8G8B8; // 4 channels, each channel 8bit + pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // what happens with the front buffer after a swap // 4. create Direct3D device + hr = pD3D->CreateDevice(adapter, devType, hWnd, vertexProcessing, &pp, &_pD3DDevice); + CheckFailed(hr, 220); // 5. tidy up + safeRelease(pD3D); return 0; } void Direct3D::beginScene() { + _pD3DDevice->BeginScene(); + + // clear buffers + _pD3DDevice->Clear( + 0, nullptr, // clear regions, here clear everything + D3DCLEAR_TARGET, // which buffers to clear + D3DCOLOR_XRGB(100, 100, 100), 1.0f, 0xffffffff // clear values + ); } void Direct3D::endScene() { + _pD3DDevice->EndScene(); + + // present frame + _pD3DDevice->Present(nullptr, nullptr, nullptr, nullptr); } void Direct3D::deInit() { + safeRelease(_pD3DDevice); } diff --git a/GDP/D3D9/main.cpp b/GDP/D3D9/main.cpp index cc20ea5..2410319 100644 --- a/GDP/D3D9/main.cpp +++ b/GDP/D3D9/main.cpp @@ -16,8 +16,8 @@ int WINAPI WinMain( ) { // some constant values - const UINT width = 640; - const UINT height = 480; + const UINT width = 1024; + const UINT height = 768; const BOOL isFullscreen = FALSE; UINT error = 0; // error code for identifying errors