testbed: application skel

This commit is contained in:
Michele Caini
2025-03-31 14:41:50 +02:00
parent 9c39f76774
commit 86d3d2207a
4 changed files with 108 additions and 7 deletions

View File

@@ -46,16 +46,16 @@ target_compile_definitions(
target_sources(
testbed
PRIVATE
testbed.cpp
app/context.cpp
application/application.cpp
application/context.cpp
testbed.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp
)
target_link_libraries(

View File

@@ -0,0 +1,74 @@
#include <cstdint>
#include <SDL3/SDL.h>
#include <application/application.h>
#include <application/context.h>
#include <backends/imgui_impl_sdl3.h>
#include <backends/imgui_impl_sdlrenderer3.h>
#include <imgui.h>
namespace testbed {
void application::update() {
ImGui_ImplSDLRenderer3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
// update...
}
void application::draw(const context &context) const {
SDL_SetRenderDrawColor(context, 0u, 0u, 0u, SDL_ALPHA_OPAQUE);
SDL_RenderClear(context);
// draw...
ImGui::Render();
ImGuiIO &io = ImGui::GetIO();
SDL_SetRenderScale(context, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), context);
SDL_RenderPresent(context);
}
void application::input() {
ImGuiIO &io = ImGui::GetIO();
SDL_Event event{};
while(SDL_PollEvent(&event)) {
ImGui_ImplSDL3_ProcessEvent(&event);
switch(event.type) {
case SDL_EVENT_KEY_DOWN:
switch(event.key.key) {
case SDLK_ESCAPE:
quit = true;
break;
}
break;
}
}
}
application::application()
: quit{} {
SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO);
}
application::~application() {
SDL_Quit();
}
int application::run() {
context context{};
quit = false;
while(!quit) {
update();
draw(context);
input();
}
return 0;
}
} // namespace testbed

View File

@@ -0,0 +1,27 @@
#pragma once
#include <SDL3/SDL_events.h>
struct SDL_Renderer;
namespace testbed {
struct config;
struct context;
class application {
void update();
void draw(const context &) const;
void input();
public:
application();
~application();
int run();
private:
bool quit;
};
} // namespace testbed

View File

@@ -1,6 +1,6 @@
#include <application/context.h>
#include <application/application.h>
int main() {
testbed::context ctx{};
return 0;
testbed::application application{};
return application.run();
}