testbed: context class
This commit is contained in:
@@ -31,24 +31,23 @@ endif()
|
||||
|
||||
# Testbed executable
|
||||
|
||||
set(ENTT_TESTBED_EXECUTABLE testbed)
|
||||
add_executable(testbed)
|
||||
|
||||
add_executable(${ENTT_TESTBED_EXECUTABLE})
|
||||
|
||||
set_target_properties(${ENTT_TESTBED_EXECUTABLE} PROPERTIES CXX_EXTENSIONS OFF)
|
||||
target_compile_features(${ENTT_TESTBED_EXECUTABLE} PUBLIC ${ENTT_CXX_STD})
|
||||
set_target_properties(testbed PROPERTIES CXX_EXTENSIONS OFF)
|
||||
target_compile_features(testbed PUBLIC ${ENTT_CXX_STD})
|
||||
|
||||
target_compile_definitions(
|
||||
${ENTT_TESTBED_EXECUTABLE}
|
||||
testbed
|
||||
PRIVATE
|
||||
ENTT_ID_TYPE=${ENTT_ID_TYPE}
|
||||
NOMINMAX
|
||||
)
|
||||
|
||||
target_sources(
|
||||
${ENTT_TESTBED_EXECUTABLE}
|
||||
testbed
|
||||
PRIVATE
|
||||
testbed.cpp
|
||||
app/context.cpp
|
||||
${imgui_SOURCE_DIR}/imgui.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
||||
@@ -59,15 +58,15 @@ target_sources(
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
${ENTT_TESTBED_EXECUTABLE}
|
||||
testbed
|
||||
PRIVATE
|
||||
EnTT::EnTT
|
||||
SDL3::SDL3
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
${ENTT_TESTBED_EXECUTABLE}
|
||||
testbed
|
||||
PRIVATE
|
||||
${testbed_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${imgui_SOURCE_DIR}
|
||||
)
|
||||
|
||||
63
testbed/app/context.cpp
Normal file
63
testbed/app/context.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <app/context.h>
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
#include <backends/imgui_impl_sdlrenderer3.h>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace testbed {
|
||||
|
||||
namespace internal {
|
||||
|
||||
static constexpr const char *window_default_title = "testbed";
|
||||
static constexpr int window_default_width = 1280;
|
||||
static constexpr int window_default_height = 720;
|
||||
|
||||
} // namespace internal
|
||||
|
||||
context::context()
|
||||
: sdl_window{SDL_CreateWindow(internal::window_default_title, internal::window_default_width, internal::window_default_height, SDL_WINDOW_HIGH_PIXEL_DENSITY)},
|
||||
sdl_renderer{SDL_CreateRenderer(sdl_window, nullptr)} {
|
||||
SDL_SetRenderVSync(sdl_renderer, SDL_RENDERER_VSYNC_ADAPTIVE);
|
||||
|
||||
SDL_SetWindowResizable(sdl_window, true);
|
||||
SDL_SetWindowPosition(sdl_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplSDL3_InitForSDLRenderer(sdl_window, sdl_renderer);
|
||||
ImGui_ImplSDLRenderer3_Init(sdl_renderer);
|
||||
}
|
||||
|
||||
context ::~context() {
|
||||
ImGui_ImplSDLRenderer3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
SDL_DestroyRenderer(sdl_renderer);
|
||||
SDL_DestroyWindow(sdl_window);
|
||||
}
|
||||
|
||||
SDL_Window *context::window() const noexcept {
|
||||
return *this;
|
||||
}
|
||||
|
||||
SDL_Renderer *context::renderer() const noexcept {
|
||||
return *this;
|
||||
}
|
||||
|
||||
context::operator SDL_Window *() const noexcept {
|
||||
return sdl_window;
|
||||
}
|
||||
|
||||
context::operator SDL_Renderer *() const noexcept {
|
||||
return sdl_renderer;
|
||||
}
|
||||
|
||||
} // namespace testbed
|
||||
29
testbed/app/context.h
Normal file
29
testbed/app/context.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
struct SDL_Renderer;
|
||||
struct SDL_Window;
|
||||
|
||||
namespace testbed {
|
||||
|
||||
struct context {
|
||||
context();
|
||||
~context();
|
||||
|
||||
context(const context &) = delete;
|
||||
context(context &&) = delete;
|
||||
|
||||
context &operator=(const context &) = delete;
|
||||
context &operator=(context &&) = delete;
|
||||
|
||||
SDL_Window *window() const noexcept;
|
||||
SDL_Renderer *renderer() const noexcept;
|
||||
|
||||
operator SDL_Window *() const noexcept;
|
||||
operator SDL_Renderer *() const noexcept;
|
||||
|
||||
private:
|
||||
SDL_Window *sdl_window;
|
||||
SDL_Renderer *sdl_renderer;
|
||||
};
|
||||
|
||||
} // namespace testbed
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <entt/entt.hpp>
|
||||
#include <app/context.h>
|
||||
|
||||
int main() {
|
||||
[[maybe_unused]] entt::registry registry;
|
||||
testbed::context ctx{};
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user