Visual Studio 2022에서 작성하였습니다.
 
해당글은 다음 블로그를 참조하였습니다.

http://www.rastertek.com/tutdx11.html

https://ppparkje.tistory.com/category/%EA%B0%95%EC%A2%8C%EB%B2%88%EC%97%AD/DirectX%2011?page=2 
https://copynull.tistory.com/category/DirectX%2011/Basic


Tutorial-8 에 이어서 작성하였음.

 

 

<BitmapClass.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
 
#ifndef _BITMAPCLASS_H_
#define _BITMAPCLASS_H_
 
class TextureClass;
 
class BitmapClass
{
public:
    struct VertexType
    {
        XMFLOAT3 position;
        XMFLOAT2 texture;
    };
 
    BitmapClass();
    BitmapClass(const BitmapClass& other);
    ~BitmapClass();
 
 
    bool Initialize(ID3D11Device* device, int screenWidth, int screenHeight, const WCHAR* textureFilename, int bitmapWidth, int bitmapHeight);
    void Shutdown();
    bool Render(ID3D11DeviceContext* deviceContext, int positionX, int positionY);
 
    int GetIndexCount();
    ID3D11ShaderResourceView* GetTexture();
 
 
private:
 
    bool InitializeBuffers(ID3D11Device* device);
    void ShutdownBuffers();
    bool UpdateBuffers(ID3D11DeviceContext* deviceContext, int positionX, int positionY);
    void RenderBuffers(ID3D11DeviceContext* deviceContext);
 
    // 텍스쳐 로드, 반환
    bool LoadTexture(ID3D11Device* device, const WCHAR* filename);
    void ReleaseTexture();
    
private:
    ID3D11Buffer* m_vertexBuffer = nullptr;
    ID3D11Buffer* m_indexBuffer = nullptr;
    int m_vertexCount = 0;
    int m_indexCount = 0;
 
    TextureClass* m_texture = nullptr;
 
    int m_screenWidth = 0;
    int m_screenHeight = 0;
    int m_bitmapWidth = 0;
    int m_bitmapHeight = 0;
    int m_previousPosX = 0;
    int m_previousPosY = 0;
 
};
 
 
 
#endif // _BITMAPCLASS_H_
cs

 

<BitmapClass.cpp>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#include "stdafx.h"
#include "BitmapClass.h"
 
#include "TextureClass.h"
 
BitmapClass::BitmapClass()
{
}
 
BitmapClass::BitmapClass(const BitmapClass& other)
{
}
 
BitmapClass::~BitmapClass()
{
}
 
bool BitmapClass::Initialize(ID3D11Device* device, int screenWidth, int screenHeight, const WCHAR* textureFilename, int bitmapWidth, int bitmapHeight)
{
    // 화면 크기를 멤버변수에 저장
    m_screenWidth = screenWidth;
    m_screenHeight = screenHeight;
 
    // 렌더링할 비트맵의 픽셀의 크기를 저장
    m_bitmapWidth = bitmapWidth;
    m_bitmapHeight = bitmapHeight;
 
    // 이전 렌더링 위치를 음수로 초기화 한다.
    m_previousPosX = -1;
    m_previousPosY = -1;
 
    // 정점 및 인덱스 버퍼를 초기화 한다.
    if (!InitializeBuffers(device))
    {
        return false;
    }
 
    // 이 모델의 텍스처를 로드한다.
    return LoadTexture(device, textureFilename);
 
}
 
void BitmapClass::Shutdown()
{
    // 모델 텍스쳐를 반환한다.
    ReleaseTexture();
 
    // 버텍스 및 인덱스 버퍼를 종료한다.
    ShutdownBuffers();
}
 
bool BitmapClass::Render(ID3D11DeviceContext* deviceContext, int positionX, int positionY)
{
    // 화면의 다른 위치로 렌더링하기 위해 동적 정점 버퍼를 다시 빌드한ㄷ.
    if (!UpdateBuffers(deviceContext, positionX, positionY))
    {
        return false;
    }
 
    // 그리기를 준비하기 위해 그래픽 파이프 라인에 꼭지점과 인덱스 버퍼를 놓는다.
    RenderBuffers(deviceContext);
 
    return true;
}
 
int BitmapClass::GetIndexCount()
{
    return m_indexCount;
}
 
ID3D11ShaderResourceView* BitmapClass::GetTexture()
{
    return m_texture->GetTexture();
}
 
bool BitmapClass::InitializeBuffers(ID3D11Device* device)
{
    // 정점 배열의 정점 수와 인덱스 배열의 인덱스 수를 지정한다.
    m_indexCount = m_vertexCount = 6;
 
    // 정점 배열을 만든다.
    VertexType* vertices = new VertexType[m_vertexCount];
    if (!vertices)
    {
        return false;
    }
 
 
    // 정점 배열을 0으로 초기화 한다.
    memset(vertices, 0, (sizeof(VertexType) * m_vertexCount));
 
    // 인덱스 배열을 만든다.
    unsigned long* indices = new unsigned long[m_indexCount];
    if (!indices)
    {
        return false;
    }
 
    // 데이터로 인덱스 배열을 로드한다.
    for (int i = 0; i < m_vertexCount; i++)
    {
        indices[i] = i;
    }
 
 
    // 정적 정점 버퍼의 구조체를 설정한다.
    D3D11_BUFFER_DESC vertexBufferDesc;
    vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
    vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount;
    vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    vertexBufferDesc.MiscFlags = 0;
    vertexBufferDesc.StructureByteStride = 0;
 
    // subresource 구조에 정점 데이터에 대한 포인터를 제공한다.
    D3D11_SUBRESOURCE_DATA vertexData;
    vertexData.pSysMem = vertices;
    vertexData.SysMemPitch = 0;
    vertexData.SysMemSlicePitch = 0;
 
    // 이제 정점 버퍼를 만듭니다.
    if (FAILED(device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer)))
    {
        return false;
    }
 
    // 인덱스 버퍼 description 생성
    D3D11_BUFFER_DESC indexBufferDesc;
    indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    indexBufferDesc.ByteWidth = sizeof(unsigned long* m_indexCount;
    indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
    indexBufferDesc.CPUAccessFlags = 0;
    indexBufferDesc.MiscFlags = 0;
    indexBufferDesc.StructureByteStride = 0;
 
    // 인덱스 데이터를 가리키는 보조 리소스 구조체 작성
    D3D11_SUBRESOURCE_DATA indexData;
    indexData.pSysMem = indices;
    indexData.SysMemPitch = 0;
    indexData.SysMemSlicePitch = 0;
 
    // 인덱스 버퍼를 생성합니다.
    if (FAILED(device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer)))
    {
        return false;
    }
 
    // 정점버퍼 인덱스 버퍼 해제
    delete[] vertices;
    vertices = nullptr;
 
    delete[] indices;
    indices = nullptr;
 
    return true;
}
 
void BitmapClass::ShutdownBuffers()
{
    // 인덱스 버퍼 해제
    if (m_indexBuffer)
    {
        m_indexBuffer->Release();
        m_indexBuffer = nullptr;
    }
 
    // 정점 버퍼를 해제합니다.
    if (m_vertexBuffer)
    {
        m_vertexBuffer->Release();
        m_indexBuffer = nullptr;
    }
}
 
bool BitmapClass::UpdateBuffers(ID3D11DeviceContext* deviceContext, int positionX, int positionY)
{
    float left, right, top, bottom;
    VertexType* vertices;
    VertexType* verticesPtr;
    D3D11_MAPPED_SUBRESOURCE mappedResource;
 
 
    // 이 비트맵을 렌더링 할 위치가 변경되지 않은 경우 정점 버퍼를 업데이트 하지 않는다.
    if ((positionX == m_previousPosX) && (positionY == m_previousPosY))
    {
        return true;
    }
 
    // 변경된 경우 렌더링 되는 위치를 업데이트 한다.
    m_previousPosX = positionX;
    m_previousPosY = positionY;
 
    // 비트 맵 왼쪽의 화면 좌표를 계산한다.
    left = static_cast<float>((m_screenWidth / 2* -1+ static_cast<float>(positionX);
 
    // 비트맵 오른쪽의 화면 좌표를 계산한다.
    right = left + static_cast<float>(m_bitmapWidth);
 
    // 비트맵 상단의 화면 좌표를 계산한다.
    top = static_cast<float>(m_screenHeight / 2- static_cast<float>(positionY);
 
    // 비트 맵 아래쪽의 화면 좌표를 계산한다.
    bottom = top - static_cast<float>(m_bitmapHeight);
 
 
    // 정점 배열을 만든다.
    vertices = new VertexType[m_vertexCount];
    if (!vertices)
    {
        return false;
    }
 
    // 정점 배열에 데이터를 로드한다.
    // 첫 번째 삼각형
    vertices[0].position = XMFLOAT3(left, top, 0.0f);
    vertices[0].texture = XMFLOAT2(0.0f, 0.0f);
 
    vertices[1].position = XMFLOAT3(right, bottom, 0.0f);
    vertices[1].texture = XMFLOAT2(1.0f, 1.0f);
 
    vertices[2].position = XMFLOAT3(left, bottom, 0.0f);
    vertices[2].texture = XMFLOAT2(0.0f, 1.0f);
 
 
    // 두번째 삼각형
    vertices[3].position = XMFLOAT3(left, top, 0.0f);
    vertices[3].texture = XMFLOAT2(0.0f, 0.0f);
 
    vertices[4].position = XMFLOAT3(right, top, 0.0f);
    vertices[4].texture = XMFLOAT2(1.0f, 0.0f);
 
    vertices[5].position = XMFLOAT3(right, bottom, 0.0f);
    vertices[5].texture = XMFLOAT2(1.0f, 1.0f);
 
    // 버텍스 버퍼를 쓸 수 있도록 잠근다.
    if (FAILED(deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0&mappedResource)))
    {
        return false;
    }
 
    // 정점 버퍼의 데이터를 가리키는 포인터를 얻는다.
    verticesPtr = reinterpret_cast<VertexType*>(mappedResource.pData);
 
    // 데이터를 정점 버퍼에 복사한다.
    memcpy(verticesPtr, vertices, (sizeof(VertexType) * m_vertexCount));
    
    // 정점 버퍼의 잠금을 해제한다.
    deviceContext->Unmap(m_vertexBuffer, 0);
 
    // 더이상 필요하지 않은 꼭지점 배열 해제
    delete[] vertices;
    vertices = 0;
 
    return true;
}
 
void BitmapClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
{
    unsigned int stride;
    unsigned int offset;
 
    // 정점 버퍼의 단위와 오프셋을 설정한다.
    stride = sizeof(VertexType);
    offset = 0;
 
    // input assembler에 정점 버퍼를 활성화하여 그려질 수 있게 한다.
    deviceContext->IASetVertexBuffers(01&m_vertexBuffer, &stride, &offset);
 
    // input Assembler에 인덱스 버퍼를 활성화여 그려질 수 있게한다.
    deviceContext->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
 
    // 정점 버퍼로 그릴 기본형을 설정한다.
    // 여기서는 삼각형이다.
    deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 
}
 
bool BitmapClass::LoadTexture(ID3D11Device* device, const WCHAR* filename)
{
    // 텍스쳐 오브젝트를 생성한다.
    m_texture = new TextureClass;
    if (!m_texture)
    {
        return false;
    }
 
    // 텍스처 오브젝트를 초기화한다.
    return m_texture->Initialize(device, filename);
}
 
void BitmapClass::ReleaseTexture()
{
    // 텍스쳐 오브젝트를 릴리즈 한다.
    if (m_texture)
    {
        m_texture->Shutdown();
        delete m_texture;
        m_texture = nullptr;
    }
    
}
 
cs

 

<D3dClass.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
 
#ifndef _D3DCLASS_H_
#define _D3DCLASS_H_
 
class D3DClass
{
public:
    D3DClass();
    D3DClass(const D3DClass&);
    ~D3DClass();
 
    bool Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear);
    void Shutdown();
 
 
    void BeginScene(float red, float green, float blue, float alpha);
    void EndScene();
 
    ID3D11Device* GetDevice();
    ID3D11DeviceContext* GetDeviceContext();
 
    void GetProjectionMatrix(XMMATRIX& projectionMatrix);
    void GetWorldMatrix(XMMATRIX& worldMatrix);
    void GetOrthoMatrix(XMMATRIX& orthoMatrix);
 
    void GetVideoCardInfo(char* cardname, int& memory);
 
    void TurnZBufferOn();
    void TurnZBufferOff();
 
private:
    bool m_vsync_enabled = false;
    int m_videoCardMemory = 0;
    char m_videoCardDescription[128= { 0, };
    IDXGISwapChain* m_swapChain = nullptr;
    ID3D11Device* m_device = nullptr;
    ID3D11DeviceContext* m_deviceContext = nullptr;
    ID3D11RenderTargetView* m_renderTargetView = nullptr;
    ID3D11Texture2D* m_depthStencilBuffer = nullptr;
    ID3D11DepthStencilState* m_depthStencilState = nullptr;
    ID3D11DepthStencilView* m_depthStencilView = nullptr;
    ID3D11RasterizerState* m_rasterState = nullptr;
    XMMATRIX m_projectionMatrix;
    XMMATRIX m_worldMatrix;
    XMMATRIX m_orthoMatrix;
 
    ID3D11DepthStencilState* m_depthDisabledStencilState = nullptr;
 
};
 
 
 
 
 
#endif // _D3DCLASS_H_
cs

 

<D3dClass.cpp>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#include "stdafx.h"
#include "D3dclass.h"
 
#include <iostream>
 
D3DClass::D3DClass()
{
}
 
D3DClass::D3DClass(const D3DClass&)
{
}
 
D3DClass::~D3DClass()
{
}
 
bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear)
{
 
    // 수직동기화 상태를 저장한다.
    m_vsync_enabled = vsync;
 
    // DirectX 그래픽 인터페이스 팩토리를 생성한다.
    IDXGIFactory* factory = nullptr;
    if (FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory))))
    {
        return false;
    }
 
 
    // 팩토리 객체를 사용하여 첫번째 그래픽 카드 인터페이스 어뎁터를 생성한다.
    IDXGIAdapter* adapter = nullptr;
    if (FAILED(factory->EnumAdapters(0&adapter)))  // 0 은 첫번째 그래픽카드 // 컴퓨터에 따라 0번이 내장 그래픽일수 도 있고 외장일 수 도 있다.
    {
        return false;
    }
 
    // 출력(모니터)에 대한 첫번째 어뎁터를 지정한다.
    IDXGIOutput* adapterOutput = nullptr;
    if (FAILED(adapter->EnumOutputs(0&adapterOutput)))
    {
        return false;
    }
 
    // 출력(모니터)에 대한 DXGI_FORMAT_R8G8B8A8_UNORM 표시 형식에 맞는 모드수를 가져옵니다.
    unsigned int numModes = 0;
    if (FAILED(adapterOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL)))
    {
        return false;
    }
 
    // 가능한 모든 모니터와 그래픽카드 조합을 저장할 리스트를 생성한다.
    DXGI_MODE_DESC* displayModeList = new DXGI_MODE_DESC[numModes];
    if (!displayModeList)
    {
        return false;
    }
 
    // 이제 디스플레이 모드에 대한 리스트를 채운다.
    if (FAILED(adapterOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList)))
    {
        return false;
    }
 
 
    // 이제 모든 디스플레이 모드에 대해 화면 너비/높이에 맞는 디스플레이 모드를 찾는다.
    // 적합한 것을 찾으면 모니터의 새로고침 비율의 분모와 분자값을 저장한다.
    unsigned int numerator = 0;
    unsigned int denominator = 0;
    for (unsigned int i = 0; i < numModes; i++)
    {
        if (displayModeList[i].Width == static_cast<unsigned>(screenWidth))
        {
            if (displayModeList[i].Height == static_cast<unsigned>(screenHeight))
            {
                numerator = displayModeList[i].RefreshRate.Numerator;
                denominator = displayModeList[i].RefreshRate.Denominator;
            }
        }
    }
 
    // 비디오카드의 구조체를 얻는다.
    DXGI_ADAPTER_DESC adapterDesc;
    if (FAILED(adapter->GetDesc(&adapterDesc)))
    {
        return false;
    }
 
    // 비디오카드 메모리 용량 단위를 메가바이트 단위로 저장한다.
    m_videoCardMemory = static_cast<int>(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
 
 
    // 비디오카드의 이름을 저장합니다.
    size_t stringLength = 0;
    if (wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128!= 0)
    {
        return false;
    }
 
 
    // 그래픽 카드 확인 용도.
    const WCHAR* pwcsName; //LPCWSTR
 
    // required size
    int size = MultiByteToWideChar(CP_ACP, 0, m_videoCardDescription, -1NULL0);
    // allocate it
    pwcsName = new WCHAR[stringLength];
    MultiByteToWideChar(CP_ACP, 0, m_videoCardDescription, -1, (LPWSTR)pwcsName, size);
    // use it....
 
    OutputDebugString(pwcsName);
    // delete it
    delete[] pwcsName;
    
    
 
    // 디스플레이 모드 리스트를 해제한다.
    delete[] displayModeList;
    displayModeList = nullptr;
 
    // 출력 어뎁터를 해제한다.
    adapterOutput->Release();
    adapterOutput = nullptr;
 
    // 어뎁터를 해제한다.
    adapter->Release();
    adapter = nullptr;
 
 
    // 스왑체인 구조체를 초기환한다.
    DXGI_SWAP_CHAIN_DESC swapChainDesc;
    ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
 
    // 백버퍼를 1개만 사용하도록 지정한다.
    swapChainDesc.BufferCount = 1;
 
    // 백버퍼의 넓이와 높이를 지정한다.
    swapChainDesc.BufferDesc.Width = screenWidth;
    swapChainDesc.BufferDesc.Height = screenHeight;
 
    // 33bit 서피스를 설정한다.
    swapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
 
    // 백버퍼의 새로고침 비율을 설정한다.
    if (m_vsync_enabled)
    {
        swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
        swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
    }
    else
    {
        swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
        swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    }
 
 
    // 백버퍼의 사용용도를 지정한다.
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
 
    // 랜더링에 사용될 윈도우 핸들을 지정한다.
    swapChainDesc.OutputWindow = hwnd;
 
    // 멀티샘플링을 끈다.
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.SampleDesc.Quality = 0;
 
    // 창모드 or 풀스크린 모드를 설정한다.
    if (fullscreen)
    {
        swapChainDesc.Windowed = false;
    }
    else
    {
        swapChainDesc.Windowed = true;
    }
 
    // 스캔 라인 순서 및 크기를 지정하지 않음으로 설정한다.
    swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
 
    // 출력된 다음 백버퍼를 비우도록 지정한다.
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
 
    // 추가 옵션 플래그를 사용하지 않는다.
    swapChainDesc.Flags = 0;
 
    // 피처레벨을 DirectX11로 설정한다.
    D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
 
    // 스왑 체인, Direct3D 장치 및 Direct3D 장치 컨텍스트를 만든다.
    if (FAILED(D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL0&featureLevel, 1,
        D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL&m_deviceContext)))
    {
        return false;
    }
 
 
    // 백버퍼 포인터를 얻어온다.
    ID3D11Texture2D* backBufferPtr = nullptr;
    if (FAILED(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),reinterpret_cast<LPVOID*>(&(backBufferPtr)))))
    {
        return false;
    }
 
 
    // 백 버퍼 포인터로 랜더 타겟 뷰를 생성한다.
    if(FAILED(m_device->CreateRenderTargetView(backBufferPtr, NULL&m_renderTargetView)))
    {
        return false;
    }
 
 
    // 백버퍼 포인터를 해제한다.
    backBufferPtr->Release();
    backBufferPtr = nullptr;
 
 
    // 깊이 버퍼 구조체를 초기화 합니다.
    D3D11_TEXTURE2D_DESC depthBufferDesc;
    ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
 
    // 깊이 버퍼 구조체를 작성합니다.
    depthBufferDesc.Width = screenWidth;
    depthBufferDesc.Height = screenHeight;
    depthBufferDesc.MipLevels = 1;
    depthBufferDesc.ArraySize = 1;
    depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    depthBufferDesc.SampleDesc.Count = 1;
    depthBufferDesc.SampleDesc.Quality = 0;
    depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    depthBufferDesc.CPUAccessFlags = 0;
    depthBufferDesc.MiscFlags = 0;
 
    // 설정된 깊이버퍼 구조체를 사용하여 깊이 버퍼 텍스쳐를 생성한다.
    if (FAILED(m_device->CreateTexture2D(&depthBufferDesc, NULL& m_depthStencilBuffer)))
    {
        return false;
    }
 
    // 스텐실 상태 구조체를 초기화 합니다.
    D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
    ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
 
    // 스텐실 상태 구조체를 작성합니다.
    depthStencilDesc.DepthEnable = true;
    depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
 
    depthStencilDesc.StencilEnable = true;
    depthStencilDesc.StencilReadMask = 0xFF;
    depthStencilDesc.StencilWriteMask = 0xFF;
 
    // 픽셀 정면의 스텐실 설정입니다.
    depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
    depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
 
    // 픽셀 뒷면의 스텐실 설정입니다.
    depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
    depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
 
    // 깊이 스텐실 상태를 설정합니다.
    m_deviceContext->OMSetDepthStencilState(m_depthStencilState, 1);
 
 
    // 깊이 스텐실 뷰의 구조체를 초기화합니다.
    D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
    ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
 
    // 깊이 스텐실 뷰 구조체를 설정한다.
    depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    depthStencilViewDesc.Texture2D.MipSlice = 0;
 
    // 깊이 스텐실 뷰를 생성한다.
    if(FAILED(m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView)))
    {
        return false;
    }
 
    // 랜더링 대상 뷰와 깊이 스텐실 버퍼를  출력 렌더 파이프 라인에 바인딩 한다.
    m_deviceContext->OMSetRenderTargets(1&m_renderTargetView, m_depthStencilView);
 
    // 그려지는 폴리곤과 방법을 결정할 레스터 구조체를 설정한다.
    D3D11_RASTERIZER_DESC rasterDesc;
    rasterDesc.AntialiasedLineEnable = false;
    rasterDesc.CullMode = D3D11_CULL_BACK;
    rasterDesc.DepthBias = 0;
    rasterDesc.DepthBiasClamp = 0.0f;
    rasterDesc.DepthClipEnable = true;
    rasterDesc.FillMode = D3D11_FILL_SOLID;
    rasterDesc.FrontCounterClockwise = false;
    rasterDesc.MultisampleEnable = false;
    rasterDesc.ScissorEnable = false;
    rasterDesc.SlopeScaledDepthBias = 0.0f;
 
    // 방금 작성한 구조체에서 레스터 라이저 상태를 만든다.
    if (FAILED(m_device->CreateRasterizerState(&rasterDesc, &m_rasterState)))
    {
        return false;
    }
 
    // 이제 레스터 라이저 상태를 설정한다.
    m_deviceContext->RSSetState(m_rasterState);
 
    // 렌더링을 위해 뷰포트를 설정한다.
    D3D11_VIEWPORT viewport;
    viewport.Width = static_cast<float>(screenWidth);
    viewport.Height = static_cast<float>(screenHeight);
    viewport.MinDepth = 0.0f;
    viewport.MaxDepth = 1.0f;
    viewport.TopLeftX = 0.0f;
    viewport.TopLeftY = 0.0f;
 
    // 뷰포트를 생성한다.
    m_deviceContext->RSSetViewports(1&viewport);
 
    // 투영 행렬을 설정한다.
    float fieldOfView = 3.141592654f / 4.0f;
    float screenAspect = static_cast<float>(screenWidth) / static_cast<float>(screenHeight);
 
    // 3D 렌더링을 위핸 투영 행렬을 만든다.
    m_projectionMatrix = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, screenNear, screenDepth);
 
    // 세계 행렬을 항동 행렬로 초기화 한다.
    m_worldMatrix = XMMatrixIdentity();
 
    // 2D렌더링을위한 직교 투영 행렬을 만든다.
    m_orthoMatrix = XMMatrixOrthographicLH(static_cast<float>(screenWidth), static_cast<float>(screenHeight), screenNear, screenDepth);
 
    // 이제 2D 렌더링을 위한 Z 버퍼를 끄는 두번째 깊이 스텐실 상태를 만든다.
    // 유일한 차이점은 DepthEnable을 false로 설정하며, 다른 모든 매개변수는 다른 깊이 스텐실 상태와 동일하다.
 
    D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
    ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));
 
    // 스텐실 상태 구조체를 작성합니다.
    depthDisabledStencilDesc.DepthEnable = false;
    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
    
    depthDisabledStencilDesc.StencilEnable = true;
    depthDisabledStencilDesc.StencilReadMask = 0xFF;
    depthDisabledStencilDesc.StencilWriteMask = 0xFF;
 
    // 픽셀 정면의 스텐실 설정입니다.
    depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
    depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
 
    // 픽셀 뒷면의 스텐실 설정입니다.
    depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
    depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
 
    // 장치를 사용하여 상태를 만든다.
    if (FAILED(m_device->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState)))
    {
        return false;
    }
 
    return true;
}
 
void D3DClass::Shutdown()
{
    // 종료하기 전에 이렇게 윈도우 모드로 바꾸지 않으면 스왑체인을 할당 해제할 때 예외가 발생합니다.
    if (m_swapChain)
    {
        m_swapChain->SetFullscreenState(false, nullptr);
    }
 
    if (m_depthDisabledStencilState)
    {
        m_depthDisabledStencilState->Release();
        m_depthDisabledStencilState = nullptr;
    }
 
    if (m_rasterState)
    {
        m_rasterState->Release();
        m_rasterState = nullptr;
    }
 
    if (m_depthStencilView)
    {
        m_depthStencilView->Release();
        m_depthStencilView = nullptr;
    }
 
    if (m_depthStencilState)
    {
        m_depthStencilState->Release();
        m_depthStencilState = nullptr;
    }
 
    if (m_depthStencilBuffer)
    {
        m_depthStencilBuffer->Release();
        m_depthStencilBuffer = nullptr;
    }
 
    if (m_renderTargetView)
    {
        m_renderTargetView->Release();
        m_renderTargetView = nullptr;
    }
 
    if (m_deviceContext)
    {
        m_deviceContext->Release();
        m_deviceContext = nullptr;
    }
 
    if (m_device)
    {
        m_device->Release();
        m_device = nullptr;
    }
 
    if (m_swapChain)
    {
        m_swapChain->Release();
        m_swapChain = nullptr;
    }
 
}
 
void D3DClass::BeginScene(float red, float green, float blue, float alpha)
{
 
    // 버퍼를 지울 색을 설정한다.
    float color[4= { red, green, blue, alpha };
 
    // 백버퍼를 지운다.
    m_deviceContext->ClearRenderTargetView(m_renderTargetView, color);
 
    // 깊이 버퍼를 지운다.
    m_deviceContext->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
}
 
void D3DClass::EndScene()
{
    // 렌더링이 완료되었으므로 화면에 백 버퍼를 표시한다.
    if(m_vsync_enabled)
    {
        // 화면 새로 고침 비율을 고정한다.
        m_swapChain->Present(10);
    }
    else
    {
        // 가능한 빠르게 출력한다.
        m_swapChain->Present(00);
    }
}
 
ID3D11Device* D3DClass::GetDevice()
{
    return m_device;
}
 
ID3D11DeviceContext* D3DClass::GetDeviceContext()
{
    return m_deviceContext;
}
 
void D3DClass::GetProjectionMatrix(XMMATRIX& projectionMatrix)
{
    // 이번 예제에서는 사용 안함.
    projectionMatrix = m_projectionMatrix;
}
 
void D3DClass::GetWorldMatrix(XMMATRIX& worldMatrix)
{
    // 이번 예제에서는 사용 안함.
    worldMatrix = m_worldMatrix;
}
 
void D3DClass::GetOrthoMatrix(XMMATRIX& orthoMatrix)
{
    // 이번 예제에서는 사용 안함.
    orthoMatrix = m_orthoMatrix;
}
 
void D3DClass::GetVideoCardInfo(char* cardname, int& memory)
{
    strcpy_s(cardname, 128, m_videoCardDescription);
    memory = m_videoCardMemory;
}
 
void D3DClass::TurnZBufferOn()
{
    m_deviceContext->OMSetDepthStencilState(m_depthStencilState, 1);
}
 
void D3DClass::TurnZBufferOff()
{
    m_deviceContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);
}
 
cs

 

<GraphicsClass.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#ifndef _GRAPHICSCLASS_H_
#define _GRAPHICSCLASS_H_
 
// GLOBALS //
const bool FULL_SCREEN = false;
const bool VSYNC_ENABLED = true;
const float SCREEN_DEPTH = 1000.0f;
const float SCREEN_NEAR = 0.1f;
 
 
class D3DClass;
class CameraClass;
//class ModelClass;
//class ColorShaderClass;
class TextureShaderClass;
class BitmapClass;
class LightShaderClass;
class LightClass;
 
class GraphicsClass
{
public:
    GraphicsClass();
    GraphicsClass(const GraphicsClass& other);
    ~GraphicsClass();
 
 
    bool Initialize(int screenWidth, int screenHeight, HWND hwnd);
    void Shutdown();
    bool Frame();
 
private:
    bool Render(float rotation);
 
private:
    D3DClass* m_D3D = nullptr;
    CameraClass* m_Camera = nullptr;
 
    //ModelClass* m_Model = nullptr;
    TextureShaderClass* m_TextureShader = nullptr;
    BitmapClass* m_Bitmap = nullptr;
    //ColorShaderClass* m_ColorShader = nullptr;
    //LightShaderClass* m_LightShader = nullptr;
    //LightClass* m_Light = nullptr;
};
 
#endif // _GRAPHICSCLASS_H_
cs

 

<GraphicsClass.cpp>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include "stdafx.h"
#include "graphicsclass.h"
 
#include "BitmapClass.h"
#include "D3dclass.h"
#include "CameraClass.h"
#include "ModelClass.h"
#include "LightShaderClass.h"
#include "LightClass.h"
#include "TextureShaderClass.h"
 
GraphicsClass::GraphicsClass()
{
}
 
GraphicsClass::GraphicsClass(const GraphicsClass& other)
{
}
 
GraphicsClass::~GraphicsClass()
{
}
 
bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
    // Direct3D 객체 생성
    m_D3D = new D3DClass;
    if (!m_D3D)
    {
        return false;
    }
 
    // Direct3D 객체를 초기화 한다.
    if (!m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR))
    {
        MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
        return false;
    }
 
 
    // m_Camera 객체 생성
    m_Camera = new CameraClass;
    if (!m_Camera)
    {
        return false;
    }
 
    // 카메라 포지션 설정
    m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
 
    //// m_Model 객체 생성
    //m_Model = new ModelClass;
    //if (!m_Model)
    //{
    //    return false;
    //}
 
    //// m_Model 초기화
    //if (!m_Model->Initialize(m_D3D->GetDevice(), "./cube.txt", L"./Textures/WoodCrate01.dds"))
    //{
    //    MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
    //}
 
    // 텍스쳐 쉐이더 객체 생성
    m_TextureShader = new TextureShaderClass;
    if (!m_TextureShader)
    {
        return false;
    }
 
    //// 텍스터 쉐이더 객테 초기화
    if (!m_TextureShader->Initialize(m_D3D->GetDevice(), hwnd))
    {
        MessageBox(hwnd, L"Could not initialize texture shader object.", L"Error", MB_OK);
        return false;
    }
 
    //// LightShaderClass 객체 생성
    //m_LightShader = new LightShaderClass;
    //if (!m_LightShader)
    //{
    //    return false;
    //}
 
    //// LightShader 객체를 초기화한다.
    //if (!m_LightShader->Initialize(m_D3D->GetDevice(), hwnd))
    //{
    //    MessageBox(hwnd, L"Could not initialize the light shader object.", L"Error", MB_OK);
    //    return false;
    //}
 
    //// LightClass 객체 생성
    //m_Light = new LightClass;
    //if (!m_Light)
    //{
    //    return false;
    //}
 
    //// Light 객체 초기화
    //m_Light->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
    //m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
    //m_Light->SetDirection(1.0f, 0.0f, 1.0f);
    //m_Light->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
    //m_Light->SetSpecularPower(32.0f);
 
    // 비트맵 객체 생성
    m_Bitmap = new BitmapClass;
    if (!m_Bitmap)
    {
        return false;
    }
 
    // 비트맵 객체 초기화
    if (!m_Bitmap->Initialize(m_D3D->GetDevice(), screenWidth, screenHeight, L"./Textures/WoodCrate01.dds",
        512512))
    {
        MessageBox(hwnd, L"Could not initialize the bitmap object.", L"Error", MB_OK);
        return false;
    }
 
    return true;
}
 
void GraphicsClass::Shutdown()
{
    // 비트맵 객체 해제
    if (m_Bitmap)
    {
        m_Bitmap->Shutdown();
        delete m_Bitmap;
        m_Bitmap = nullptr;
    }
    //// light 객체 해제
    //if (m_Light)
    //{
    //    delete m_Light;
    //    m_Light = nullptr;
    //}
 
    //// LightShader 객체 해제
    //if (m_LightShader)
    //{
    //    m_LightShader->Shutdown();
    //    delete m_LightShader;
    //    m_LightShader = nullptr;
    //}
 
    // m_TextureShader 객체 반환
    //if (m_TextureShader)
    //{
    //    m_TextureShader->Shutdown();
    //    delete m_TextureShader;
    //    m_TextureShader = nullptr;
    //}
 
    //// m_Model 객체 반환
    //if (m_Model)
    //{
    //    m_Model->Shutdown();
    //    delete m_Model;
    //    m_Model = nullptr;
    //}
 
    // m_Camera 객체 반환
    if (m_Camera)
    {
        delete m_Camera;
        m_Camera = nullptr;
    }
 
    // D3D 객체를 반환합니다.
    if (m_D3D)
    {
        m_D3D->Shutdown();
        delete m_D3D;
        m_D3D = nullptr;
    }
}
 
bool GraphicsClass::Frame()
{
    static float rotation = 0.0f;
 
    // 각 프레임 마다 rotation 변수값을 업데이트 한다.
    rotation += XM_PI * 0.005f;
    if (rotation > 360.0f)
    {
        rotation -= 360.0f;
    }
    //그래픽 렌더링을 수행합니다.
    if (!Render(rotation))
    {
        
        return false;
    }
    return true;
}
 
bool GraphicsClass::Render(float rotation)
{
    // 씬 그리기를 시작하기 위해 버퍼의 내용을 지웁니다.
    m_D3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
 
    // 카메라의 위치에 따라 뷰 행렬을 생성한다.
    m_Camera->Render();
 
    // 카메라 및 d3d 객체에서 월드, 뷰 및 투영 행렬을 가져온다.
    XMMATRIX worldMatrix, viewMatrix, projectionMatrix, orthoMatrix;
    m_D3D->GetWorldMatrix(worldMatrix);
    m_Camera->GetViewMatrix(viewMatrix);
    m_D3D->GetProjectionMatrix(projectionMatrix);
    m_D3D->GetOrthoMatrix(orthoMatrix);
 
    // 2D 렌더링을 시작하기 위해 Z버퍼를 끈다.
    m_D3D->TurnZBufferOff();
 
    // 비트맵 버텍스와 인덱스 버퍼를 그래픽 파이프 라인에 배치하여 그리기를 준비한다.
    if (!m_Bitmap->Render(m_D3D->GetDeviceContext(), 100100))
    {
        return false;
    }
 
    // 도형이 회전 할 수 있도록 회전 값으로 월드 행렬을 회전한다.
    // = XMMatrixRotationY(rotation);
 
    // 모델 버텍스와 인덱스 버퍼를 그래픽 파이프 라인에 배치하여 드로잉을 준비한다.
    //m_Model->Render(m_D3D->GetDeviceContext());
 
 
    // Light 쉐이더를 사용하여 모델을 렌더링 한다.
    //if (!m_LightShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix,
    //    viewMatrix, projectionMatrix, m_Model->GetTexture(), m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor()
    //    , m_Camera->GetPosition(), m_Light->GetSpecularColor(), m_Light->GetSpecularPower()))
    //{
    //    return false;
    //}
 
 
    // 텍스처 쉐이더를 사용하여 모델을 랜더링 한다.
    if (!m_TextureShader->Render(m_D3D->GetDeviceContext(), m_Bitmap->GetIndexCount(), worldMatrix, viewMatrix, orthoMatrix,
        m_Bitmap->GetTexture()))
    {
        return false;
    }
 
    // 모든2D 렌더링이 완료되었으므로 Z버퍼를 다시 켠다.
    m_D3D->TurnZBufferOn();
 
    // 버퍼에 그려진 씬을 화면에 표시합니다.
    m_D3D->EndScene();
 
    return true;
}
 
cs

 

<결과>

<소스코드>

https://github.com/woonhak-kong/DirectX_11_Tutorial/releases/tag/Tutorial_9

 

 

+ Recent posts