add frame rendering

This commit is contained in:
2025-09-10 10:05:09 +02:00
parent 4fd52c1567
commit 417b951112
2 changed files with 24 additions and 2 deletions
+19
View File
@@ -1,5 +1,6 @@
#include "Direct3D.h"
#include "Utilities.h"
#include <random>
INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen)
{
@@ -50,10 +51,28 @@ INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen)
void Direct3D::beginScene()
{
_pD3DDevice->BeginScene(); // init a frame, after this call we are allowed to do draw calls
// change background color
static std::default_random_engine e;
static std::uniform_int_distribution<int> d(0, 255);
_pD3DDevice->Clear(
0, nullptr, // areas to clear, null -> everything
D3DCLEAR_TARGET, // what to clear, bitmask
// how to clean
//D3DCOLOR_XRGB(d(e), d(e), d(e)), //random color
//D3DCOLOR_XRGB(255, 0, 0), // red color
D3DCOLOR_XRGB(0, 0, 0), // black color
1.0f, 0xFFFFFFFF
);
}
void Direct3D::endScene()
{
_pD3DDevice->EndScene(); // close a frame, after this call we are not allowed to do draw calls
_pD3DDevice->Present(nullptr, nullptr, nullptr, nullptr); // swap back- with frontbuffer
}
void Direct3D::deInit()
+5 -2
View File
@@ -16,12 +16,15 @@ INT Window::init(HINSTANCE hInstance, UINT width, UINT height)
if (!RegisterClass(&wc)) return 100;
// 3. adjust window size (optional)
DWORD style;
style = WS_OVERLAPPEDWINDOW; // window with border & title
//style = WS_POPUP; // borderless window
// 4. create window instance
_hWnd = CreateWindow(
wc.lpszClassName, // class name for window instance
wc.lpszClassName, // window title
WS_OVERLAPPEDWINDOW, // visual window style
style, // visual window style
100, 100, // window position (left-top corner)
width, height, // window size
nullptr, // handle to parent window
@@ -75,7 +78,7 @@ LRESULT WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
if (wParam == VK_ESCAPE)
{
DestroyWindow(hWnd);
return 0;