Skip to content

Commit

Permalink
feat(sdl): scaling work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Oct 30, 2019
1 parent 10a8cc0 commit 51fbfa9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ if (USE_SDL_ANTARA_WRAPPER)
add_library(antara::sdl_import ALIAS antara_sdl_import)
#add_dependencies(antara_sdl_import external_sdl)
#include(GNUInstallDirs)
set(SDL2_DIR ${CMAKE_BINARY_DIR}/sdl/external/installed/lib/cmake/SDL2)
if (WIN32)
set(SDL2_DIR ${CMAKE_BINARY_DIR}/sdl/external/installed/cmake/)
else ()
set(SDL2_DIR ${CMAKE_BINARY_DIR}/sdl/external/installed/lib/cmake/SDL2)
endif ()
find_package(SDL2 REQUIRED)
target_link_libraries(antara_sdl_import INTERFACE SDL2::SDL2-static)
target_include_directories(antara_sdl_import
Expand Down
13 changes: 11 additions & 2 deletions modules/sdl/antara/gaming/sdl/graphic.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#ifdef _WIN32
#pragma comment(lib, "Shcore.lib")
#define NOMINMAX
#include <windows.h>
#include <ShellScalingApi.h>
#endif

#include <iostream>
#include <SDL2/SDL.h>
#include <antara/gaming/event/quit.game.hpp>

#include "antara/gaming/graphics/component.canvas.hpp"
#include "antara/gaming/event/fatal.error.hpp"
#include "antara/gaming/sdl/graphic.system.hpp"
Expand All @@ -32,7 +38,7 @@ namespace
SDL_Window *window = nullptr;
auto[screen_width, screen_height] = canvas_2d.window.size.to<math::vec2i>();
auto[screen_pos_x, screen_pos_y] = canvas_2d.window.position.to<math::vec2i>();
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");

Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
if (canvas_2d.is_fullscreen) {
flags |= SDL_WINDOW_FULLSCREEN;
Expand All @@ -57,6 +63,9 @@ namespace antara::gaming::sdl

graphic_system::graphic_system(entt::registry &registry) noexcept : system(registry)
{
#ifdef _WIN32
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
#endif
if (auto res = SDL_Init(SDL_INIT_EVERYTHING); res < 0) {
this->dispatcher_.trigger<event::fatal_error>(std::error_code(res, sdl::sdl_error_category()));
}
Expand Down

0 comments on commit 51fbfa9

Please sign in to comment.