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)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

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

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
GameChoi

Choi Programming

[Direct11] 11. EX App Program - Color Box
C++ Algorithm & Study/Game Math & DirectX 11

[Direct11] 11. EX App Program - Color Box

2023. 6. 14. 20:03

1. EX App Program

1.1 Color Box

1.1.1 Geometry Buffer

 - 색상이 있는 박스를 생성하기 위해 각 정점에 대해 좌표 및 색상 적용

Vertex vertices[] =
{
    { XMFLOAT3(-1.0f, -1.0f, -1.0f), XMFLOAT4((const float*)&Colors::White)   },
    { XMFLOAT3(-1.0f, +1.0f, -1.0f), XMFLOAT4((const float*)&Colors::Black)   },
    { XMFLOAT3(+1.0f, +1.0f, -1.0f), XMFLOAT4((const float*)&Colors::Red)     },
    { XMFLOAT3(+1.0f, -1.0f, -1.0f), XMFLOAT4((const float*)&Colors::Green)   },
    { XMFLOAT3(-1.0f, -1.0f, +1.0f), XMFLOAT4((const float*)&Colors::Blue)    },
    { XMFLOAT3(-1.0f, +1.0f, +1.0f), XMFLOAT4((const float*)&Colors::Yellow)  },
    { XMFLOAT3(+1.0f, +1.0f, +1.0f), XMFLOAT4((const float*)&Colors::Cyan)    },
    { XMFLOAT3(+1.0f, -1.0f, +1.0f), XMFLOAT4((const float*)&Colors::Magenta) }
};

   - 정점 버퍼에 해당하는 구조체를 생성한 후 정점 버퍼 생성

HR(_device->CreateBuffer(&vbd, &vinitData, _vertexBuffer.GetAddressOf()));

 - 색상이 있는 상자가 어떻게 생겼는 지 확인하기 위해 Index Buffer를 생성하여 확인

HR(_device->CreateBuffer(&ibd, &iinitData, _indexBuffer.GetAddressOf()));

1.1.2 FX Create

 - Effect File을 사용하기 위해 이전 글에서 사용한 방식을 사용

HRESULT hr = ::D3DCompileFromFile(L"../Shaders/02. color.fx", 0, 
	D3D_COMPILE_STANDARD_FILE_INCLUDE, 0, "fx_5_0", shaderFlags, 0, 
	compiledShader.GetAddressOf(), compilationMsgs.GetAddressOf());
HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), 
    compiledShader->GetBufferSize(), 0, _device.Get(), _fx.GetAddressOf()));

   - 상수 버퍼를 연결하기 위해 이름 및 값을 찾음

_tech = _fx->GetTechniqueByName("T0");
_fxWorldViewProj = _fx->GetVariableByName("gWorldViewProj")->AsMatrix();

1.1.3 Vertex Layout

 - 응용 프로그램에서 전달된 정점 버퍼는 GPU에서 어떻게 사용하는 지 모름

   - Input Layout을 통해 정점 버퍼에 대해 묘사

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
};

   - 효과 파일에 있는 정점 버퍼의 포인터 및 크기를 받아 생성

D3DX11_PASS_DESC passDesc;_tech->GetPassByIndex(0)->GetDesc(&passDesc);
HR(_device->CreateInputLayout(vertexDesc, 2, 
	passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, _inputLayout.GetAddressOf()));

1.1.4 Scene

1.1.4.1 On Resize

 - 화면의 크기가 조정될 때 Projection 행렬 또한 값이 변하게 되므로 설정

XMMATRIX P = XMMatrixPerspectiveFovLH(0.25f * XM_PI, AspectRatio(), 1.0f, 1000.0f);
XMStoreFloat4x4(&_proj, P);

1.1.4.2 Update Scene

 - 키보드 입력이나 마우스 이동을 통해 화면이 변경될 때 마다 카메라 행렬에 대해 변하게 되므로 설정

XMVECTOR pos = XMVectorSet(x, y, z, 1.0f);
XMVECTOR target = XMVectorZero(); XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

XMMATRIX V = XMMatrixLookAtLH(pos, target, up); XMStoreFloat4x4(&_view, V);

1.1.4.3 Draw Scene

 - 그림을 그리기 전에 화면에 Render Taget View & Depth Stencil View를 정리

_deviceContext->ClearRenderTargetView(_renderTargetView.Get(), 
	reinterpret_cast<const float*>(&Colors::LightSteelBlue));
_deviceContext->ClearDepthStencilView(_depthStencilView.Get(), 
	D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

   - 이 후 정점 버퍼에 대해 GPU가 알지 못하므로 묘사하고 기하구조를 삼각형으로 설정

_deviceContext->IASetInputLayout(_inputLayout.Get());
_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

   - 묘사된 값과 동일하게 생성된 정점 버퍼 & 인덱스 버퍼를 전달

uint32 stride = sizeof(Vertex); uint32 offset = 0;
_deviceContext->IASetVertexBuffers(0, 1, _vertexBuffer.GetAddressOf(), &stride, &offset);
_deviceContext->IASetIndexBuffer(_indexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0);

 - 상수 버퍼에 대해 값을 넣어주지 않았으므로 설정하고 포인터 값을 통해 값 전달

XMMATRIX world = ::XMLoadFloat4x4(&_world);
XMMATRIX view = ::XMLoadFloat4x4(&_view); 
XMMATRIX proj = ::XMLoadFloat4x4(&_proj);
XMMATRIX worldViewProj = world * view * proj;
_fxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));

 - 마지막으로 Effect File의 주소를 받아 모든 물체들을 효과 파일에 있는 값으로 적용하고 그림을 그림

   - 모든 값이 정리가 된다면 Present 함수를 사용하여 제시

D3DX11_TECHNIQUE_DESC techDesc; _tech->GetDesc(&techDesc);

for (uint32 p = 0; p < techDesc.Passes; ++p)
{
    _tech->GetPassByIndex(p)->Apply(0, _deviceContext.Get());
    _deviceContext->DrawIndexed(36, 0, 0);
}
HR(_swapChain->Present(0, 0));
저작자표시 (새창열림)

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

[Direct11] 13. Lighting System - Diffuse & Ambient & Specular Light  (0) 2023.06.15
[Direct11] 12. EX App Program - Hills  (1) 2023.06.14
[Direct11] 10. Direct3D Effect Framework  (0) 2023.06.14
[Direct11] 9. Direct3D API Interface & Function #2  (0) 2023.06.14
[Direct11] 8. Direct3D API Interface & Function #1  (0) 2023.06.14
    'C++ Algorithm & Study/Game Math & DirectX 11' 카테고리의 다른 글
    • [Direct11] 13. Lighting System - Diffuse & Ambient & Specular Light
    • [Direct11] 12. EX App Program - Hills
    • [Direct11] 10. Direct3D Effect Framework
    • [Direct11] 9. Direct3D API Interface & Function #2
    GameChoi
    GameChoi

    티스토리툴바