├── example
├── screenshot.png
└── main.cpp
├── renderer.vcxproj.filters
├── renderer.sln
├── README.md
├── include
├── font.hpp
├── color.hpp
├── renderer.h
└── renderer.cpp
├── .gitattributes
├── .gitignore
└── renderer.vcxproj
/example/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bulb4/renderer/HEAD/example/screenshot.png
--------------------------------------------------------------------------------
/renderer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | include
7 |
8 |
9 |
10 |
11 | {6bf1e545-4448-4a24-927b-9012dfc1b62f}
12 |
13 |
14 |
15 |
16 | include
17 |
18 |
19 | include
20 |
21 |
22 | include
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/renderer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2042
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "renderer", "renderer.vcxproj", "{D64122D2-48EB-4A94-B3FC-5451A1E2D240}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Debug|x64.ActiveCfg = Debug|x64
17 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Debug|x64.Build.0 = Debug|x64
18 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Debug|x86.ActiveCfg = Debug|Win32
19 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Debug|x86.Build.0 = Debug|Win32
20 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Release|x64.ActiveCfg = Release|x64
21 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Release|x64.Build.0 = Release|x64
22 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Release|x86.ActiveCfg = Release|Win32
23 | {D64122D2-48EB-4A94-B3FC-5451A1E2D240}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {DA715E33-9EB0-4FA5-A251-D303E62CFAF3}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Example
2 |
3 | [SOURCE \*click*](../master/example/main.cpp)
4 | 
5 |
6 | ## Usage
7 |
8 | #### Include:
9 | ```
10 | git submodule add https://github.com/Bulb4/renderer.git
11 | ```
12 |
13 | ```java
14 | #include "..//renderer/include/renderer.h"
15 | ```
16 |
17 | ***
18 | #### Initializing:
19 | If bUseDynamicSinCos is true, circle drawing will be faster but also it will take more memory.
20 | Use it if you do not change points count in runtime
21 |
22 | ```cpp
23 | cRender* pRender = new cRender(g_pd3dDevice, true);//g_pd3dDevice is our IDirect3DDevice9
24 |
25 | ID3DXFont* font1 = nullptr;
26 | pRender->AddFont(&font1, "Consolas", 48, false);
27 |
28 | pRender->SetFramerateUpdateRate(400U);
29 | ```
30 | ***
31 |
32 | #### In your drawing function(EndScene, Present, etc.):
33 | ```cpp
34 | pRender->BeginDraw();
35 |
36 | //drawing stuff
37 |
38 | pRender->EndDraw();
39 | ```
40 | ***
41 | #### In your Reset:
42 | ```cpp
43 | pRender->OnLostDevice();
44 |
45 | if (g_pd3dDevice->Reset(&g_d3dpp) >= 0)
46 | pRender->OnResetDevice();
47 | ```
48 | ***
49 | #### Notes:
50 | * Use `pRender->GetFramerate()` for fps monitoring and you can change it's update rate by `pRender->SetFramerateUpdateRate(400U);//ms`
51 | * Use `pRender->PushRenderState(...)` if you need to use some render states while drawing, but you need to return it's previous value after.
52 | * Use `DrawBox(...)` without `short thickness` argument if the thickness is 1.
53 |
54 | ***
55 | ## Contacts:
56 | * Discord: `Bulb4#2901`
57 | * Steam: [`Bulb4<3`](https://steamcommunity.com/id/bulb4_/)
58 | * e-mail: `bulb4main@gmail.com`
59 |
60 | ***
61 |
--------------------------------------------------------------------------------
/include/font.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "renderer.h"
4 |
5 | class cFont
6 | {
7 | public:
8 | cFont() { }
9 | cFont(IDirect3DDevice9* pDevice)
10 | {
11 | this->pDevice = pDevice;
12 | Update();
13 | }
14 | cFont(IDirect3DDevice9* pDevice, const char* szName, uint8_t iSize)
15 | {
16 | sprintf(this->szName, szName);
17 |
18 | this->iSize = iSize;
19 | this->pDevice = pDevice;
20 |
21 | Update();
22 | }
23 | cFont(IDirect3DDevice9* pDevice, const char* szName, uint8_t iSize, uint16_t iFontWeight, uint16_t iCharset, bool bItalic, bool bAntiAliased)
24 | {
25 | sprintf(this->szName, szName);
26 |
27 | this->iSize = iSize;
28 | this->iFontWeight = iFontWeight;
29 | this->iCharset = iCharset;
30 | this->bItalic = bItalic;
31 | this->bAntiAliased = bAntiAliased;
32 | this->pDevice = pDevice;
33 |
34 | Update();
35 | }
36 |
37 | ~cFont()
38 | {
39 | RELEASE_INTERFACE(pFont);
40 | }
41 |
42 | IDirect3DDevice9* pDevice;
43 | char szName[32] = "System";
44 | int32_t iSize = 14;
45 | //0, 100, 200 ... 1000
46 | uint32_t iFontWeight = FW_NORMAL;
47 | uint32_t iCharset = DEFAULT_CHARSET;
48 | bool bItalic = false;
49 | bool bAntiAliased = false;
50 |
51 | bool Update()
52 | {
53 | RELEASE_INTERFACE(pFont);
54 |
55 | return D3DXCreateFontA(pDevice, iSize, 0,
56 | iFontWeight, 1, BOOL(bItalic), iCharset, OUT_DEFAULT_PRECIS,
57 | bAntiAliased ? ANTIALIASED_QUALITY : NONANTIALIASED_QUALITY,
58 | DEFAULT_PITCH, szName, &pFont) == D3D_OK;
59 | }
60 |
61 | ID3DXFont* GetFont() { return pFont; }
62 |
63 | void OnLostDevice()
64 | {
65 | if (pFont)
66 | pFont->OnLostDevice();
67 | }
68 | void OnResetDevice()
69 | {
70 | if (pFont)
71 | {
72 | pFont->OnResetDevice();
73 | Update();
74 | }
75 | }
76 | private:
77 | ID3DXFont* pFont = nullptr;
78 | };
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/include/color.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #pragma comment(lib,"d3d9.lib")
5 |
6 | #include
7 | #include
8 |
9 | //rgba float[4] to color_t, it should be faster than color_t(float*) constructor
10 | #define PF2COL(color) reinterpret_cast(( \
11 | (((color[3] * 255.f) & 0xff) << 24) | (((color[0] * 255.f) & 0xff) << 16) | \
12 | (((color[1] * 255.f) & 0xff) << 8) | ((color[2] * 255.f) & 0xff)))
13 |
14 | struct color_t
15 | {
16 | D3DCOLOR color;
17 |
18 | inline uint8_t* a() { return reinterpret_cast(&color + 3); }
19 | inline uint8_t* r() { return reinterpret_cast(&color + 2); }
20 | inline uint8_t* g() { return reinterpret_cast(&color + 1); }
21 | inline uint8_t* b() { return reinterpret_cast(&color + 0); }
22 |
23 | inline const float get_a() { return *a() / 255.f; }
24 | inline const float get_r() { return *r() / 255.f; }
25 | inline const float get_g() { return *g() / 255.f; }
26 | inline const float get_b() { return *b() / 255.f; }
27 |
28 | inline void set_a(const float a) { reinterpret_cast(&color)[3] = static_cast(a * 255.f); }
29 | inline void set_r(const float r) { reinterpret_cast(&color)[2] = static_cast(r * 255.f); }
30 | inline void set_g(const float g) { reinterpret_cast(&color)[1] = static_cast(g * 255.f); }
31 | inline void set_b(const float b) { reinterpret_cast(&color)[0] = static_cast(b * 255.f); }
32 |
33 | color_t() : color(0) {}
34 | color_t(int value) : color(value) {}
35 | color_t(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) : color(D3DCOLOR_RGBA(r, g, b, a)) {}
36 | color_t(float* value) : color(D3DCOLOR_COLORVALUE(value[0], value[1], value[2], value[3])) {}
37 |
38 | inline color_t& operator=(const int& rhs)
39 | {
40 | color = rhs;
41 | return *this;
42 | }
43 | inline color_t& operator=(const D3DCOLOR& rhs)
44 | {
45 | color = rhs;
46 | return *this;
47 | }
48 | inline color_t& operator=(const float* rhs)
49 | {
50 | color = D3DCOLOR_COLORVALUE(rhs[0], rhs[1], rhs[2], rhs[3]);
51 | return *this;
52 | }
53 | inline operator const D3DCOLOR() const { return color; }
54 | inline operator const uint8_t*() const { return (uint8_t*)this; }
55 |
56 | void SetHSV(float h, float s, float v, float a = 1.f)
57 | {
58 | if (s == 0.f)// gray
59 | {
60 | color = D3DCOLOR_COLORVALUE(v, v, v, a);
61 | return;
62 | }
63 |
64 | h = fmodf(h, 1.f) / (60.f / 360.f);
65 |
66 | const int i = static_cast(h);
67 | const float f = h - static_cast(i);
68 | const float q = v * (1.f - s * f);
69 | const float t = v * (1.f - s * (1.0f - f));
70 | const float p = v * (1.f - s);
71 |
72 | float r, g, b;
73 |
74 | switch (i)
75 | {
76 | case 0: r = v; g = t; b = p; break;
77 | case 1: r = q; g = v; b = p; break;
78 | case 2: r = p; g = v; b = t; break;
79 | case 3: r = p; g = q; b = v; break;
80 | case 4: r = t; g = p; b = v; break;
81 | default: r = v; g = p; b = q; break;
82 | }
83 |
84 | color = D3DCOLOR_COLORVALUE(r, g, b, a);
85 | }
86 | };
87 |
88 | #define DEF_COLOR(value, name) namespace Colors { static const color_t name = color_t(value); }
89 |
90 | DEF_COLOR(0xFF000000, Black);
91 | DEF_COLOR(0xFFFFFFFF, White);
92 |
93 | DEF_COLOR(0xFFFF0000, Red);
94 | DEF_COLOR(0xFF00FF00, Green);
95 | DEF_COLOR(0xFF0000FF, Blue);
96 |
97 | DEF_COLOR(0xFFFFFF00, Yellow);
98 | DEF_COLOR(0xFF00FFFF, SkyBlue);
99 | DEF_COLOR(0xFFFF00FF, Pink);
--------------------------------------------------------------------------------
/include/renderer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifndef _CRT_SECURE_NO_WARNINGS
4 | #define _CRT_SECURE_NO_WARNINGS
5 | #endif // ! _CRT_SECURE_NO_WARNINGS
6 |
7 | #ifndef _USE_MATH_DEFINES
8 | #define _USE_MATH_DEFINES
9 | #endif // ! _USE_MATH_DEFINES
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include