Added raylib+rmlui template
This commit is contained in:
51
src/Application.cpp
Normal file
51
src/Application.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "Application.h"
|
||||
#include "backend/RaylibInput.h"
|
||||
|
||||
#include <raylib.h>
|
||||
#include <RmlUi/Core.h>
|
||||
#include <RmlUi/Debugger.h>
|
||||
|
||||
bool Application::Init(int width, int height, const char* title, const char* documentPath) {
|
||||
InitWindow(width, height, title);
|
||||
SetTargetFPS(60);
|
||||
|
||||
Rml::SetSystemInterface(&system_interface);
|
||||
Rml::SetRenderInterface(&render_interface);
|
||||
Rml::Initialise();
|
||||
|
||||
context = Rml::CreateContext("main", Rml::Vector2i(width, height));
|
||||
Rml::Debugger::Initialise(context);
|
||||
|
||||
// TODO: load a real font
|
||||
|
||||
if (Rml::ElementDocument* document = context->LoadDocument(documentPath)) {
|
||||
document->Show();
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "Failed to load %s", documentPath);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::Frame() {
|
||||
if (WindowShouldClose()) {
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ForwardInputToRml(context);
|
||||
context->Update();
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(DARKGRAY);
|
||||
|
||||
// --- game world rendering goes here, before the UI ---
|
||||
|
||||
context->Render();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
void Application::Shutdown() {
|
||||
Rml::Shutdown();
|
||||
CloseWindow();
|
||||
}
|
||||
Reference in New Issue
Block a user