이 강의는 C++/DirectX11 기반 게임 프로젝트에서 다음과 같은 요소들을 다룬다:
| 용어 | 설명 |
|---|---|
| Static Library (.lib) | 정적 링크되는 코드 라이브러리. Engine은 .lib로 빌드됨 |
| Engine | 공통 기능(렌더링, 입력 등)을 담당하는 정적 라이브러리 프로젝트 |
| Client | 실행 책임을 지는 프로젝트. Engine을 참조함 |
| Output Directory | .lib/.exe 결과물이 출력되는 경로 설정 |
| Intermediate Directory | .obj 등 임시 산출물이 저장되는 경로 설정 |
| Additional Include Directories | 헤더를 탐색할 경로를 지정하는 속성 값 |
| Additional Library Directories | 링커가 .lib 파일을 찾는 경로 지정 |
| Pre-Build Event | 빌드 전에 자동 실행되는 명령 (ex. xcopy) |
| FX11 | Microsoft의 Effect Framework for DirectX11 |
| technique / pass | FX11에서 쉐이더 흐름을 정의하는 단위 구조 |
| xcopy /Y | 덮어쓰기를 포함한 파일 복사 명령 |
| IExecute | 실행 단위 클래스. Client에서 어떤 기능을 실행할지 위임받음 |
Static Library (.lib)$(SolutionDir)Libraries\Lib\Engine\$(SolutionDir)Intermediate\$(Configuration)\$(SolutionDir)Libraries\Include\;%(AdditionalIncludeDirectories)$(SolutionDir)Libraries\Lib\;%(AdditionalLibraryDirectories)xcopy /Y "$(SolutionDir)Engine\*.h" "$(SolutionDir)Libraries\Include\Engine"
xcopy /Y "$(SolutionDir)Engine\*.inl" "$(SolutionDir)Libraries\Include\Engine"
pch.cpp는 Create (/Yc), 나머지 파일은 Use (/Yu)// pch.h 내부
#pragma once
#pragma comment(lib, "Engine/Engine.lib")
#include "Engine/EnginePch.h"
GameCoding2/
├── Binaries/ # 실행파일
├── Intermediate/ # 빌드 중간파일
├── Libraries/
│ ├── Include/
│ │ ├── DirectXTex/
│ │ ├── FX11/
│ │ └── Engine/ # 헤더 복사 대상
│ └── Lib/
│ ├── DirectXTex/ # DirectXTex.lib 등
│ ├── FX11/
│ └── Engine/ # Engine.lib 출력 경로
├── Shaders/ # .hlsl, .fx 파일
├── Resources/ # 텍스처, 폰트, 사운드
├── Client/ # 실행 프로젝트
├── Engine/ # 정적 라이브러리 프로젝트
└── GameCoding2.sln # 솔루션 파일
struct VertexInput {
float4 position : POSITION;
};
struct VertexOutput {
float4 position : SV_POSITION;
};
VertexOutput VS(VertexInput input)
{
VertexOutput output;
output.position = input.position;
return output;
}
float4 PS(VertexOutput input) : SV_TARGET { return float4(1, 0, 0, 1); } // 빨강
float4 PS2(VertexOutput input) : SV_TARGET { return float4(0, 1, 0, 1); } // 초록
float4 PS3(VertexOutput input) : SV_TARGET { return float4(0, 0, 1, 1); } // 파랑
technique11 T0 {
pass P0 { SetVertexShader(CompileShader(vs_5_0, VS())); SetPixelShader(CompileShader(ps_5_0, PS())); }
pass P1 { SetVertexShader(CompileShader(vs_5_0, VS())); SetPixelShader(CompileShader(ps_5_0, PS2())); }
}
technique11 T1 {
pass P0 { SetVertexShader(CompileShader(vs_5_0, VS())); SetPixelShader(CompileShader(ps_5_0, PS3())); }
}
Effect (/fx)Shader Model 5.0class TriangleDemo : public IExecute
{
public:
void Init() override;
void Update() override;
void Render() override;
private:
shared_ptr<Shader> _shader;
vector<VertexData> _vertices;
shared_ptr<VertexBuffer> _buffer;
};
void TriangleDemo::Init()
{
_shader = make_shared<Shader>(L"01. Triangle.fx");
_vertices.resize(3);
_vertices[0].position = Vec3(-0.5f, 0.f, 0.f);
_vertices[1].position = Vec3(0.f, 0.5f, 0.f);
_vertices[2].position = Vec3(0.5f, 0.f, 0.f);
_buffer = make_shared<VertexBuffer>();
_buffer->Create(_vertices);
}
void TriangleDemo::Render()
{
uint32 stride = _buffer->GetStride();
uint32 offset = _buffer->GetOffset();
DC->IASetVertexBuffers(0, 1, _buffer->GetComPtr().GetAddressOf(), &stride, &offset);
_shader->Draw(0, 0, 3); // technique 0, pass 0
}