Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ImGui/imgui.h"
- #include "ImGui/imgui_internal.h"
- Renderer* Renderer::m_pInstance;
- Renderer::Renderer()
- {
- }
- Renderer::~Renderer()
- {
- }
- void Renderer::Initialize()
- {
- ImGuiIO& io = ImGui::GetIO();
- // This is my example of font initializing
- // First font used for UI
- // Second for rendering, 32.0f is pixel size, not font size.
- io.Fonts->AddFontFromMemoryTTF(g_fRubik, sizeof(g_fRubik), 16.0f, NULL, io.Fonts->GetGlyphRangesCyrillic());
- m_pFont = io.Fonts->AddFontFromMemoryTTF(g_fRubik, sizeof(g_fRubik), 32.0f, NULL, io.Fonts->GetGlyphRangesCyrillic());
- }
- void Renderer::BeginScene()
- {
- ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
- ImGui::Begin("BackBuffer", reinterpret_cast<bool*>(true), ImVec2(0, 0), 0.0f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs);
- ImGui::SetWindowPos(ImVec2(0, 0), ImGuiSetCond_Always);
- ImGui::SetWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y), ImGuiSetCond_Always);
- }
- void Renderer::DrawScene()
- {
- ImGuiIO& io = ImGui::GetIO();
- DrawText(m_pFont,
- TextFormat(META_STRING("%.0f"), io.Framerate), ImVec2(10, lastY), 32.0f, 0xFFFFFFFF);
- }
- void Renderer::EndScene()
- {
- ImGuiWindow* window = ImGui::GetCurrentWindow();
- window->DrawList->PushClipRectFullScreen();
- ImGui::End();
- ImGui::PopStyleColor();
- }
- float Renderer::DrawText(ImFont* pFont, const std::string& text, const ImVec2& pos, float size, uint32_t color, bool center)
- {
- ImGuiWindow* window = ImGui::GetCurrentWindow();
- float a = (color >> 24) & 0xff;
- float r = (color >> 16) & 0xff;
- float g = (color >> 8) & 0xff;
- float b = (color) & 0xff;
- std::stringstream steam(text);
- std::string line;
- float y = 0.0f;
- int i = 0;
- while (std::getline(steam, line))
- {
- ImVec2 textSize = pFont->CalcTextSizeA(size, FLT_MAX, 0.0f, line.c_str());
- if (center)
- {
- window->DrawList->AddText(pFont, size, ImVec2((pos.x - textSize.x / 2.0f) + 1, (pos.y + textSize.y * i) + 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2((pos.x - textSize.x / 2.0f) - 1, (pos.y + textSize.y * i) - 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2((pos.x - textSize.x / 2.0f) + 1, (pos.y + textSize.y * i) - 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2((pos.x - textSize.x / 2.0f) - 1, (pos.y + textSize.y * i) + 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2(pos.x - textSize.x / 2.0f, pos.y + textSize.y * i), ImGui::GetColorU32(ImVec4(r / 255, g / 255, b / 255, a / 255)), line.c_str());
- }
- else
- {
- window->DrawList->AddText(pFont, size, ImVec2((pos.x) + 1, (pos.y + textSize.y * i) + 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2((pos.x) - 1, (pos.y + textSize.y * i) - 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2((pos.x) + 1, (pos.y + textSize.y * i) - 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2((pos.x) - 1, (pos.y + textSize.y * i) + 1), ImGui::GetColorU32(ImVec4(0, 0, 0, a / 255)), line.c_str());
- window->DrawList->AddText(pFont, size, ImVec2(pos.x, pos.y + textSize.y * i), ImGui::GetColorU32(ImVec4(r / 255, g / 255, b / 255, a / 255)), line.c_str());
- }
- y = pos.y + textSize.y * (i + 1);
- i++;
- }
- return y;
- }
- void Renderer::DrawLine(const ImVec2& from, const ImVec2& to, uint32_t color, float thickness)
- {
- ImGuiWindow* window = ImGui::GetCurrentWindow();
- float a = (color >> 24) & 0xff;
- float r = (color >> 16) & 0xff;
- float g = (color >> 8) & 0xff;
- float b = (color) & 0xff;
- window->DrawList->AddLine(from, to, ImGui::GetColorU32(ImVec4(r / 255, g / 255, b / 255, a / 255)), thickness);
- }
- void Renderer::DrawCircle(const ImVec2& position, float radius, uint32_t color, float thickness)
- {
- ImGuiWindow* window = ImGui::GetCurrentWindow();
- float a = (color >> 24) & 0xff;
- float r = (color >> 16) & 0xff;
- float g = (color >> 8) & 0xff;
- float b = (color) & 0xff;
- window->DrawList->AddCircle(position, radius, ImGui::GetColorU32(ImVec4(r / 255, g / 255, b / 255, a / 255)), 12, thickness);
- }
- void Renderer::DrawCircleFilled(const ImVec2& position, float radius, uint32_t color)
- {
- ImGuiWindow* window = ImGui::GetCurrentWindow();
- float a = (color >> 24) & 0xff;
- float r = (color >> 16) & 0xff;
- float g = (color >> 8) & 0xff;
- float b = (color) & 0xff;
- window->DrawList->AddCircleFilled(position, radius, ImGui::GetColorU32(ImVec4(r / 255, g / 255, b / 255, a / 255)), 12);
- }
- Renderer* Renderer::GetInstance()
- {
- if (!m_pInstance)
- m_pInstance = new Renderer();
- return m_pInstance;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement