-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIRenderer.cpp
More file actions
108 lines (95 loc) · 2.91 KB
/
UIRenderer.cpp
File metadata and controls
108 lines (95 loc) · 2.91 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
#include "stdafx.h"
#include "UIRenderer.h"
UIRenderer::UIRenderer()
{
}
UIRenderer::~UIRenderer()
{
}
void UIRenderer::Init()
{
HDC hdc = GetDC(_hWnd);
width = 100;
height = 100;
memDC = CreateCompatibleDC(hdc);
hBit = (HBITMAP)CreateCompatibleBitmap(hdc, width, height);
oBit = (HBITMAP)SelectObject(memDC, hBit);
hBit = (HBITMAP)CreateCompatibleBitmap(hdc, width, height);
SelectObject(alphaMemDC, hBit);
ReleaseDC(_hWnd, hdc);
transform->SetX(0);
transform->SetY(0);
alpha = 255;
blendFunction.BlendOp = AC_SRC_OVER;
blendFunction.BlendFlags = 0;
blendFunction.AlphaFormat = 0;
blendFunction.SourceConstantAlpha = alpha;
}
void UIRenderer::Init(const char* filename, int width, int height)
{
HDC hdc = GetDC(_hWnd);
this->width = width;
this->height = height;
memDC = CreateCompatibleDC(hdc);
hBit = (HBITMAP)LoadImage(_hInstance, filename, IMAGE_BITMAP, width, height, LR_LOADFROMFILE);
oBit = (HBITMAP)SelectObject(memDC, hBit);
hBit = CreateCompatibleBitmap(hdc, width, height);
SelectObject(alphaMemDC, hBit);
ReleaseDC(_hWnd, hdc);
transform->SetX(0);
transform->SetY(0);
alpha = 255;
blendFunction.BlendOp = AC_SRC_OVER;
blendFunction.BlendFlags = 0;
blendFunction.AlphaFormat = 0;
blendFunction.SourceConstantAlpha = alpha;
}
void UIRenderer::Update()
{
}
void UIRenderer::Render()
{
int startX = CAMERAMANAGER->mainCam->transform->GetX() + transform->GetX() - width/2;
int startY = CAMERAMANAGER->mainCam->transform->GetY() + transform->GetY() - height / 2;
BitBlt(alphaMemDC, 0, 0, width, height, _backBuffer->getMemDC(), startX, startY, 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
startX, //출력할 DC에서 그림의 찍을 좌표 x
startY, //출력할 DC에서 그림의 찍을 좌표 y
width, //출력한 DC에서 그림의 가로 길이
height, //출력한 DC에서 그림의 세로 길이
memDC, //그림의 DC
0, //그림에서 그리기 시작할 좌표 x
0, //그림에서 그리기 시작할 좌표 y
width, //그림에서 출력DC에 그릴 그림의 가로 길이
height, //그림에서 출력DC에 그릴 그림의 세로 길이
blendFunction); //알파블렌드에서의 옵션값
}
void UIRenderer::Resize(int width, int height)
{
HDC hdc = GetDC(_hWnd);
this->width = width;
this->height = height;
memDC = CreateCompatibleDC(hdc);
hBit = (HBITMAP)CreateCompatibleBitmap(hdc, width, height);
SelectObject(memDC, oBit);
oBit = (HBITMAP)SelectObject(memDC, hBit);
hBit = (HBITMAP)CreateCompatibleBitmap(hdc, width, height);
SelectObject(alphaMemDC, hBit);
}
void UIRenderer::SetAlpha(int alpha)
{
this->alpha = alpha;
blendFunction.SourceConstantAlpha = this->alpha;
}