Skip to content
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: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
lfs: true
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Setup anew (or from cache) vcpkg (and does not build any package)
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: '88b81397bbf10f554d54246b50f188dac41470f1'
vcpkgGitCommitId: 'ce613c41372b23b1f51333815feb3edd87ef8a8b'

- name: Run CMake consuming CMakePreset.json and run vcpkg to build packages
uses: lukka/run-cmake@v10
Expand All @@ -27,7 +27,7 @@ jobs:
buildPreset: 'ninja-multi-vcpkg'
buildPresetAdditionalArgs: "['--config Release']"

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: windows
path: builds/ninja-multi-vcpkg/Release
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/non-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
lfs: true
Expand All @@ -17,7 +17,7 @@ jobs:
- name: Setup anew (or from cache) vcpkg (and does not build any package)
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: '88b81397bbf10f554d54246b50f188dac41470f1'
vcpkgGitCommitId: 'ce613c41372b23b1f51333815feb3edd87ef8a8b'

- name: Run CMake consuming CMakePreset.json and run vcpkg to build packages
uses: lukka/run-cmake@v10
Expand All @@ -26,7 +26,7 @@ jobs:
buildPreset: 'ninja-multi-vcpkg'
buildPresetAdditionalArgs: "['--config Release']"

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: windows
path: out/Release
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
[submodule "imgui-filebrowser"]
path = ext/imgui-filebrowser
url = https://github.com/AirGuanZ/imgui-filebrowser
[submodule "ext/IconFontCppHeaders"]
[submodule "IconFontCppHeaders"]
path = ext/IconFontCppHeaders
url = https://github.com/juliettef/IconFontCppHeaders
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ find_package(freetype CONFIG REQUIRED)
find_package(harfbuzz CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(magic_enum CONFIG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL3 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(utf8cpp CONFIG REQUIRED)

Expand All @@ -48,7 +48,7 @@ target_link_libraries(font-render-tester PRIVATE
harfbuzz::harfbuzz
imgui::imgui
magic_enum::magic_enum
SDL2::SDL2 SDL2::SDL2main
SDL3::SDL3
spdlog::spdlog spdlog::spdlog_header_only
utf8::cpp utf8cpp::utf8cpp
)
Expand Down
2 changes: 1 addition & 1 deletion src/colors.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COLORS_HPP
#define COLORS_HPP

#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
#include <array>
#include <imgui.h>

Expand Down
8 changes: 4 additions & 4 deletions src/draw_glyph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void DrawGlyph(SDL_Renderer *renderer, DebugSettings &debug, const Font &font,
};

SDL_Rect bound;
SDL_RenderGetViewport(renderer, &bound);
SDL_GetRenderViewport(renderer, &bound);

/*
* Adjust the coordinate, and recalculate the new y origin of the rectangle.
Expand All @@ -38,14 +38,14 @@ void DrawGlyph(SDL_Renderer *renderer, DebugSettings &debug, const Font &font,
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetTextureColorMod(g.texture, color.r, color.g, color.b);

SDL_RenderCopyF(renderer, g.texture, nullptr, &rect);
SDL_RenderTexture(renderer, g.texture, nullptr, &rect);

if (debug.enabled && debug.debugGlyphBound) {
SDL_SetRenderDrawColor(renderer, debugGlyphBoundColor.r,
debugGlyphBoundColor.g, debugGlyphBoundColor.b,
debugGlyphBoundColor.a);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderDrawRectF(renderer, &rect);
SDL_RenderRect(renderer, &rect);
}

if (debug.enabled && debug.debugCaret) {
Expand All @@ -62,7 +62,7 @@ void DrawGlyph(SDL_Renderer *renderer, DebugSettings &debug, const Font &font,
debugCaretColor.b, debugCaretColor.a);

SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderDrawRectF(renderer, &rect);
SDL_RenderRect(renderer, &rect);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/font.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "font.hpp"

#include <algorithm>
#include <harfbuzz/hb-ft.h>
#include <magic_enum_all.hpp>
#include <magic_enum/magic_enum_all.hpp>
#include <spdlog/spdlog.h>
#include <utf8cpp/utf8.h>

Expand Down Expand Up @@ -39,7 +40,7 @@ bool Font::Init() {

void Font::CleanUp() { FT_Done_FreeType(library); }

Font::Font(){};
Font::Font() {};

Font &Font::operator=(const Font &f) {
data = f.data;
Expand Down Expand Up @@ -73,7 +74,7 @@ static std::string ConvertFromFontString(const char *str, const int &length) {
const char16_t *c16str = reinterpret_cast<const char16_t *>(str);
std::vector<char16_t> buffer;
for (int i = 0; i < length / 2; i++) {
buffer.push_back(SDL_SwapBE16(c16str[i]));
buffer.push_back(SDL_Swap16BE(c16str[i]));
}

std::string output;
Expand Down
4 changes: 2 additions & 2 deletions src/font.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
#include <harfbuzz/hb.h>

#include <ft2build.h>
Expand All @@ -10,7 +10,7 @@
#include <functional>
#include <hb-ot.h>
#include <iterator>
#include <magic_enum_containers.hpp>
#include <magic_enum/magic_enum_containers.hpp>
#include <map>
#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion src/io_util.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <SDL3/SDL.h>
#include <filesystem>
#include <fstream>
#include <streambuf>
#include <SDL2/SDL.h>

template <class container_type>
container_type LoadFile(const std::filesystem::path &path,
Expand Down
102 changes: 55 additions & 47 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
#define SDL_MAIN_USE_CALLBACKS

#include "io_util.hpp"
#include "main_scene.hpp"
#include <IconsForkAwesome.h>
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <imgui.h>
#include <imgui_impl_sdl2.h>
#include <imgui_impl_sdlrenderer2.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_sdlrenderer3.h>
#include <memory>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/spdlog.h>

static constexpr char imguiIni[] = "imgui.ini";
static constexpr char logfile[] = "log.txt";
static constexpr char IMGUI_INI[] = "imgui.ini";
static constexpr char LOGFILE[] = "log.txt";

static constexpr int windowMinimumWidth = 1280;
static constexpr int windowMinimumHeight = 720;
static constexpr int WINDOW_MINIMUM_WIDTH = 1280;
static constexpr int WINDOW_MINIMUM_HEIGHT = 720;

int main(int argc, char **argv) {
const auto preferencePath = GetPreferencePath();
static constexpr size_t MAX_LOG_FILE_SIZE = 5 * 1024 * 1024;
static constexpr size_t MAX_LOG_FILE = 3;

constexpr auto maxLogFileSize = 5 * 1024 * 1024;
constexpr auto maxLogFile = 3;
namespace {
SDL_Renderer *renderer = nullptr;
SDL_Window *window = nullptr;
} // namespace

const auto logFilePath = preferencePath / logfile;
const auto logger = spdlog::rotating_logger_mt("logger", logFilePath.string(),
maxLogFileSize, maxLogFile);
SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
const auto logFilePath = GetPreferencePath() / LOGFILE;
const auto logger = spdlog::rotating_logger_mt(
"logger", logFilePath.string(), MAX_LOG_FILE_SIZE, MAX_LOG_FILE);
logger->flush_on(spdlog::level::info);
spdlog::set_default_logger(logger);

SDL_Init(SDL_INIT_VIDEO);

SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");

SDL_Window *window = SDL_CreateWindow(
"font-render-tester", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
windowMinimumWidth, windowMinimumHeight,
SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
// High DPI is currently not working properly on MacOS
window = SDL_CreateWindow(
"font-render-tester", WINDOW_MINIMUM_WIDTH, WINDOW_MINIMUM_HEIGHT,
SDL_WINDOW_RESIZABLE /* | SDL_WINDOW_HIGH_PIXEL_DENSITY*/);

SDL_SetWindowMinimumSize(window, windowMinimumWidth, windowMinimumHeight);
SDL_SetWindowMinimumSize(window, WINDOW_MINIMUM_WIDTH, WINDOW_MINIMUM_HEIGHT);

SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
renderer = SDL_CreateRenderer(window, nullptr);

const auto imguiIniPath = preferencePath / imguiIni;
const auto imguiIniPath = GetPreferencePath() / IMGUI_INI;
std::string imguiIniStr = imguiIniPath.string();

IMGUI_CHECKVERSION();
Expand Down Expand Up @@ -71,50 +75,54 @@ int main(int argc, char **argv) {

io.Fonts->Build();

ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
ImGui_ImplSDLRenderer2_Init(renderer);
ImGui_ImplSDL3_InitForSDLRenderer(window, renderer);
ImGui_ImplSDLRenderer3_Init(renderer);

if (!SceneInit()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"Unable to initialize the new scene", window);

return EXIT_FAILURE;
return SDL_APP_FAILURE;
};

while (true) {
SDL_Event event;
if (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
break;
}
return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppIterate(void *appstate) {
ImGui_ImplSDL3_NewFrame();
ImGui_ImplSDLRenderer3_NewFrame();

ImGui_ImplSDL2_NewFrame(window);
ImGui_ImplSDLRenderer2_NewFrame();
ImGui::NewFrame();

ImGui::NewFrame();
SceneDoUI();

SceneDoUI();
ImGui::EndFrame();
ImGui::Render();

ImGui::EndFrame();
ImGui::Render();
SceneTick(renderer);

SceneTick(renderer);
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), renderer);
SDL_RenderPresent(renderer);

ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer);
SDL_Delay(1);
return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
ImGui_ImplSDL3_ProcessEvent(event);
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
}
return SDL_APP_CONTINUE;
}

void SDL_AppQuit(void *appstate, SDL_AppResult result) {
SceneCleanUp();

ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui_ImplSDLRenderer3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();

SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();

return EXIT_SUCCESS;
}
Loading
Loading