#include "Entrypoint/Common.hpp" #include "Entrypoint/DirectX11.hpp" #include "Entrypoint/DirectX12.hpp" #include "Entrypoint/Metal.hpp" #include "Entrypoint/OpenGL2.hpp" #include "Entrypoint/OpenGL3.hpp" #include "Entrypoint/Vulkan.hpp" #include "Model/GlobalStates.hpp" #include "UI/Localization.hpp" #include "UI/States.hpp" #include "UI/UI.hpp" #include "Utils/I18n.hpp" #include "Utils/Sigslot.hpp" #include #include #include #include #include #include #include #include #include #include using namespace std::literals::string_literals; using namespace std::literals::string_view_literals; static std::unique_ptr CreateDefaultBackend() { #if PLATFORM_WIN32 # if BUILD_CORE_WITH_DX12_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # elif BUILD_CORE_WITH_DX11_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # elif BUILD_CORE_WITH_VULKAN_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # elif BUILD_CORE_WITH_OPENGL3_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # elif BUILD_CORE_WITH_OPENGL2_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # endif #elif PLATFORM_MACOS // We currently only support using metal on macos backend = std::make_unique(); #elif PLATFORM_LINUX # if BUILD_CORE_WITH_VULKAN_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # elif BUILD_CORE_WITH_OPENGL3_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # elif BUILD_CORE_WITH_OPENGL2_BACKEND try { auto backend = std::make_unique(); return backend; } catch (const std::exception&) { } # endif #endif return nullptr; } static std::unique_ptr CreateBackend(std::string_view option) { if (option == "default") { return CreateDefaultBackend(); } else if (option == "opengl2") { return std::make_unique(); } else if (option == "opengl3") { return std::make_unique(); } else if (option == "vulkan") { return std::make_unique(); } else if (option == "dx11") { return std::make_unique(); } else if (option == "dx12") { return std::make_unique(); } else if (option == "metal") { return std::make_unique(); } else { std::string message; message += "Unknown backend '"; message += option; message += "'.\n"; throw std::runtime_error(message); return nullptr; } } int main(int argc, char* argv[]) { argparse::ArgumentParser parser; parser.add_argument("--rendering-backend") .help("Which rendering backend to use. If equals 'default', the preferred API for each platform will be used") .default_value("default"s); try { parser.parse_args(argc, argv); } catch (const std::runtime_error& error) { std::cout << error.what() << '\n'; std::cout << parser; return -1; } auto backendOption = parser.get("--rendering-backend"); auto backend = CreateBackend(backendOption); ImGui::GetIO().IniFilename = nullptr; ImGui::GetIO().LogFilename = nullptr; ImGui::StyleColorsLight(); // Includes latin alphabet, although for some reason smaller than if rendered using 18 point NotoSans regular ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/NotoSansSC-Regular.otf", 18, nullptr, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); ImWchar iconRanges[] = { ICON_MIN_FA, ICON_MAX_FA }; ImFontConfig config; config.MergeMode = true; ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/FontAwesome5-Solid.otf", 14, &config, iconRanges); I18n::OnReload.Connect([]() { LocaleStrings::Instance = std::make_unique(); }); // Do i18n initialization after linking reload signals, so that when SetLanguage() is called, the locale strings will be initialized (without us writing the code another time outside the slot) I18n::Init(); I18n::SetLanguage("zh_CN"); GlobalStates::Init(); UIState::Init(); auto window = backend->GetWindow(); while (!glfwWindowShouldClose(window)) { backend->BeginFrame(); UI::MainWindow(); ImGui::ShowDemoWindow(); backend->EndFrame(); } UIState::Shutdown(); GlobalStates::Shutdown(); return 0; }