Skip to content
This repository was archived by the owner on Aug 2, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "external/msdf-atlas-gen"]
path = external/msdf-atlas-gen
url = https://github.com/Chlumsky/msdf-atlas-gen.git
[submodule "external/imgui"]
path = external/imgui
url = https://github.com/ocornut/imgui.git
[submodule "external/nfd-extended"]
path = external/nfd-extended
url = https://github.com/btzy/nativefiledialog-extended.git
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# SDL2
find_package(imgui CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(nfd CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_path(EARCUT_HPP_INCLUDE_DIRS "mapbox/earcut.hpp")
find_package(Freetype REQUIRED)
find_package(Templi CONFIG REQUIRED) # 4.1.31

set(SDLK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SDLK_IS_MAIN_PROJECT OFF)
Expand Down Expand Up @@ -67,7 +70,6 @@ if (SDLK_IS_MAIN_PROJECT)
@ONLY)
endif ()

add_subdirectory(external/nfd-extended)
add_subdirectory(external/msdf-atlas-gen)
add_subdirectory(sources)
add_subdirectory(examples)
Expand Down
2 changes: 2 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"MSDF_ATLAS_BUILD_STANDALONE": "OFF",
"MSDF_ATLAS_INSTALL": "ON",
"MSDF_ATLAS_USE_SKIA": "OFF",
"MSDF_ATLAS_USE_VCPKG": "ON",
"CMAKE_TOOLCHAIN_FILE": "/home/ricka/Apk/vcpkg/scripts/buildsystems/vcpkg.cmake"
Expand Down
15 changes: 10 additions & 5 deletions cmake/sdlkConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@SDLK_LIB_NAME@Targets.cmake")
include(CMakeFindDependencyMacro)

if(EXISTS "@CMAKE_SOURCE_DIR@/resources")
file(COPY "@CMAKE_SOURCE_DIR@/resources"
DESTINATION "${CMAKE_BINARY_DIR}/bin")
endif()
find_dependency(glm CONFIG)
find_dependency(SDL2 CONFIG)
find_dependency(imgui CONFIG)
find_dependency(SDL2_image CONFIG)
find_dependency(nlohmann_json CONFIG)

include("${CMAKE_CURRENT_LIST_DIR}/sdlkTargets.cmake")

check_required_components(sdlk)
38 changes: 0 additions & 38 deletions cmake/sdlk_resources.cmake

This file was deleted.

4 changes: 1 addition & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
add_executable(example main.cpp
../include/sdlk/core/imgui/imgui_drawer_utils.hpp
../include/sdlk/extra/nfd_wrapper.hpp)
add_executable(example main.cpp)

target_include_directories(example PRIVATE ${SDLK_SOURCE_DIR}/include)

Expand Down
10 changes: 5 additions & 5 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ auto rectangle_with_vertex_color() -> std::shared_ptr<renderable>;

auto main(const int argc, char** argv) -> int
{
app rc_engine("RC_Engine", 1200, 800);
auto rc_engine = app::make("RC_Engine", 1200, 800);

rc_engine.add_view("home", home());
rc_engine->add_view("home", home());

rc_engine.add_event_listener(
rc_engine->add_event_listener(
event_type::key_up, [&](const SDL_Event& event) { std::cout << "Clicked \n"; });

return rc_engine.run("home", argc, argv);
return rc_engine->run("home", argc, argv);
}

auto home() -> std::shared_ptr<renderable>
Expand All @@ -38,7 +38,7 @@ auto home() -> std::shared_ptr<renderable>

auto text_hello_world() -> std::shared_ptr<renderable>
{
auto font = msdf_font::make("./resources/assets/fonts/arial.ttf");
auto font = sdlk2d::msdf_font::make("./resources/assets/fonts/arial.ttf");
return std::make_shared<sdlk2d::text_shape>(U"Hello World helloé",
sdlk2d::text_style{ .m_size = 20.0f, .m_fg_color = color::white() },
font);
Expand Down
1 change: 0 additions & 1 deletion external/imgui
Submodule imgui deleted from 5166be
1 change: 0 additions & 1 deletion external/nfd-extended
Submodule nfd-extended deleted from fc168e
101 changes: 23 additions & 78 deletions include/sdlk/core/components/2d/fonts/msdf_font.hpp
Original file line number Diff line number Diff line change
@@ -1,92 +1,37 @@
//
// Created by ricka on 2026-01-18.
// Created by ricka on 2026-05-18.
//

#pragma once

#include <msdf-atlas-gen/msdf-atlas-gen.h>

#include <memory>
#include <optional>
#include <sdlk/core/gl/gl_texture.hpp>

#define MIN_SIDE 256
#include <string>

namespace sdlk
namespace sdlk2d
{
using namespace msdf_atlas;

using charset = Charset;
using font_geometry = FontGeometry;
using font_metrics = msdfgen::FontMetrics;
using glyph_geometry = GlyphGeometry;
using font_handle = msdfgen::FontHandle;

using bitmap = msdfgen::Bitmap<byte, 3>;
using bitmap_ref = msdfgen::BitmapRef<byte, 3>;
using bitmap_const_ref = msdfgen::BitmapConstRef<byte, 3>;
using msdf_dynamic_atlas =
DynamicAtlas<ImmediateAtlasGenerator<float, 3, msdfGenerator, BitmapAtlasStorage<byte, 3>>>;

struct msdf_font_conf
{
const float m_pixel_range = 2;
const float m_glyph_scale = 32.0;
const float m_miter_limit = 1.0;
const float m_max_corner_angle = 3.0;
};

struct glyph_storage
{
font_handle *m_font_handle{};
std::vector<glyph_geometry> m_data{};
font_geometry m_font_geometry{ &m_data };
std::unordered_map<char32_t, glyph_geometry *> m_glyphs{};

[[nodiscard]] auto size() const -> size_t;
[[nodiscard]] auto is_loaded(const char32_t &character) const -> bool;
[[nodiscard]] auto slice(size_t start_index) -> glyph_geometry *;
[[nodiscard]] auto get(const char32_t &character)
-> std::optional<std::reference_wrapper<const GlyphGeometry>>;

auto invalidate_glyphs_map() -> void;
auto load(const charset &charset) -> void;

~glyph_storage();
};

class msdf_font final
{
msdf_font_conf m_conf{};
bitmap_const_ref m_bitmap{};
msdf_dynamic_atlas m_atlas{ 256 };

bool m_texture_initialized{ false };
std::shared_ptr<gl_texture> m_texture{};

glyph_storage m_glyph_storage{ nullptr };

auto update_texture(msdf_dynamic_atlas::ChangeFlags flags) -> void;
auto add_to_atlas(size_t start_index) -> msdf_dynamic_atlas::ChangeFlags;
class msdf_font_impl;

public:
explicit msdf_font(const std::string &font_path, msdf_font_conf &&conf = {});
struct msdf_font_conf
{
const float m_pixel_range = 2;
const float m_glyph_scale = 32.0;
const float m_miter_limit = 1.0;
const float m_max_corner_angle = 3.0;
};

static auto make(const std::string &font_path) -> std::shared_ptr<msdf_font>;
class msdf_font
{
msdf_font_conf m_conf;
std::shared_ptr<msdf_font_impl> m_impl;

[[nodiscard]] auto get(const char32_t &c)
-> std::optional<std::reference_wrapper<const GlyphGeometry>>;
public:
explicit msdf_font(const std::string &path, msdf_font_conf conf = {});

[[nodiscard]] auto get_conf() const -> msdf_font_conf;
[[nodiscard]] auto get_bitmap() const -> bitmap_const_ref;
[[nodiscard]] auto is_loaded(const char32_t &c) const -> bool;
[[nodiscard]] auto get_texture() const -> std::shared_ptr<gl_texture>;
[[nodiscard]] auto get_metrics() const -> font_metrics;
[[nodiscard]] auto get_impl() const -> std::shared_ptr<msdf_font_impl>;

auto load(const Charset &charset) -> void;
auto load(const char32_t &character) -> void;
auto load(const std::u32string &text) -> void;
[[nodiscard]] static auto make(const std::string &path, msdf_font_conf conf = {}) -> std::shared_ptr<msdf_font>;

~msdf_font() = default;
};
} // namespace sdlk
msdf_font() = delete;
~msdf_font() = default;
};
}
4 changes: 2 additions & 2 deletions include/sdlk/core/components/2d/shape/text_shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace sdlk2d
protected:
text_style m_style{};
std::u32string m_text{};
std::shared_ptr<sdlk::msdf_font> m_font{};
std::shared_ptr<msdf_font> m_font{};

auto update_vertices() -> void;

public:
explicit text_shape(std::u32string text,
const text_style &text_style,
const std::shared_ptr<sdlk::msdf_font> &font);
const std::shared_ptr<msdf_font> &font);

auto render(const std::shared_ptr<sdlk::gl_program> &program) -> void override;
};
Expand Down
8 changes: 8 additions & 0 deletions sources/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ set(SDLK_ENGINE_SOURCES
views/home/draw_project_card.cpp
conf/sdlk_engine_conf.cpp
utils/os.cpp
utils/utils.cpp
views/project_editor/project_editor.cpp
views/home/trigger_open_project.cpp
views/home/trigger_new_project.cpp
views/home/get_last_projects.cpp
views/home/draw_home_options.cpp
views/home/draw_create_project.cpp
)

add_executable(${SDLK_ENGINE_NAME} ${SDLK_ENGINE_SOURCES})
Expand All @@ -22,6 +28,8 @@ target_include_directories(${SDLK_ENGINE_NAME} PRIVATE ${SDLK_SOURCE_DIR}/includ

target_link_libraries(${SDLK_ENGINE_NAME} PRIVATE ${SDLK_LIB_NAME})

target_link_libraries(${SDLK_ENGINE_NAME} PRIVATE Templi)

set_target_properties(${SDLK_ENGINE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

if (SDLK_ENGINE_INSTALL)
Expand Down
15 changes: 14 additions & 1 deletion sources/engine/conf/sdlk_engine_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,30 @@

#define SDLK_CONF_DIRECTORY ".sdlk-engine"
#define SDLK_CONF_FILE "sdlk-engine.conf.json"
#define SDLK_TEMPLATE_DIRECTORY "template-release"

using json = nlohmann::json;

sdlk_engine_conf::sdlk_engine_conf(std::string version, const std::vector<std::string> &last_project)
: m_version(std::move(version)), m_last_project_paths(last_project)
{}

auto sdlk_engine_conf::get_config_path() -> std::filesystem::path
{
const auto home_path = std::filesystem::path(os::get_home_dir());
return home_path / SDLK_CONF_DIRECTORY;
}

auto sdlk_engine_conf::get_file_path() -> std::filesystem::path
{
const auto home_path = std::filesystem::path(os::get_home_dir());
return std::filesystem::path(home_path / SDLK_CONF_DIRECTORY) / SDLK_CONF_FILE;
return get_config_path() / SDLK_CONF_FILE;
}

auto sdlk_engine_conf::get_template_path() -> std::filesystem::path
{
const auto home_path = std::filesystem::path(os::get_home_dir());
return get_config_path() / SDLK_TEMPLATE_DIRECTORY;
}

auto sdlk_engine_conf::is_valid(const std::filesystem::path& file_conf_path) -> bool
Expand Down
4 changes: 3 additions & 1 deletion sources/engine/conf/sdlk_engine_conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class sdlk_engine_conf
public:
static constexpr size_t MAX_RECENTS = 6;

[[nodiscard]] static auto get_template_path() -> std::filesystem::path;
[[nodiscard]] static auto get_config_path() -> std::filesystem::path;
[[nodiscard]] static auto get_file_path() -> std::filesystem::path;
[[nodiscard]] static auto load_or_init() -> sdlk_engine_conf*;

auto save() const -> void;
auto add_recent_project(const std::string& path) -> void;
auto get_last_project_paths() const -> std::vector<std::string>;

[[nodiscard]] auto get_last_project_paths() const -> std::vector<std::string>;
[[nodiscard]] static auto is_valid(const std::filesystem::path &file_conf_path) -> bool;

sdlk_engine_conf(std::string version, const std::vector<std::string> &last_projects);
Expand Down
Loading
Loading