DirectX 개발을 위한 Visual Studio 프로젝트 초기 세팅과 프레임워크 구성 (PCH 설정, 외부 라이브러리 연동, 메시지 루프, Game 클래스 설계)
GameCoding, 01.Start 등 01. Main: GameCoding.cpp, Game.h 등 메인 실행/게임 로직 관련 파일 관리99. Headers: 공용 헤더 파일, 구조체, 상수 정의 등 포함Andromeda: pch.h, pch.cpp 등 미리 컴파일 헤더 관리 전용 폴더$(SolutionDir)Binaries\
.exe 및 .pdb 파일이 Binaries 폴더에 자동 생성 01.Start.exe, 01.Start.pdb C/C++ → 일반 → 추가 포함 디렉터리$(SolutionDir)Libraries/Include/
Linker → 일반 → 추가 라이브러리 디렉터리$(SolutionDir)Libraries/Lib/
Include/ 폴더, .lib 파일은 Lib/ 폴더에 배치#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dcompiler.lib")
#ifdef _DEBUG
#pragma comment(lib, "DirectXTex\\DirectXTex_Debug.lib")
#else
#pragma comment(lib, "DirectXTex\\DirectXTex.lib")
#endif
→ Debug/Release 모드에 따라 다른 라이브러리를 자동 적용
#pragma once
#include "Types.h"
#include "Values.h"
#include "Struct.h"
// STL
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;
// WIN
#include <Windows.h>
#include <assert.h>
// DX
#include <d3d11.h>
#include <d3dcompiler.h>
#include <wrl.h>
#include <DirectXMath.h>
#include <DirectXTex/DirectXTex.h>
#include <DirectXTex/DirectXTex.inl>
using namespace DirectX;
using namespace Microsoft::WRL;
pch.cpp: C/C++ → Precompiled Headers → Create (/Yc).cpp 파일들: Use (/Yu).cpp 상단에는 반드시 #include "pch.h" 포함 error C1010: unexpected end of file while looking for precompiled header| 파일명 | 내용 |
|---|---|
| Types.h | 사용자 정의 정수 타입, DirectX 벡터 별칭 (XMFLOAT2, XMFLOAT3 등) |
| Values.h | 전역 상수 정의 (예: GWinSizeX, GWinSizeY) |
| Struct.h | 공용 구조체 정의 예정 |
| pch.h | 자주 사용하는 헤더 및 라이브러리 포함 (컴파일 효율 목적) |
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
while (msg.message != WM_QUIT)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
game.Update();
game.Render();
}
}
→ 입력이 없을 때도 게임 상태를 계속 업데이트 및 렌더링할 수 있음
| 용어 | 설명 |
|---|---|
| 출력 디렉터리 | 빌드 후 생성 파일(.exe, .pdb 등)을 저장하는 경로 |
| 추가 포함 디렉터리 | .h, .inl 파일이 있는 외부 헤더 경로 |
| 추가 라이브러리 디렉터리 | .lib 파일들이 존재하는 경로 |
| PCH | 자주 쓰이는 헤더를 미리 컴파일해 빌드 속도를 높이는 시스템 |
| pragma comment(lib) | 특정 라이브러리를 코드 상에서 직접 연결하는 방식 |
#pragma once
class Game
{
public:
Game(); ~Game();
void Init(HWND hwnd);
void Update();
void Render();
private:
HWND _hwnd;
uint32 _width = 0;
uint32 _height = 0;
};
#include "pch.h"
#include "Game.h"
Game::Game() {}
Game::~Game() {}
void Game::Init(HWND hwnd)
{
_hwnd = hwnd;
_width = GWinSizeX;
_height = GWinSizeY;
}
void Game::Update() {}
void Game::Render() {}
#include "pch.h"
#include "framework.h"
#include "GameCoding.h"
#include "Game.h"
HINSTANCE hInst;
HWND hWnd;
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow)
{
MyRegisterClass(hInstance);
if (!InitInstance(hInstance, nCmdShow)) return FALSE;
Game game;
game.Init(hWnd);
MSG msg = {};
while (msg.message != WM_QUIT)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
game.Update();
game.Render();
}
}
return (int) msg.wParam;
}
→ 핵심: 게임 객체를 생성하고 초기화한 뒤, 메시지 루프 안에서 계속 Update/Render 호출
#include "pch.h" 반드시 포함, 설정 안 하면 컴파일 에러 발생pragma comment(lib)로 연결