-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.cpp
More file actions
119 lines (103 loc) · 3.02 KB
/
Renderer.cpp
File metadata and controls
119 lines (103 loc) · 3.02 KB
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
#include "stdafx.h"
#include "Renderer.h"
Renderer::Renderer()
{
}
Renderer::~Renderer()
{
}
void Renderer::Init(const char* filename, int width, int height)
{
HDC hdc = GetDC(_hWnd);
this->width = width;
this->height = height;
memDC = CreateCompatibleDC(hdc);
alphaMemDC = CreateCompatibleDC(hdc);
hBit = (HBITMAP)LoadImage(_hInstance, filename, IMAGE_BITMAP, width, height, LR_LOADFROMFILE);
oBit = (HBITMAP)SelectObject(memDC, hBit);
hBit = (HBITMAP)CreateCompatibleBitmap(hdc, width, height);
SelectObject(alphaMemDC, hBit);
ReleaseDC(_hWnd, hdc);
alpha = 255;
blendFunc.BlendOp = AC_SRC_OVER;
blendFunc.BlendFlags = 0;
blendFunc.AlphaFormat = 0;
blendFunc.SourceConstantAlpha = alpha;
rc = RectMakeCenter(this->gameObject->transform->position.x,
this->gameObject->transform->position.y,
width,
height);
}
void Renderer::Init()
{
HDC hdc = GetDC(_hWnd);
width = transform->GetWidth();
height = transform->GetHeight();
memDC = CreateCompatibleDC(hdc);
alphaMemDC = CreateCompatibleDC(hdc);
hBit = (HBITMAP)CreateCompatibleBitmap(hdc, width, height);
oBit = (HBITMAP)SelectObject(memDC, hBit);
SelectObject(alphaMemDC, hBit);
alpha = 255;
blendFunc.BlendOp = AC_SRC_OVER;
blendFunc.BlendFlags = 0;
blendFunc.AlphaFormat = 0;
blendFunc.SourceConstantAlpha = alpha;
rc = RectMakeCenter(this->transform->GetX(), transform->GetY(),
width, height);
ReleaseDC(_hWnd, hdc);
}
void Renderer::Render()
{
if(!KEYMANAGER->isToggleKey(VK_TAB))
Rectangle(_backBuffer->getMemDC(), rc);
BitBlt(alphaMemDC, 0, 0, width, height, _backBuffer->getMemDC(), rc.left, rc.top, SRCCOPY);
GdiTransparentBlt(
alphaMemDC, //복사될 영역의 DC
0, //복사될 좌표(left)
0, //복사될 좌표(top)
width, //복사될 크기 (가로크기)
height, //복사될 크기 (세로크기)
memDC, //복사해올 DC
0, 0, //복사해올 시작좌표(left, top)
width, //복사해올 가로크기
height, //복사해올 세로크기
RGB(255, 0, 255) //복사할때 제외할 픽셀값
);
AlphaBlend(
_backBuffer->getMemDC(), //복사될 영역의 DC
rc.left, //복사될 좌표(left)
rc.top, //복사될 좌표(top)
width, //복사될 크기 (가로크기)
height, //복사될 크기 (세로크기)
alphaMemDC, //복사해올 DC
0, 0, //복사해올 시작좌표(left, top)
width, //복사해올 가로크기
height, //복사해올 세로크기
blendFunc //복사할때 제외할 픽셀값
);
}
void Renderer::Update()
{
rc = RectMakeCenter(this->gameObject->transform->position.x,
this->gameObject->transform->position.y,
width,
height);
}
void Renderer::Resize(int newWidth, int newHeight)
{
HDC hdc = GetDC(_hWnd);
HDC temp;
HBITMAP scaleBitmap = CreateCompatibleBitmap(hdc, newWidth, newHeight);
SelectObject(memDC, oBit);
oBit = (HBITMAP)SelectObject(memDC, scaleBitmap);
scaleBitmap = CreateCompatibleBitmap(hdc, newWidth, newHeight);
SelectObject(alphaMemDC, scaleBitmap);
ReleaseDC(_hWnd, hdc);
rc = RectMakeCenter(this->gameObject->transform->position.x,
this->gameObject->transform->position.y,
newWidth,
newHeight);
width = newWidth;
height = newHeight;
}