Pixels, Surfaces, Renderer, oh my...

This commit is contained in:
BadQuanta
2026-05-11 10:28:21 +00:00
parent 97c8847eb0
commit 28e9c4ba18
35 changed files with 4578 additions and 1210 deletions
+66
View File
@@ -0,0 +1,66 @@
#include <hdk/sdl.hpp> // Hollow Wrapper to SDL
#include <hdk/sdl/main.hpp> // Hollow Wrapper to SDL main boilerplate via hdk::sdl::ApplicationInterface & the macro HDK_SDL_MAIN_CLASS
namespace hello_renderer_2d {
using namespace hdk;
class HelloRenderer2D : public sdl::PublicApp {
public:
const sdl::Log& AppLog { sdl::Log::Application };
grid::eps::TapScope taps, loud;
sdl::evt::AllTypes events;
const sdl::evt::EventConduit::Callback_t LOG_EVENT = [&](SDL_Event* event) {
auto description = sdl::Event::GetDescription<1024>(event);
AppLog.Debug("Event received: %s", description.c_str());
};
virtual SDL_AppResult Event(SDL_Event* event) override {
// Get a description of the event for logging, you can adjust the buffer size as needed, defaults to 512
events.Trigger(event);
return AppStatus;
}
sdl::Window window { nullptr };
sdl::Renderer renderer { nullptr };
virtual SDL_AppResult Init(int argc, char* argv[]) override {
sdl::Log::SetPriorities(SDL_LOG_PRIORITY_DEBUG);
auto [w, r] = sdl::CreateWindowAndRenderer("Hello World", 800, 600, 0);
window = w;
renderer = r;
if (!window || !renderer) {
SDL_Log("Failed to create window or renderer: %s", SDL_GetError());
return AppStatus = SDL_APP_FAILURE;
}
renderer.SetLogicalPresentation(800, 600, SDL_LOGICAL_PRESENTATION_LETTERBOX);
renderer.SetDrawColor(255, 0, 0, 0);
taps << events.Quit.Attach([&](SDL_Event* event) {
AppStatus = SDL_APP_SUCCESS;
printf("Quit event received, exiting...\n");
});
loud << events.Attach(LOG_EVENT);
SDL_WindowID window_id = window.GetID();
taps << events.Window[window_id].MouseLeave.Attach([&](SDL_Event* event) {
AppLog.Info("Mouse left the window!");
loud.PauseAll();
});
taps << events.Window[window_id].MouseEnter.Attach([&](SDL_Event* event) {
AppLog.Info("Mouse entered the window!");
loud.ResumeAll();
});
return AppStatus;
}
virtual SDL_AppResult Iterate() override {
renderer.SetDrawColor(255, 0, 0, 0);
renderer.FillRect(nullptr);
renderer.SetDrawColor(255, 255, 255, 255);
renderer.DebugTextFormat(0, 0, "Displays: %d", sdl::Display::GetDisplays().size());
renderer.DebugTextFormat(0, 20, "Render Drivers: %d", sdl::Renderer::GetNumRenderDrivers());
renderer.Present();
return AppStatus;
}
};
}
// We tell the HDK_SDL_MAIN_CLASS macro to use our HelloRenderer2D class
HDK_SDL_MAIN_CLASS(hello_renderer_2d::HelloRenderer2D)
// this builds all the SDL main boilerplate and connects it to our HelloRenderer2D class