{"id":10066,"date":"2023-02-01T21:00:00","date_gmt":"2023-02-01T12:00:00","guid":{"rendered":"https:\/\/taki-lab.site\/bocci\/?p=10066"},"modified":"2023-01-31T08:34:58","modified_gmt":"2023-01-30T23:34:58","slug":"direct2d%e3%82%92%e8%a9%a6%e3%81%99%e3%80%81%e3%81%9d%e3%81%ae3","status":"publish","type":"post","link":"https:\/\/taki-lab.site\/bocci\/?p=10066","title":{"rendered":"DIRECT2D\u3092\u8a66\u3059\u3001\u305d\u306e3"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f wp-block-embed-\u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"1I0E6eEbOe\"><a href=\"https:\/\/taki-lab.site\/bocci\/?p=10044\">DIRECT2D\u3092\u8a66\u3059\u3001\u305d\u306e2<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;DIRECT2D\u3092\u8a66\u3059\u3001\u305d\u306e2&#8221; &#8212; \u81ea\u5206\u3001\u307c\u3063\u3061\u3067\u3059\u304c\u4f55\u304b\uff1f\" src=\"https:\/\/taki-lab.site\/bocci\/?p=10044&#038;embed=true#?secret=07tKqpNEdB#?secret=1I0E6eEbOe\" data-secret=\"1I0E6eEbOe\" width=\"474\" height=\"267\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u4eca\u56de\u306fFPS\u3092\u56fa\u5b9a\u5316\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5927\u62b5\u306e\u30b2\u30fc\u30e0\u30a8\u30f3\u30b8\u30f3\u306f\u30a8\u30f3\u30b8\u30f3\u5074\u3067FPS\u3092\u5236\u5fa1\u3057\u3066\u3044\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001<\/p>\n\n\n\n<p>DirectX\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u5b9f\u969b\u306b\u6642\u9593\u3092\u8a08\u6e2c\u3057\u3066\u753b\u9762\u66f4\u65b0\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u8a08\u3089\u306a\u304f\u3061\u3083\u3044\u3051\u306a\u3044\u3093\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\u30b5\u30a4\u30c8\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><a href=\"http:\/\/dioltista.blogspot.com\/2019\/04\/c-directx11-fps.html\" title=\"\">http:\/\/dioltista.blogspot.com\/2019\/04\/c-directx11-fps.html<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>main.h<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#pragma once\r\n\r\n#include &lt;windows.h>\r\n#pragma comment(lib,\"winmm.lib\")\r\n\r\nclass Window\r\n{\r\npublic:\r\n    HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow);\r\n    void InitFps();\r\n    void CalculationFps();\r\n    void CalculationSleep();\r\n    static HWND GethWnd();\r\n    static double GetFps();\r\nprivate:\r\n    static HWND g_hWnd;\r\n    static double g_dFps;\r\n    LARGE_INTEGER Freq = { 0 };\r\n    LARGE_INTEGER StartTime = { 0 };\r\n    LARGE_INTEGER NowTime = { 0 };\r\n    int iCount = 0;\r\n    DWORD SleepTime = 0;\r\n};\r\n<\/code><\/pre>\n\n\n\n<p>main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"Main.h\"\r\n#include \"DirectX.h\"\r\n\r\nHWND Window::g_hWnd = nullptr;\r\ndouble Window::g_dFps = 0;\r\n\r\n\/\/--------------------------------------------------------------------------------------\r\n\/\/ \u524d\u65b9\u5ba3\u8a00\r\n\/\/--------------------------------------------------------------------------------------\r\nLRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);\r\n\r\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\r\n{\r\n    Window win;\r\n\r\n    if (FAILED(win.InitWindow(hInstance, nCmdShow)))\r\n        return 0;\r\n\r\n    DirectX11 dx;\r\n\r\n    if (FAILED(dx.InitDevice()))\r\n        return 0;\r\n\r\n    win.InitFps();\r\n\r\n    \/\/ \u30e1\u30a4\u30f3\u30e1\u30c3\u30bb\u30fc\u30b8\u30eb\u30fc\u30d7\r\n    MSG msg = { 0 };\r\n    while (WM_QUIT != msg.message)\r\n    {\r\n        if (PeekMessage(&amp;msg, nullptr, 0, 0, PM_REMOVE))\r\n        {\r\n            TranslateMessage(&amp;msg);\r\n            DispatchMessage(&amp;msg);\r\n        }\r\n        else\r\n        {\r\n            win.CalculationFps();\r\n\r\n            dx.Render();\r\n\r\n            win.CalculationSleep();\r\n        }\r\n    }\r\n\r\n    return (int)msg.wParam;\r\n}\r\n\r\nLRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r\n{\r\n    PAINTSTRUCT ps;\r\n    HDC hdc;\r\n\r\n    switch (message)\r\n    {\r\n    case WM_PAINT:\r\n        hdc = BeginPaint(hWnd, &amp;ps);\r\n        EndPaint(hWnd, &amp;ps);\r\n        break;\r\n\r\n    case WM_DESTROY:\r\n        PostQuitMessage(0);\r\n        break;\r\n\r\n    default:\r\n        return DefWindowProc(hWnd, message, wParam, lParam);\r\n    }\r\n\r\n    return 0;\r\n}\r\n\r\nHRESULT Window::InitWindow(HINSTANCE hInstance, int nCmdShow)\r\n{\r\n    WNDCLASSEX wcex;\r\n    wcex.cbSize = sizeof(WNDCLASSEX);\r\n    wcex.style = CS_HREDRAW | CS_VREDRAW;\r\n    wcex.lpfnWndProc = WndProc;\r\n    wcex.cbClsExtra = 0;\r\n    wcex.cbWndExtra = 0;\r\n    wcex.hInstance = hInstance;\r\n    wcex.hIcon = nullptr;\r\n    wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);\r\n    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);\r\n    wcex.lpszMenuName = nullptr;\r\n    wcex.lpszClassName = L\"WindowClass\";\r\n    wcex.hIconSm = nullptr;\r\n    if (!RegisterClassEx(&amp;wcex))\r\n        return E_FAIL;\r\n\r\n    RECT rc = { 0, 0, 800, 600 };\r\n    AdjustWindowRect(&amp;rc, WS_OVERLAPPEDWINDOW, FALSE);\r\n    g_hWnd = CreateWindow(L\"WindowClass\", L\"FPS\u306e\u56fa\u5b9a\",\r\n        WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,\r\n        CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, hInstance,\r\n        nullptr);\r\n    if (!g_hWnd)\r\n        return E_FAIL;\r\n\r\n    ShowWindow(g_hWnd, nCmdShow);\r\n\r\n    return S_OK;\r\n}\r\n\r\nHWND Window::GethWnd()\r\n{\r\n    return g_hWnd;\r\n}\r\n\r\nvoid Window::InitFps()\r\n{\r\n\r\n    QueryPerformanceFrequency(&amp;Freq);\r\n    QueryPerformanceCounter(&amp;StartTime);\/\/\u73fe\u5728\u306e\u6642\u9593\u3092\u53d6\u5f97\uff081\u30d5\u30ec\u30fc\u30e0\u76ee\uff09\r\n}\r\n\r\nvoid Window::CalculationFps()\r\n{\r\n    \/\/FPS\u306e\u8a08\u7b97\r\n    if (iCount == 60)\/\/\u30ab\u30a6\u30f3\u30c8\u304c60\u306e\u6642\u306e\u51e6\u7406\r\n    {\r\n        QueryPerformanceCounter(&amp;NowTime);\/\/\u73fe\u5728\u306e\u6642\u9593\u3092\u53d6\u5f97\uff0860\u30d5\u30ec\u30fc\u30e0\u76ee\uff09\r\n        \/\/FPS = 1\u79d2 \/ 1\u30d5\u30ec\u30fc\u30e0\u306e\u63cf\u753b\u306b\u304b\u304b\u308b\u6642\u9593\r\n        \/\/    = 1000ms \/ ((\u73fe\u5728\u306e\u6642\u9593ms - 1\u30d5\u30ec\u30fc\u30e0\u76ee\u306e\u6642\u9593ms) \/ 60\u30d5\u30ec\u30fc\u30e0)\r\n        g_dFps = 1000.0 \/ (static_cast&lt;double>((NowTime.QuadPart - StartTime.QuadPart) * 1000 \/ Freq.QuadPart) \/ 60.0);\r\n        iCount = 0;\/\/\u30ab\u30a6\u30f3\u30c8\u3092\u521d\u671f\u5024\u306b\u623b\u3059\r\n        StartTime = NowTime;\/\/1\u30d5\u30ec\u30fc\u30e0\u76ee\u306e\u6642\u9593\u3092\u73fe\u5728\u306e\u6642\u9593\u306b\u3059\u308b\r\n    }\r\n    iCount++;\/\/\u30ab\u30a6\u30f3\u30c8+1\r\n}\r\n\r\nvoid Window::CalculationSleep()\r\n{\r\n    \/\/Sleep\u3055\u305b\u308b\u6642\u9593\u306e\u8a08\u7b97\r\n    QueryPerformanceCounter(&amp;NowTime);\/\/\u73fe\u5728\u306e\u6642\u9593\u3092\u53d6\u5f97\r\n    \/\/Sleep\u3055\u305b\u308b\u6642\u9593ms = 1\u30d5\u30ec\u30fc\u30e0\u76ee\u304b\u3089\u73fe\u5728\u306e\u30d5\u30ec\u30fc\u30e0\u307e\u3067\u306e\u63cf\u753b\u306b\u304b\u304b\u308b\u3079\u304d\u6642\u9593ms - 1\u30d5\u30ec\u30fc\u30e0\u76ee\u304b\u3089\u73fe\u5728\u306e\u30d5\u30ec\u30fc\u30e0\u307e\u3067\u5b9f\u969b\u306b\u304b\u304b\u3063\u305f\u6642\u9593ms\r\n    \/\/                  = (1000ms \/ 60)*\u30d5\u30ec\u30fc\u30e0\u6570 - (\u73fe\u5728\u306e\u6642\u9593ms - 1\u30d5\u30ec\u30fc\u30e0\u76ee\u306e\u6642\u9593ms)\r\n    SleepTime = static_cast&lt;DWORD>((1000.0 \/ 60.0) * iCount - (NowTime.QuadPart - StartTime.QuadPart) * 1000 \/ Freq.QuadPart);\r\n    if (SleepTime > 0 &amp;&amp; SleepTime &lt; 18)\/\/\u5927\u304d\u304f\u5909\u52d5\u304c\u306a\u3051\u308c\u3070SleepTime\u306f1\uff5e17\u306e\u9593\u306b\u7d0d\u307e\u308b\r\n    {\r\n        timeBeginPeriod(1);\r\n        Sleep(SleepTime);\r\n        timeEndPeriod(1);\r\n    }\r\n    else\/\/\u5927\u304d\u304f\u5909\u52d5\u304c\u3042\u3063\u305f\u5834\u5408\r\n    {\r\n        timeBeginPeriod(1);\r\n        Sleep(1);\r\n        timeEndPeriod(1);\r\n    }\r\n}\r\n\r\ndouble Window::GetFps()\r\n{\r\n    return g_dFps;\r\n}<\/code><\/pre>\n\n\n\n<p>DirectX.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#pragma once\r\n\r\n#pragma comment(lib,\"d3d11.lib\")\r\n#pragma comment(lib,\"d2d1.lib\")\r\n#pragma comment(lib,\"dwrite.lib\")\r\n#include &lt;d3d11_1.h>\r\n#include &lt;directxcolors.h>\r\n#include &lt;d2d1.h>\r\n#include &lt;dwrite.h>\r\n#include &lt;wchar.h>\r\n\r\nclass DirectX11\r\n{\r\npublic:\r\n    DirectX11();\r\n    ~DirectX11();\r\n    HRESULT InitDevice();\r\n    void Render();\r\nprivate:\r\n    ID3D11Device* pd3dDevice;\r\n    ID3D11Device1* pd3dDevice1;\r\n    ID3D11DeviceContext* pImmediateContext;\r\n    ID3D11DeviceContext1* pImmediateContext1;\r\n    IDXGISwapChain* pSwapChain;\r\n    IDXGISwapChain1* pSwapChain1;\r\n    ID3D11RenderTargetView* pRenderTargetView;\r\n\r\n    ID2D1Factory* pD2DFactory;\r\n    IDWriteFactory* pDWriteFactory;\r\n    IDWriteTextFormat* pTextFormat;\r\n    ID2D1RenderTarget* pRT;\r\n    ID2D1SolidColorBrush* pSolidBrush;\r\n    IDXGISurface* pDXGISurface;\r\n};\r\n<\/code><\/pre>\n\n\n\n<p>DirectX.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"Main.h\"\r\n#include \"DirectX.h\"\r\n\r\nDirectX11::DirectX11()\r\n{\r\n    pd3dDevice = nullptr;\r\n    pd3dDevice1 = nullptr;\r\n    pImmediateContext = nullptr;\r\n    pImmediateContext1 = nullptr;\r\n    pSwapChain = nullptr;\r\n    pSwapChain1 = nullptr;\r\n    pRenderTargetView = nullptr;\r\n\r\n    pD2DFactory = nullptr;\r\n    pDWriteFactory = nullptr;\r\n    pTextFormat = nullptr;\r\n    pRT = nullptr;\r\n    pSolidBrush = nullptr;\r\n    pDXGISurface = nullptr;\r\n}\r\n\r\nDirectX11::~DirectX11()\r\n{\r\n    if (pDXGISurface) pDXGISurface->Release();\r\n    if (pSolidBrush) pSolidBrush->Release();\r\n    if (pRT) pRT->Release();\r\n    if (pTextFormat) pTextFormat->Release();\r\n    if (pDWriteFactory) pDWriteFactory->Release();\r\n    if (pD2DFactory) pD2DFactory->Release();\r\n\r\n    if (pImmediateContext) pImmediateContext->ClearState();\r\n\r\n    if (pRenderTargetView) pRenderTargetView->Release();\r\n    if (pSwapChain1) pSwapChain1->Release();\r\n    if (pSwapChain) pSwapChain->Release();\r\n    if (pImmediateContext1) pImmediateContext1->Release();\r\n    if (pImmediateContext) pImmediateContext->Release();\r\n    if (pd3dDevice1) pd3dDevice1->Release();\r\n    if (pd3dDevice) pd3dDevice->Release();\r\n}\r\n\r\nHRESULT DirectX11::InitDevice()\r\n{\r\n    HRESULT hr = S_OK;\r\n\r\n    RECT rc;\r\n    GetClientRect(Window::GethWnd(), &amp;rc);\r\n    UINT width = rc.right - rc.left;\r\n    UINT height = rc.bottom - rc.top;\r\n\r\n    UINT createDeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;\r\n\r\n#ifdef _DEBUG\r\n    createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;\r\n#endif\r\n\r\n    D3D_DRIVER_TYPE driverTypes&#91;] =\r\n    {\r\n        D3D_DRIVER_TYPE_HARDWARE,\r\n        D3D_DRIVER_TYPE_WARP,\r\n        D3D_DRIVER_TYPE_REFERENCE,\r\n    };\r\n    UINT numDriverTypes = ARRAYSIZE(driverTypes);\r\n\r\n    D3D_FEATURE_LEVEL featureLevels&#91;] =\r\n    {\r\n        D3D_FEATURE_LEVEL_11_1,\r\n        D3D_FEATURE_LEVEL_11_0,\r\n        D3D_FEATURE_LEVEL_10_1,\r\n        D3D_FEATURE_LEVEL_10_0,\r\n    };\r\n    UINT numFeatureLevels = ARRAYSIZE(featureLevels);\r\n\r\n    D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;\r\n    D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;\r\n    for (UINT driverTypeIndex = 0; driverTypeIndex &lt; numDriverTypes; driverTypeIndex++)\r\n    {\r\n        g_driverType = driverTypes&#91;driverTypeIndex];\r\n        hr = D3D11CreateDevice(nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,\r\n            D3D11_SDK_VERSION, &amp;pd3dDevice, &amp;g_featureLevel, &amp;pImmediateContext);\r\n\r\n        if (hr == E_INVALIDARG)\r\n        {\r\n            hr = D3D11CreateDevice(nullptr, g_driverType, nullptr, createDeviceFlags, &amp;featureLevels&#91;1], numFeatureLevels - 1,\r\n                D3D11_SDK_VERSION, &amp;pd3dDevice, &amp;g_featureLevel, &amp;pImmediateContext);\r\n        }\r\n\r\n        if (SUCCEEDED(hr))\r\n            break;\r\n    }\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    IDXGIFactory1* dxgiFactory = nullptr;\r\n    {\r\n        IDXGIDevice* dxgiDevice = nullptr;\r\n        hr = pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast&lt;void**>(&amp;dxgiDevice));\r\n        if (SUCCEEDED(hr))\r\n        {\r\n            IDXGIAdapter* adapter = nullptr;\r\n            hr = dxgiDevice->GetAdapter(&amp;adapter);\r\n            if (SUCCEEDED(hr))\r\n            {\r\n                hr = adapter->GetParent(__uuidof(IDXGIFactory1), reinterpret_cast&lt;void**>(&amp;dxgiFactory));\r\n                adapter->Release();\r\n            }\r\n            dxgiDevice->Release();\r\n        }\r\n    }\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    IDXGIFactory2* dxgiFactory2 = nullptr;\r\n    hr = dxgiFactory->QueryInterface(__uuidof(IDXGIFactory2), reinterpret_cast&lt;void**>(&amp;dxgiFactory2));\r\n    if (dxgiFactory2)\r\n    {\r\n        hr = pd3dDevice->QueryInterface(__uuidof(ID3D11Device1), reinterpret_cast&lt;void**>(&amp;pd3dDevice1));\r\n        if (SUCCEEDED(hr))\r\n        {\r\n            (void)pImmediateContext->QueryInterface(__uuidof(ID3D11DeviceContext1), reinterpret_cast&lt;void**>(&amp;pImmediateContext1));\r\n        }\r\n\r\n        DXGI_SWAP_CHAIN_DESC1 sd = {};\r\n        sd.Width = width;\r\n        sd.Height = height;\r\n        sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;\r\n        sd.SampleDesc.Count = 1;\r\n        sd.SampleDesc.Quality = 0;\r\n        sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;\r\n        sd.BufferCount = 1;\r\n\r\n        hr = dxgiFactory2->CreateSwapChainForHwnd(pd3dDevice, Window::GethWnd(), &amp;sd, nullptr, nullptr, &amp;pSwapChain1);\r\n        if (SUCCEEDED(hr))\r\n        {\r\n            hr = pSwapChain1->QueryInterface(__uuidof(IDXGISwapChain), reinterpret_cast&lt;void**>(&amp;pSwapChain));\r\n        }\r\n\r\n        dxgiFactory2->Release();\r\n    }\r\n    else\r\n    {\r\n        DXGI_SWAP_CHAIN_DESC sd = {};\r\n        sd.BufferCount = 1;\r\n        sd.BufferDesc.Width = width;\r\n        sd.BufferDesc.Height = height;\r\n        sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;\r\n        sd.BufferDesc.RefreshRate.Numerator = 60;\r\n        sd.BufferDesc.RefreshRate.Denominator = 1;\r\n        sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;\r\n        sd.OutputWindow = Window::GethWnd();\r\n        sd.SampleDesc.Count = 1;\r\n        sd.SampleDesc.Quality = 0;\r\n        sd.Windowed = TRUE;\r\n\r\n        hr = dxgiFactory->CreateSwapChain(pd3dDevice, &amp;sd, &amp;pSwapChain);\r\n    }\r\n\r\n    dxgiFactory->MakeWindowAssociation(Window::GethWnd(), DXGI_MWA_NO_ALT_ENTER);\r\n\r\n    dxgiFactory->Release();\r\n\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    ID3D11Texture2D* pBackBuffer = nullptr;\r\n    hr = pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast&lt;void**>(&amp;pBackBuffer));\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    hr = pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &amp;pRenderTargetView);\r\n    pBackBuffer->Release();\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    pImmediateContext->OMSetRenderTargets(1, &amp;pRenderTargetView, nullptr);\r\n\r\n    D3D11_VIEWPORT vp;\r\n    vp.Width = (FLOAT)width;\r\n    vp.Height = (FLOAT)height;\r\n    vp.MinDepth = 0.0f;\r\n    vp.MaxDepth = 1.0f;\r\n    vp.TopLeftX = 0;\r\n    vp.TopLeftY = 0;\r\n    pImmediateContext->RSSetViewports(1, &amp;vp);\r\n\r\n    \/\/ Direct2D,DirectWrite\u306e\u521d\u671f\u5316\r\n    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &amp;pD2DFactory);\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    hr = pSwapChain->GetBuffer(0, IID_PPV_ARGS(&amp;pDXGISurface));\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    FLOAT dpiX;\r\n    FLOAT dpiY;\r\n    \/\/pD2DFactory->GetDesktopDpi(&amp;dpiX, &amp;dpiY);\r\n    dpiX = (FLOAT)GetDpiForWindow(GetDesktopWindow());\r\n    dpiY = dpiX;\r\n\r\n    D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), dpiX, dpiY);\r\n\r\n    hr = pD2DFactory->CreateDxgiSurfaceRenderTarget(pDXGISurface, &amp;props, &amp;pRT);\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast&lt;IUnknown**>(&amp;pDWriteFactory));\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    \/\/\u95a2\u6570CreateTextFormat()\r\n    \/\/\u7b2c1\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u540d\uff08L\"\u30e1\u30a4\u30ea\u30aa\", L\"Arial\", L\"Meiryo UI\"\u7b49\uff09\r\n    \/\/\u7b2c2\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08nullptr\uff09\r\n    \/\/\u7b2c3\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u306e\u592a\u3055\uff08DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_WEIGHT_BOLD\u7b49\uff09\r\n    \/\/\u7b2c4\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u30b9\u30bf\u30a4\u30eb\uff08DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STYLE_OBLIQUE, DWRITE_FONT_STYLE_ITALIC\uff09\r\n    \/\/\u7b2c5\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u306e\u5e45\uff08DWRITE_FONT_STRETCH_NORMAL,DWRITE_FONT_STRETCH_EXTRA_EXPANDED\u7b49\uff09\r\n    \/\/\u7b2c6\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\uff0820, 30\u7b49\uff09\r\n    \/\/\u7b2c7\u5f15\u6570\uff1a\u30ed\u30b1\u30fc\u30eb\u540d\uff08L\"\"\uff09\r\n    \/\/\u7b2c8\u5f15\u6570\uff1a\u30c6\u30ad\u30b9\u30c8\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\uff08&amp;g_pTextFormat\uff09\r\n    hr = pDWriteFactory->CreateTextFormat(L\"\u30e1\u30a4\u30ea\u30aa\", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 20, L\"\", &amp;pTextFormat);\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    \/\/\u95a2\u6570SetTextAlignment()\r\n    \/\/\u7b2c1\u5f15\u6570\uff1a\u30c6\u30ad\u30b9\u30c8\u306e\u914d\u7f6e\uff08DWRITE_TEXT_ALIGNMENT_LEADING\uff1a\u524d, DWRITE_TEXT_ALIGNMENT_TRAILING\uff1a\u5f8c, DWRITE_TEXT_ALIGNMENT_CENTER\uff1a\u4e2d\u592e\uff09\r\n    hr = pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    \/\/\u95a2\u6570CreateSolidColorBrush()\r\n    \/\/\u7b2c1\u5f15\u6570\uff1a\u30d5\u30a9\u30f3\u30c8\u8272\uff08D2D1::ColorF(D2D1::ColorF::Black)\uff1a\u9ed2, D2D1::ColorF(D2D1::ColorF(0.0f, 0.2f, 0.9f, 1.0f))\uff1aRGBA\u6307\u5b9a\uff09\r\n    hr = pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &amp;pSolidBrush);\r\n    if (FAILED(hr))\r\n        return hr;\r\n\r\n    return S_OK;\r\n}\r\n\r\nvoid DirectX11::Render()\r\n{\r\n    pImmediateContext->ClearRenderTargetView(pRenderTargetView, DirectX::Colors::Aquamarine);\r\n\r\n    \/\/ \u30c6\u30ad\u30b9\u30c8\u306e\u63cf\u753b\r\n    WCHAR wcText1&#91;256] = { 0 };\r\n\r\n    swprintf(wcText1, 256, L\"%lf\", Window::GetFps());\r\n\r\n    pRT->BeginDraw();\r\n    pRT->DrawText(wcText1, ARRAYSIZE(wcText1) - 1, pTextFormat, D2D1::RectF(0, 0, 800, 20), pSolidBrush, D2D1_DRAW_TEXT_OPTIONS_NONE);\r\n    pRT->EndDraw();\r\n\r\n    pSwapChain->Present(0, 0);\r\n}\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"379\" data-attachment-id=\"10068\" data-permalink=\"https:\/\/taki-lab.site\/bocci\/?attachment_id=10068\" data-orig-file=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?fit=1029%2C822&amp;ssl=1\" data-orig-size=\"1029,822\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"3207a23d6246495e53b7dfc207a68a47\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?fit=474%2C379&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?resize=474%2C379&#038;ssl=1\" alt=\"\" class=\"wp-image-10068\" srcset=\"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?resize=1024%2C818&amp;ssl=1 1024w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?resize=300%2C240&amp;ssl=1 300w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?resize=768%2C614&amp;ssl=1 768w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?w=1029&amp;ssl=1 1029w, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2023\/01\/3207a23d6246495e53b7dfc207a68a47.png?w=948&amp;ssl=1 948w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<a href=\"https:\/\/blog.with2.net\/link\/?id=2023426&#038;cid=9200\" title=\"\u65e5\u3005\u306e\u51fa\u6765\u4e8b\u30e9\u30f3\u30ad\u30f3\u30b0\" target=\"_blank\" rel=\"noopener\"><image src=\"https:\/\/taki-lab.site\/bocci\/wp-content\/uploads\/2022\/11\/99c62cdd0038c9d3b540e561ee138b82-1.jpg\"><\/a>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fFPS\u3092\u56fa\u5b9a\u5316\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u307e\u3059\u3002 \u5927\u62b5\u306e\u30b2\u30fc\u30e0\u30a8\u30f3\u30b8\u30f3\u306f\u30a8\u30f3\u30b8\u30f3\u5074\u3067FPS\u3092\u5236\u5fa1\u3057\u3066\u3044\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001 DirectX\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u5b9f\u969b\u306b\u6642\u9593\u3092\u8a08\u6e2c\u3057\u3066\u753b\u9762\u66f4\u65b0\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u8a08\u3089\u306a\u304f\u3061\u3083\u3044\u3051\u306a\u3044\u3093\u3067\u3059\u306d\u3002  &hellip; <a href=\"https:\/\/taki-lab.site\/bocci\/?p=10066\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">DIRECT2D\u3092\u8a66\u3059\u3001\u305d\u306e3<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[],"class_list":["post-10066","post","type-post","status-publish","format-standard","hentry","category-3"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8SDbY-2Cm","jetpack-related-posts":[{"id":886,"url":"https:\/\/taki-lab.site\/bocci\/?p=886","url_meta":{"origin":10066,"position":0},"title":"\u3010C\u8a00\u8a9e\u3011\u6700\u521d\u306e\u30d7\u30ed\u30b0\u30e9\u30e0","author":"taki","date":"2019\u5e742\u670827\u65e5","format":false,"excerpt":"\u524d\u3005\u304b\u3089\u3084\u308d\u3046\u3068\u601d\u3063\u3066\u3044\u305f\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u30ec\u30af\u30c1\u30e3\u30fc\u3059\u308b\u8a18\u4e8b\u3092\u66f8\u304d\u305f\u304b\u3063\u305f\u3002 \u306a\u306e\u3067\u3001\u307e\u305a\u306fC\u8a00\u8a9e\u2026","rel":"","context":"C\u8a00\u8a9e","block_context":{"text":"C\u8a00\u8a9e","link":"https:\/\/taki-lab.site\/bocci\/?cat=90"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2019\/02\/fb27ee94eb59a144a140b30e1ce4b25a.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2019\/02\/fb27ee94eb59a144a140b30e1ce4b25a.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2019\/02\/fb27ee94eb59a144a140b30e1ce4b25a.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2019\/02\/fb27ee94eb59a144a140b30e1ce4b25a.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2019\/02\/fb27ee94eb59a144a140b30e1ce4b25a.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":2226,"url":"https:\/\/taki-lab.site\/bocci\/?p=2226","url_meta":{"origin":10066,"position":1},"title":"\u3010Laravel\u3011\u3010\u30db\u30c6\u30eb\u4e88\u7d04\u7ba1\u7406\u3011\u6b21\u306e\u8ab2\u984c\u306f\u3001\u81ea\u52d5\u6c7a\u6e08\u3092\u53ef\u80fd\u306b\u3059\u308b\u3002","author":"taki","date":"2020\u5e741\u670825\u65e5","format":false,"excerpt":"\u3055\u3066\u3001\u304a\u6b21\u306e\u8ab2\u984c\u306f\u3001\u81ea\u52d5\u6c7a\u6e08\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3001\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002 \u5177\u4f53\u7684\u306b\u306f\u3001 \u30af\u30ec\u30b8\u30c3\u30c8\u60c5\u5831\u3092\u767b\u9332\u3059\u2026","rel":"","context":"Laravel","block_context":{"text":"Laravel","link":"https:\/\/taki-lab.site\/bocci\/?cat=167"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":412,"url":"https:\/\/taki-lab.site\/bocci\/?p=412","url_meta":{"origin":10066,"position":2},"title":"\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3046\u3068\u304d\u306f\u3001\u304a\u4f5c\u6cd5\u3092\u30de\u30b9\u30bf\u30fc\u3057\u3088\u3046\uff01","author":"taki","date":"2018\u5e744\u67082\u65e5","format":false,"excerpt":"\u305f\u3068\u3048\u3070\u3001 PHP\u306eLaravel\u3068\u304b\u3001cakePHP\u3068\u304b\u3001 Javascript\u306eVue.js\u3068\u304b\u2026","rel":"","context":"\u6280\u8853","block_context":{"text":"\u6280\u8853","link":"https:\/\/taki-lab.site\/bocci\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10077,"url":"https:\/\/taki-lab.site\/bocci\/?p=10077","url_meta":{"origin":10066,"position":3},"title":"IT\u30cb\u30e5\u30fc\u30b9(02\/01)","author":"taki","date":"2023\u5e742\u67081\u65e5","format":false,"excerpt":"Discord\u3092\u8d77\u52d5\u3057\u3066\u3044\u308b\u3068\u30b2\u30fc\u30e0\u6027\u80fd\u304c\u4f4e\u4e0b\u3059\u308b\u4e0d\u5177\u5408\u3002GeForce\u74b0\u5883\u3067\u767a\u751f\u3002\u5bfe\u51e6\u65b9\u6cd5\u30fb\u56de\u907f\u7b56\u2026","rel":"","context":"\u30cb\u30e5\u30fc\u30b9","block_context":{"text":"\u30cb\u30e5\u30fc\u30b9","link":"https:\/\/taki-lab.site\/bocci\/?cat=106"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2315,"url":"https:\/\/taki-lab.site\/bocci\/?p=2315","url_meta":{"origin":10066,"position":4},"title":"\u3010Laravel\u3011\u3010\u30db\u30c6\u30eb\u4e88\u7d04\u7ba1\u7406\u3011\u89e3\u9320\u30ca\u30f3\u30d0\u30fc\u3092QR\u30b3\u30fc\u30c9\u306b\u5909\u63db\u3059\u308b","author":"taki","date":"2020\u5e742\u67087\u65e5","format":false,"excerpt":"\u524d\u56de\u307e\u3067\u306e\u72b6\u6cc1\u306f\u3053\u3061\u3089\u3002 https:\/\/taki-lab.site\/bocci\/?p=2301 \u6700\u2026","rel":"","context":"Laravel","block_context":{"text":"Laravel","link":"https:\/\/taki-lab.site\/bocci\/?cat=167"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2020\/02\/Screenshot_20200207-100719.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2020\/02\/Screenshot_20200207-100719.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2020\/02\/Screenshot_20200207-100719.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2020\/02\/Screenshot_20200207-100719.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2020\/02\/Screenshot_20200207-100719.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":900,"url":"https:\/\/taki-lab.site\/bocci\/?p=900","url_meta":{"origin":10066,"position":5},"title":"\u3010C\u8a00\u8a9e\u3011\u5909\u6570","author":"taki","date":"2019\u5e743\u67083\u65e5","format":false,"excerpt":"\u5909\u6570\u3068\u306f\u3001\u8a08\u7b97\u4e2d\u306e\u5024\u3092\u4e00\u6642\u7684\u306b\u4fdd\u7ba1\u3059\u308b\u5165\u308c\u7269\u3067\u3059\u3002 \u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u2026","rel":"","context":"C\u8a00\u8a9e","block_context":{"text":"C\u8a00\u8a9e","link":"https:\/\/taki-lab.site\/bocci\/?cat=90"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/taki-lab.site\/bocci\/wp-content\/uploads\/2019\/03\/eca1053c8c8c900d15caa9ba9882bcf0.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/10066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10066"}],"version-history":[{"count":1,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/10066\/revisions"}],"predecessor-version":[{"id":10069,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=\/wp\/v2\/posts\/10066\/revisions\/10069"}],"wp:attachment":[{"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taki-lab.site\/bocci\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}