-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRenderManager.cpp
236 lines (197 loc) · 6.93 KB
/
RenderManager.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
/*
Syn's AyyWare Framework 2015
*/
#pragma once
#include "RenderManager.h"
#define _CRT_SECURE_NO_WARNINGS
// Font Instances
namespace Render
{
// Text functions
namespace Fonts
{
DWORD Default;
DWORD Menu;
DWORD MenuBold;
DWORD ESP;
};
};
// We don't use these anywhere else, no reason for them to be
// available anywhere else
enum EFontFlags
{
FONTFLAG_NONE,
FONTFLAG_ITALIC = 0x001,
FONTFLAG_UNDERLINE = 0x002,
FONTFLAG_STRIKEOUT = 0x004,
FONTFLAG_SYMBOL = 0x008,
FONTFLAG_ANTIALIAS = 0x010,
FONTFLAG_GAUSSIANBLUR = 0x020,
FONTFLAG_ROTARY = 0x040,
FONTFLAG_DROPSHADOW = 0x080,
FONTFLAG_ADDITIVE = 0x100,
FONTFLAG_OUTLINE = 0x200,
FONTFLAG_CUSTOM = 0x400,
FONTFLAG_BITMAP = 0x800,
};
// Initialises the rendering system, setting up fonts etc
void Render::Initialise()
{
Fonts::Default = 0x1D; // MainMenu Font from vgui_spew_fonts
Fonts::Menu = Interfaces::Surface->FontCreate();
Fonts::MenuBold = Interfaces::Surface->FontCreate();
Fonts::ESP = Interfaces::Surface->FontCreate();
Interfaces::Surface->SetFontGlyphSet(Fonts::Menu, "DINPro-Regular", 14, 500, 0, 0, FONTFLAG_ANTIALIAS);
Interfaces::Surface->SetFontGlyphSet(Fonts::MenuBold, "DINPro-Regular", 14, 900, 0, 0, FONTFLAG_ANTIALIAS);
Interfaces::Surface->SetFontGlyphSet(Fonts::ESP, "DINPro-Regular", 14, 500, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW);
Utilities::Log("Render System Ready");
}
RECT Render::GetViewport()
{
RECT Viewport = { 0, 0, 0, 0 };
int w, h;
Interfaces::Engine->GetScreenSize(w, h);
Viewport.right = w; Viewport.bottom = h;
return Viewport;
}
void Render::Clear(int x, int y, int w, int h, Color color)
{
Interfaces::Surface->DrawSetColor(color);
Interfaces::Surface->DrawFilledRect(x, y, x + w, y + h);
}
void Render::Outline(int x, int y, int w, int h, Color color)
{
Interfaces::Surface->DrawSetColor(color);
Interfaces::Surface->DrawOutlinedRect(x, y, x + w, y + h);
}
void Render::Line(int x, int y, int x2, int y2, Color color)
{
Interfaces::Surface->DrawSetColor(color);
Interfaces::Surface->DrawLine(x, y, x2, y2);
}
void Render::PolyLine(int *x, int *y, int count, Color color)
{
Interfaces::Surface->DrawSetColor(color);
Interfaces::Surface->DrawPolyLine(x, y, count);
}
bool Render::WorldToScreen(Vector &in, Vector &out)
{
const matrix3x4& worldToScreen = Interfaces::Engine->WorldToScreenMatrix(); //Grab the world to screen matrix from CEngineClient::WorldToScreenMatrix
float w = worldToScreen[3][0] * in[0] + worldToScreen[3][1] * in[1] + worldToScreen[3][2] * in[2] + worldToScreen[3][3]; //Calculate the angle in compareson to the player's camera.
out.z = 0; //Screen doesn't have a 3rd dimension.
if (w > 0.001) //If the object is within view.
{
RECT ScreenSize = GetViewport();
float fl1DBw = 1 / w; //Divide 1 by the angle.
out.x = (ScreenSize.right / 2) + (0.5f * ((worldToScreen[0][0] * in[0] + worldToScreen[0][1] * in[1] + worldToScreen[0][2] * in[2] + worldToScreen[0][3]) * fl1DBw) * ScreenSize.right + 0.5f); //Get the X dimension and push it in to the Vector.
out.y = (ScreenSize.bottom / 2) - (0.5f * ((worldToScreen[1][0] * in[0] + worldToScreen[1][1] * in[1] + worldToScreen[1][2] * in[2] + worldToScreen[1][3]) * fl1DBw) * ScreenSize.bottom + 0.5f); //Get the Y dimension and push it in to the Vector.
return true;
}
return false;
}
void Render::Text(int x, int y, Color color, DWORD font, const char* text)
{
size_t origsize = strlen(text) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
Interfaces::Surface->DrawSetTextFont(font);
Interfaces::Surface->DrawSetTextColor(color);
Interfaces::Surface->DrawSetTextPos(x, y);
Interfaces::Surface->DrawPrintText(wcstring, wcslen(wcstring));
return;
}
void Render::Text(int x, int y, Color color, DWORD font, const wchar_t* text)
{
Interfaces::Surface->DrawSetTextFont(font);
Interfaces::Surface->DrawSetTextColor(color);
Interfaces::Surface->DrawSetTextPos(x, y);
Interfaces::Surface->DrawPrintText(text, wcslen(text));
}
void Render::Textf(int x, int y, Color color, DWORD font, const char* fmt, ...)
{
if (!fmt) return; //if the passed string is null return
if (strlen(fmt) < 2) return;
//Set up va_list and buffer to hold the params
va_list va_alist;
char logBuf[256] = { 0 };
//Do sprintf with the parameters
va_start(va_alist, fmt);
_vsnprintf_s(logBuf + strlen(logBuf), 256 - strlen(logBuf), sizeof(logBuf) - strlen(logBuf), fmt, va_alist);
va_end(va_alist);
Text(x, y, color, font, logBuf);
}
RECT Render::GetTextSize(DWORD font, const char* text)
{
size_t origsize = strlen(text) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
RECT rect; int x, y;
Interfaces::Surface->GetTextSize(font, wcstring, x, y);
rect.left = x; rect.bottom = y;
rect.right = x;
return rect;
}
void Render::GradientV(int x, int y, int w, int h, Color c1, Color c2)
{
Clear(x, y, w, h, c1);
BYTE first = c2.r();
BYTE second = c2.g();
BYTE third = c2.b();
for (int i = 0; i < h; i++)
{
float fi = i, fh = h;
float a = fi / fh;
DWORD ia = a * 255;
Clear(x, y + i, w, 1, Color(first, second, third, ia));
}
}
void Render::GradientH(int x, int y, int w, int h, Color c1, Color c2)
{
Clear(x, y, w, h, c1);
BYTE first = c2.r();
BYTE second = c2.g();
BYTE third = c2.b();
for (int i = 0; i < w; i++)
{
float fi = i, fw = w;
float a = fi / fw;
DWORD ia = a * 255;
Clear(x + i, y, 1, h, Color(first, second, third, ia));
}
}
void Render::Polygon(int count, Vertex_t* Vertexs, Color color)
{
static int Texture = Interfaces::Surface->CreateNewTextureID(true); //need to make a texture with procedural true
unsigned char buffer[4] = { 255, 255, 255, 255 };//{ color.r(), color.g(), color.b(), color.a() };
Interfaces::Surface->DrawSetTextureRGBA(Texture, buffer, 1, 1); //Texture, char array of texture, width, height
Interfaces::Surface->DrawSetColor(color); // keep this full color and opacity use the RGBA @top to set values.
Interfaces::Surface->DrawSetTexture(Texture); // bind texture
Interfaces::Surface->DrawTexturedPolygon(count, Vertexs);
}
void Render::PolygonOutline(int count, Vertex_t* Vertexs, Color color, Color colorLine)
{
static int x[128];
static int y[128];
Render::Polygon(count, Vertexs, color);
for (int i = 0; i < count; i++)
{
x[i] = Vertexs[i].m_Position.x;
y[i] = Vertexs[i].m_Position.y;
}
Render::PolyLine(x, y, count, colorLine);
}
void Render::PolyLine(int count, Vertex_t* Vertexs, Color colorLine)
{
static int x[128];
static int y[128];
for (int i = 0; i < count; i++)
{
x[i] = Vertexs[i].m_Position.x;
y[i] = Vertexs[i].m_Position.y;
}
Render::PolyLine(x, y, count, colorLine);
}