Replies: 1 comment 7 replies
-
Hi. Overall this looks pretty reasonable to me, with your specific requirements. You could perhaps consider taking advantage of our backend targets directly, as shown below. For people starting out fresh, I would generally recommend to use a package manager, like So far we have mainly treated the backends as example code. There are just so many ways to set things up, and a lot of customization options, so it is a bit hard to find something that can be widely recommended. And each backend has something specific to it. But maybe we could make some improvements. There has also been some chatter of adding the various backends as features to e.g. vcpkg. For users that want something quicker up and running, you could take advantage of our cmake targets for the backends. This one also handles transitive dependencies. Here is something quite minimal that should work, assuming that Freetype, SDL3, and SDL3-image is available somehow (skipping the custom loader here).
cmake_minimum_required(VERSION 3.27)
project(Snake)
set(CMAKE_CXX_STANDARD 20)
find_package(Freetype CONFIG REQUIRED)
find_package(SDL3 CONFIG REQUIRED)
find_package(SDL3_image CONFIG REQUIRED)
include(FetchContent)
set(RMLUI_BACKEND "SDL_GL3" CACHE STRING "RmlUi Backend")
# This ensures the backend targets are added. We are setting this manually as an alternative to enabling the samples.
set(RMLUI_SHELL ON)
FetchContent_Declare(
RmlUi
GIT_REPOSITORY https://github.com/mikke89/RmlUi.git
GIT_TAG 47476069e9283f39333331e0afaa58be26dfa44a
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(RmlUi)
add_executable(Snake main.cpp)
target_link_libraries(Snake PUBLIC
RmlUi::RmlUi
rmlui_backend_SDL_GL3
)
#include <RmlUi/Core.h>
#include <RmlUi/Debugger.h>
#include <RmlUi_Backend.h>
static const char* document_rml = R"(
<rml>
<head>
<style>
body {
font-family: rmlui-debugger-font;
font-size: 12px;
top: 100px; right: 100px; bottom: 100px; left: 100px;
padding: 150px;
text-align: center;
background: #333;
color: white;
}
p {
display: block;
padding: 30px;
}
p:hover {
background: #444;
}
</style>
</head>
<body>
<p>Hello world!</p>
</body>
</rml>
)";
int main() {
Backend::Initialize("Znake", 1024, 768, true);
Rml::SetSystemInterface(Backend::GetSystemInterface());
Rml::SetRenderInterface(Backend::GetRenderInterface());
Rml::Initialise();
Rml::Context *context = Rml::CreateContext("Znake", {1024, 768});
Rml::Debugger::Initialise(context);
Rml::Debugger::SetVisible(true);
Rml::ElementDocument *document = context->LoadDocumentFromMemory(document_rml);
document->Show();
while (Backend::ProcessEvents(context)) {
context->Update();
Backend::BeginFrame();
context->Render();
Backend::PresentFrame();
}
Rml::Shutdown();
Backend::Shutdown();
return 0;
} Have fun with the library, and make sure to show us your creations in time :) Let us know if there is anything we can help out with. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. My C++ project is using SDL3 for system interactions, OpenGL3 with glad loader, Lua (sol3) for scripting, and have been using Nuklear for GUI. Nuklear and Dear ImGUI are excellent choices for a quick & simple GUI, however, immediate mode UIs are an absolute pain to integrate with scripting, and has some other limiting caveats, e.g. constant CPU load.
Thus, I decided to switch to RmlUi, which looks promising to me - UI layout can be defined in separate files (so no need to bind it to Lua to make UI moddable; and if I need, it has some kind of Lua support, which I haven't looked into yet), performance seems to be +- fine, support for SDL3 and GL3. Though, trying to integrate it had led me to several pitfalls, which are not covered in docs and samples.
So, I'd like to ask if my solution is optimal, note some problems and share it for those trying to do the same:
Beta Was this translation helpful? Give feedback.
All reactions