Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <string>
- #define WIN32_LEAN_AND_MEAN
- #include <Windows.h>
- #include <d3d9.h>
- #include <d3dx9.h>
- #pragma comment (lib, "d3d9.lib")
- #pragma comment (lib, "d3dx9.lib")
- using namespace std;
- using namespace std::literals;
- #define LOG(...) OutputDebugStringA(("MSG: <Test Program> "s + __FUNCTION__ + "(): "s + __VA_ARGS__ + "\n"s).c_str());
- LPDIRECT3D9 d3d;
- LPDIRECT3DDEVICE9 d3ddev;
- LPD3DXFONT d3dfont;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- void render_frame();
- int APIENTRY wWinMain(
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPWSTR lpCmdLine,
- int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- WNDCLASSEXW wcex;
- wcex.cbSize = sizeof(wcex);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = nullptr;
- wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wcex.lpszMenuName = nullptr;
- wcex.lpszClassName = L"DrawTextIssue";
- wcex.hIconSm = nullptr;
- RegisterClassExW(&wcex);
- auto window = CreateWindowW(
- L"DrawTextIssue",
- L"DrawTextIssue",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- 0,
- 800,
- 600,
- nullptr,
- nullptr,
- hInstance,
- nullptr);
- if (!window)
- return FALSE;
- ShowWindow(window, nCmdShow);
- UpdateWindow(window);
- d3d = Direct3DCreate9(D3D_SDK_VERSION);
- D3DPRESENT_PARAMETERS d3dpp;
- ZeroMemory(&d3dpp, sizeof(d3dpp));
- d3dpp.Windowed = TRUE;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = window;
- d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- d3d->CreateDevice(
- D3DADAPTER_DEFAULT,
- D3DDEVTYPE_HAL,
- window,
- D3DCREATE_HARDWARE_VERTEXPROCESSING,
- &d3dpp,
- &d3ddev);
- D3DXCreateFontW(
- d3ddev,
- 20,
- 0,
- FW_NORMAL,
- 1,
- FALSE,
- DEFAULT_CHARSET,
- OUT_DEFAULT_PRECIS,
- ANTIALIASED_QUALITY,
- DEFAULT_PITCH | FF_DONTCARE,
- L"Source Code Pro",
- &d3dfont);
- MSG msg;
- while (1)
- {
- while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- if (msg.message == WM_QUIT)
- break;
- render_frame();
- }
- d3dfont->Release();
- d3ddev->Release();
- d3d->Release();
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- void render_frame()
- {
- LOG("Start of the function."s);
- static auto last = chrono::steady_clock::now();
- static int framesDrawn = 0;
- static auto refreshFPSAt = last + 1s;
- static wstring fps = L"0"s;
- framesDrawn++;
- LOG("Calling chrono::steady_clock::now()"s);
- auto now = chrono::steady_clock::now();
- if (now > refreshFPSAt)
- {
- refreshFPSAt = now + 1s;
- fps = to_wstring(framesDrawn);
- LOG("FPS: "s + to_string(framesDrawn));
- framesDrawn = 0;
- }
- auto secondsPassed = chrono::duration_cast<chrono::nanoseconds>(now - last).count() / 1000000000.0;
- last = now;
- static auto color = 255.0;
- color += secondsPassed * 127.0;
- color = fmod(color, 512.0);
- LOG("d3ddev->Clear()"s);
- d3ddev->Clear(0, nullptr, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, static_cast<int>(color > 256.0 ? 512.0 - color : color)), 1.0f, 0);
- LOG("d3ddev->BeginScene()"s);
- d3ddev->BeginScene();
- RECT textRect{ 0, 0, 100, 100 };
- /*
- * Uncomment that stuff below to trigger the issue.
- */
- //LOG("d3dfont->DrawTextW()"s);
- //d3dfont->DrawTextW(
- // nullptr,
- // L"Hello",
- // -1,
- // &textRect,
- // DT_LEFT | DT_TOP,
- // D3DCOLOR_XRGB(255, 255, 255));
- LOG("d3ddev->EndScene()"s);
- d3ddev->EndScene();
- LOG("d3ddev->Present()"s);
- d3ddev->Present(nullptr, nullptr, nullptr, nullptr);
- //Sleep(500);
- LOG("End of the function."s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement