summaryrefslogtreecommitdiffstats
path: root/src/Render.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-06-13 10:47:33 +0200
committerLaG1924 <lag1924@gmail.com>2021-06-13 10:47:33 +0200
commitf2266b843959413277767a990bb9a9c5593f3489 (patch)
treef26e90e9f7ceb9be3c108eb5129305356ac8df3a /src/Render.cpp
parentAdded RmlUi to CMakeLists.txt (diff)
downloadAltCraft-f2266b843959413277767a990bb9a9c5593f3489.tar
AltCraft-f2266b843959413277767a990bb9a9c5593f3489.tar.gz
AltCraft-f2266b843959413277767a990bb9a9c5593f3489.tar.bz2
AltCraft-f2266b843959413277767a990bb9a9c5593f3489.tar.lz
AltCraft-f2266b843959413277767a990bb9a9c5593f3489.tar.xz
AltCraft-f2266b843959413277767a990bb9a9c5593f3489.tar.zst
AltCraft-f2266b843959413277767a990bb9a9c5593f3489.zip
Diffstat (limited to '')
-rw-r--r--src/Render.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Render.cpp b/src/Render.cpp
index d583205..7835b98 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -3,6 +3,7 @@
#include <imgui.h>
#include <easylogging++.h>
#include <optick.h>
+#include <RmlUi/Core.h>
#include "imgui_impl_sdl_gl3.h"
#include "Shader.hpp"
@@ -16,6 +17,7 @@
#include "Settings.hpp"
#include "Framebuffer.hpp"
#include "Plugin.hpp"
+#include "Rml.hpp"
Render::Render(unsigned int windowWidth, unsigned int windowHeight,
std::string windowTitle) {
@@ -31,6 +33,8 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight,
glCheckError();
PrepareToRendering();
glCheckError();
+ InitRml();
+ glCheckError();
//Read settings
strcpy(fieldUsername, Settings::Read("username", "HelloOne").c_str());
@@ -73,6 +77,10 @@ Render::~Render() {
Settings::WriteDouble("resolutionScale", fieldResolutionScale);
Settings::Save();
+ Rml::RemoveContext("default");
+ rmlRender.reset();
+ rmlSystem.reset();
+
PluginSystem::Init();
framebuffer.reset();
@@ -125,6 +133,7 @@ void Render::InitGlew() {
glViewport(0, 0, width, height);
glClearColor(0.8,0.8,0.8, 1.0f);
glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LEQUAL);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
@@ -220,6 +229,8 @@ void Render::HandleEvents() {
SDL_GL_GetDrawableSize(window, &width, &height);
renderState.WindowWidth = width;
renderState.WindowHeight = height;
+ rmlRender->Update(width, height);
+ rmlContext->SetDimensions(Rml::Vector2i(width, height));
framebuffer->Resize(width * fieldResolutionScale, height * fieldResolutionScale);
Framebuffer::GetDefault().Resize(width, height);
break;
@@ -331,6 +342,7 @@ void Render::HandleEvents() {
break;
}
}
+ rmlContext->Update();
}
void Render::HandleMouseCapture() {
@@ -366,6 +378,9 @@ void Render::Update() {
void Render::RenderGui() {
OPTICK_EVENT();
+
+ rmlContext->Render();
+
ImGui_ImplSdlGL3_NewFrame(window);
if (isMouseCaptured) {
@@ -750,3 +765,28 @@ void Render::InitEvents() {
}
});
}
+
+void Render::InitRml() {
+ LOG(INFO) << "Initializing Rml";
+
+ rmlSystem = std::make_unique<RmlSystemInterface>();
+ Rml::SetSystemInterface(rmlSystem.get());
+
+ rmlRender = std::make_unique<RmlRenderInterface>(renderState);
+ Rml::SetRenderInterface(rmlRender.get());
+ rmlRender->Update(renderState.WindowWidth, renderState.WindowHeight);
+
+ if (!Rml::Initialise())
+ LOG(WARNING) << "Rml not initialized";
+
+ rmlContext = Rml::CreateContext("default", Rml::Vector2i(renderState.WindowWidth, renderState.WindowHeight));
+
+ if (!Rml::LoadFontFace("OpenSans-Regular.ttf"))
+ LOG(WARNING) << "Rml font not loaded";
+
+ Rml::ElementDocument* document = rmlContext->LoadDocument("test.rml");
+ if (document)
+ document->Show();
+ else
+ LOG(WARNING) << "Rml document not loaded";
+}