GameChoi
Choi Programming
GameChoi
전체 방문자
오늘
어제
  • 분류 전체보기 (468)
    • C++ Algorithm & Study (184)
      • C++ & Algorithm Strategies (45)
      • Game Math & DirectX 11 (72)
      • Server + UE5 (29)
      • Lyra Clone Coding (37)
    • Create Game (284)
      • [Window API] Game Client & .. (55)
      • [DirectX] DirectX 2D & 3D (155)
      • [UE5] BLUEPRINT & C++ (74)
    • odds and ends (0)
      • English (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Player State
  • RPG Game
  • protobuf
  • Other Character
  • Direct3D
  • c++
  • Game Room
  • UE5
  • Game Server
  • client
  • session
  • server
  • GAME Client
  • Algorithm Strategies
  • job queue
  • Player Move Packet
  • Direct11
  • Network Worker
  • core
  • Destination Move Packet

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
GameChoi

Choi Programming

[Direct11] 3. Direct3D EX Application Framework
C++ Algorithm & Study/Game Math & DirectX 11

[Direct11] 3. Direct3D EX Application Framework

2023. 6. 12. 18:37

1. Direct3D

1.1 Direct3D EX Application Framework

1.1.1 D3D App

 - Direct3D 응용 프로그램 클래스로 응용 프로그램의 Main Window 생성

class App

   - 응용 프로그램 메시지 루프 실행, Window 메시지 처리, Direct3D 초기화를 위한 함수 제공

     - D3D App을 상속해서 가상 함수로 선언된 프레임워크 함수들을 재정의 (중요한 함수 및 변수만 적을 예정)

class App
{
public:
	App(HINSTANCE hInstance);
	virtual ~App();

public:    
	int32 Run(); // 응용프로그램 메시지 루프를 감싼 함수
	virtual bool Init(); // 자원 할당,장면 물체 초기화,광원 설정 등
	virtual void OnResize(); 
	virtual LRESULT MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
	// 응용 프로그램 주 창의 메시지 처리 기능

protected:
	bool InitMainWindow(); // 응용프로그램 Main Window 초기화
	bool InitDirect3D(); // DX3D를 초기화하는 함수
	void CalculateFrameStats(); // 평균 초당 프레임 수와 평균 프레임당 밀리초를 계산하는 함수
    
protected:
	HINSTANCE _hAppInst = 0; HWND  _hMainWnd = 0;
	int32 _clientWidth = 800; int32 _clientHeight = 600;
};

1.1.2 OnResize

 - WM_SIZE 메시지가 발생했을 때 호출

   - 창의 크기가 변하면 클라이언트 영역의 크기에 의존하는 Direct3D의 속성 몇 가지를 갱싱

     - 특히 Back Buffer와 Depth & Stencil Buffer를 창의 새 클라이언트 영역에 맞게 조정

assert(_deviceContext); assert(_device); assert(_swapChain);
CreateRenderTargetView(); CreateDepthStencilView();

   - 이 후 OM단계에서 Render Target & Depth, Stencil View를 변경하고 변경된 Viewport의 크기를 설정한 후 적용 

_deviceContext->OMSetRenderTargets(1, _renderTargetView.GetAddressOf(), _depthStencilView.Get());
// viewport Settings..
_deviceContext->RSSetViewports(1, &_viewport);

1.1.3 Create Device & SwapChain

 - Device & Device Context & Swap Chain에 대한 구조체를 생성, CreateDeviceAndSwapChain 함수 사용

DXGI_SWAP_CHAIN_DESC desc; ZeroMemory(&desc, sizeof(desc)); // Swap Chian Settings..
HRESULT hr = ::D3D11CreateDeviceAndSwapChain(
    nullptr, // default adapter
    _driverType,
    nullptr, // no software device
    createDeviceFlags,
    nullptr,
    0,
    D3D11_SDK_VERSION,
    &desc,
    _swapChain.GetAddressOf(),
    _device.GetAddressOf(),
    nullptr,
    _deviceContext.GetAddressOf()
);
CHECK(hr);

1.1.4 Create Render Target View

 - Back Buffer를 사용하기 위해  Buffer를 생성 후 Render Target View에 적용

ComPtr<ID3D11Texture2D> backBuffer = nullptr;
HRESULT hr = _swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)backBuffer.GetAddressOf());
CHECK(hr);
hr = _device->CreateRenderTargetView(backBuffer.Get(), nullptr, _renderTargetView.GetAddressOf());
CHECK(hr);

1.1.5 Create Depth & StencilView

 - 마찬가지로 위에 했던 방식으로 구조체를 생성하여 Texture & VIew 적용

HRESULT hr = _device->CreateTexture2D(&desc, nullptr, _depthStencilBuffer.GetAddressOf());
CHECK(hr);
hr = _device->CreateDepthStencilView(_depthStencilBuffer.Get(), &desc, _depthStencilView.GetAddressOf());
CHECK(hr);

1.2 Direct3D EX Initialization

1.2.1 Init Demo

 - 위에서 사용한 응용 프로그램 프레임워크를 이용하여 간단한 예제 응용 프로그램 생성

   - 주된 기능은 부모 클래스인 D3D App이 대부분 담당하고 있으므로 상속

class InitDemo : public App
{
public:
	InitDemo(HINSTANCE hInstance);
	~InitDemo();

public:
	bool Init();
	void OnResize();
	void UpdateScene(float dt);
	void DrawScene();
};

1.2.2 Draw Scene

 - 화면 창에 생성한 것을 띄우기 위해 Draw Scene을 생성하여 적용

   - 그림이 그려질 때 마다 Back Buffer에 그림을 지우고 다시 그려지게 끔 설정

_deviceContext->ClearRenderTargetView(_renderTargetView.Get(), reinterpret_cast<const float*>(&Colors::Blue));
_deviceContext->ClearDepthStencilView(_depthStencilView.Get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
HR(_swapChain->Present(0, 0));
저작자표시 (새창열림)

'C++ Algorithm & Study > Game Math & DirectX 11' 카테고리의 다른 글

[Direct11] 5. Rendering Pipeline - Vertex Shader (VS)  (0) 2023.06.13
[Direct11] 4. Rendering Pipeline - Input Assembler (IA)  (0) 2023.06.13
[Direct11] 2. Direct3D initialization  (0) 2023.06.12
[Direct11] 1. Direct3D Basic Knowledge  (0) 2023.06.12
[GameMath] 24. Intersection # Triangle to Point  (0) 2023.04.22
    'C++ Algorithm & Study/Game Math & DirectX 11' 카테고리의 다른 글
    • [Direct11] 5. Rendering Pipeline - Vertex Shader (VS)
    • [Direct11] 4. Rendering Pipeline - Input Assembler (IA)
    • [Direct11] 2. Direct3D initialization
    • [Direct11] 1. Direct3D Basic Knowledge
    GameChoi
    GameChoi

    티스토리툴바