์์ :)
https://github.com/eazuooz/WindowAPI/commit/d17c2e8e757274a803f76cb94fb4bb7feee67504
Duble Buffering · eazuooz/WindowAPI@d17c2e8
Show file tree Showing 13 changed files with 181 additions and 18 deletions.
github.com
์ฐ๋ฆฌ ํ๋ ์์ํฌ์๋ ๋ฌธ์ ์ ์ด ํ๋ ์๋ค.
์ฐ๋ฆฌ๊ฐ ๋นํธ๋งต ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ๊ทธ๋ฆผ์ ๊ทธ๋ฆฌ๋ ์์ ์ ๊ทธ๋ฆผ์ ์ฝ๋ ์์ ์ ๋นํด ํจ์ฌ ๋๋ฆฌ๋ค๋
๋จ์ ์ด ์๋ค.
๋ํ ์ค์๊ฐ์ผ๋ก ์ง์์ฃผ๊ณ ๋ค์ ๊ทธ๋ฆฌ๊ณ ์ง์์ฃผ๊ณ ๋ค์๊ทธ๋ฆฌ๊ณ ๋ฅผ ๋ฐ๋ณตํ๋ค ๋ณด๋ฉด ๊น๋นก๊ฑฐ๋ฆผ ํ์์ด ์ผ์ด๋๊ฒ ๋๋ค.
์ด๋ฌํ Flicking ํ์์ ํด๊ฒฐํ๊ธฐ ์ํด ๋๋ธ ๋ฒํผ๋ง์ ์ฌ์ฉํ๋ค.
์๋ก์ด HDC์ ๋ฐฐ๊ฒฝ์ธ BITMAP ์ ๋ง๋ค์ด์ค๋ค.
๋ง๋ค๊ธฐ์ ์์ ์ค์ ์๋์ฐ ํฌ๊ธฐ์ ์ค์ ์์ ์์ญ์ด ๋ค๋ฅด๋ค.
์ฐ๋ฆฌ๊ฐ ์์ฑํ ์๋์ฐ ์์ญ์ ๋ธ๋ผ์ฐ์ ์๋จ์์ญ ๋ฐ ๊ทธ์ธ ์ข์ฐ ๋ฐ๋ฑ ์๋์ฐ ์ ์ฒด์์ญ์ ๊ธฐ์ค์ผ๋ก ํฌ๊ธฐ๋ฅผ
์ ํ์ฌ ์๋์ฐ์ฐฝ์ ๋ง๋ค์ด ์ฃผ์๋ค.
AdjustWindowRectํจ์๋ฅผ ์ด์ฉํ๋ฉด ์ค์ ์์ ์์ญ์ ํฌ๊ธฐ๋ฅผ ์ง์ ํด์ค์ ์๋ค.
bool Application::InitializeWindow(WindowData& data)
{
mWindowData.hWnd = data.hWnd;
mWindowData.hdc = GetDC(mWindowData.hWnd);
mWindowData.width = data.width;
mWindowData.height = data.height;
// ๋นํธ๋งต ํด์๋๋ฅผ ์ค์ ํ๊ธฐ ์ํ ์ค์ ์๋์ฐ ํฌ๊ธฐ ๊ณ์ฐ
RECT rect = { 0, 0, mWindowData.width, mWindowData.height };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);
// ์๋์ฐ ํฌ๊ธฐ ๋ณ๊ฒฝ ๋ฐ ์ถ๋ ฅ ์ค์
SetWindowPos(mWindowData.hWnd
, nullptr, 0, 0
, rect.right - rect.left
, rect.bottom - rect.top
, 0);
ShowWindow(mWindowData.hWnd, true);
// ์ด์ค ๋ฒํผ๋ง
// ์๋์ฐ ํด์๋์ ๋์ผํ ํฌ๊ธฐ์ ๋นํธ๋งต์ ์์ฑ
// ์๋ก ์์ฑํ ๋นํธ๋งต์ ๊ฐ๋ฆฌํค๋ ์ ์ฉ DC ์์ฑ
// ์์ ์์ฑํ ๋นํธ๋งต๊ณผ DC ๋ฅผ ์๋ก ์ฐ๊ฒฐ
mWindowData.backTexture
= CreateCompatibleBitmap(mWindowData.hdc, mWindowData.width, mWindowData.height);
mWindowData.backBuffer = CreateCompatibleDC(mWindowData.hdc);
HBITMAP defaultBitmap = (HBITMAP)SelectObject(mWindowData.backBuffer, mWindowData.backTexture);
DeleteObject(defaultBitmap);
return true;
}
์ด์ backBuffer์ ๋ฌผ์ฒด๋ฅผ ๊ทธ๋ ค์คํ ์๋ buffer์ ๋ณต์ฌํด์ ํ๋ฒ์ ๊ทธ๋ฆด์ ์๊ฒ ๋์๋ค.
๋๋ธ ๋ฒํผ๋ง์ ์ ์ฉ์์ผ ๋ณด์.
void Application::Tick()
{
// ์
๋ฐ์ดํธ
Time::GetInstance().Tick();
InputManager::GetInstance().Tick();
SceneManager::GetInstance().Tick();
// Clear
Rectangle(mWindowData.backBuffer, -1, -1, mWindowData.width + 1, mWindowData.height + 1);
// ๋ ๋๋ง
SceneManager::GetInstance().Render(mWindowData.backBuffer);
Time::GetInstance().Render(mWindowData.backBuffer);
// BitBlt ํจ์๋ DC ๊ฐ์ ๊ทธ๋ฆผ์ ๋ณต์ฌํ๋ ํจ์์
๋๋ค.
BitBlt(mWindowData.hdc, 0, 0, mWindowData.width, mWindowData.height
, mWindowData.backBuffer, 0, 0, SRCCOPY);
}
'๐ Development Study > ๐ป Win32API' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Path, Resource Load (1) | 2022.09.22 |
---|---|
Resources, Brush, Pen (0) | 2022.09.20 |
Input (0) | 2022.09.15 |
Scene, Object, Time (0) | 2022.09.15 |
Singleton Patten (0) | 2022.09.13 |
๋๊ธ