diff --git a/CMakeLists.txt b/CMakeLists.txt index 40a9ce15f..fc0af96e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,62 +63,8 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.") -if(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "") - find_package(IrrlichtMt QUIET - PATHS "${IRRLICHTMT_BUILD_DIR}" - NO_DEFAULT_PATH -) - - if(NOT TARGET IrrlichtMt::IrrlichtMt) - # find_package() searches certain subdirectories. ${PATH}/cmake is not - # the only one, but it is the one where IrrlichtMt is supposed to export - # IrrlichtMtConfig.cmake - message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.") - endif() # This is done here so that relative search paths are more reasonable -elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt") - message(STATUS "Using user-provided IrrlichtMt at subdirectory 'lib/irrlichtmt'") - if(BUILD_CLIENT) - # tell IrrlichtMt to create a static library - set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library" FORCE) - add_subdirectory(lib/irrlichtmt EXCLUDE_FROM_ALL) - unset(BUILD_SHARED_LIBS CACHE) - - if(NOT TARGET IrrlichtMt) - message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!") - endif() - else() - add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED) - set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt/include") - endif() -else() - find_package(IrrlichtMt QUIET) - if(NOT TARGET IrrlichtMt::IrrlichtMt) - string(CONCAT explanation_msg - "The Minetest team has forked Irrlicht to make their own customizations. " - "It can be found here: https://github.com/minetest/irrlicht\n" - "For example use: git clone --depth=1 https://github.com/minetest/irrlicht lib/irrlichtmt\n") - if(BUILD_CLIENT) - message(FATAL_ERROR "IrrlichtMt is required to build the client, but it was not found.\n${explanation_msg}") - endif() - - include(MinetestFindIrrlichtHeaders) - if(NOT IRRLICHT_INCLUDE_DIR) - message(FATAL_ERROR "Irrlicht or IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}") - endif() - message(STATUS "Found Irrlicht headers: ${IRRLICHT_INCLUDE_DIR}") - add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED) - # Note that we can't use target_include_directories() since that doesn't work for IMPORTED targets before CMake 3.11 - set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}") - endif() -endif() - -if(TARGET IrrlichtMt::IrrlichtMt) - message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}") -endif() +find_package(Irrlicht) # Installation diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f207244c..dcf9d170f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,17 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER)) set(BUILD_SERVER TRUE) endif() +option(USE_SDL "Use SDL2 for window management" FALSE) + +if(USE_SDL) + find_package(SDL2) + if (SDL2_FOUND) + message(STATUS "SDL2 found.") + include_directories(${SDL2_INCLUDEDIR}) + else() + message(FATAL_ERROR "SDL2 not found.") + endif() +endif() option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) set(USE_CURL FALSE) @@ -294,6 +305,10 @@ else() if(NOT HAIKU AND NOT APPLE) find_package(X11 REQUIRED) endif(NOT HAIKU AND NOT APPLE) + + find_package(JPEG REQUIRED) + find_package(BZip2 REQUIRED) + find_package(PNG REQUIRED) endif() set(PLATFORM_LIBS -lpthread ${CMAKE_DL_LIBS}) @@ -485,7 +500,9 @@ endif() include_directories( ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} + ${IRRLICHT_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} + ${PNG_INCLUDE_DIR} ${ZSTD_INCLUDE_DIR} ${SQLITE3_INCLUDE_DIR} ${LUA_INCLUDE_DIR} @@ -524,7 +541,10 @@ if(BUILD_CLIENT) target_link_libraries( ${PROJECT_NAME} ${ZLIB_LIBRARIES} - IrrlichtMt::IrrlichtMt + ${IRRLICHT_LIBRARY} + ${JPEG_LIBRARIES} + ${BZIP2_LIBRARIES} + ${PNG_LIBRARIES} ${ZSTD_LIBRARY} ${X11_LIBRARIES} ${SOUND_LIBRARIES} @@ -535,6 +555,7 @@ if(BUILD_CLIENT) ${LUA_BIT_LIBRARY} ${FREETYPE_LIBRARY} ${PLATFORM_LIBS} + ${SDL2_LIBRARIES} ) if(NOT USE_LUAJIT) set_target_properties(${PROJECT_NAME} PROPERTIES diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 723865db4..1859aca8f 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -46,6 +46,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #endif +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ +#include +#include +#endif + #ifdef _WIN32 #include #include @@ -204,7 +209,23 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) #ifdef XORG_USED const video::SExposedVideoData exposedData = driver->getExposedVideoData(); +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + SDL_Window *window = reinterpret_cast(exposedData.OpenGLSDL.Window); + + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(window, &info); + + if (info.subsystem != SDL_SYSWM_X11) + return; + + Display *x11_dpl = info.info.x11.display; + Window x11_win = info.info.x11.window; +#else Display *x11_dpl = reinterpret_cast(exposedData.OpenGLLinux.X11Display); + Window x11_win = reinterpret_cast(exposedData.OpenGLLinux.X11Window); +#endif + if (x11_dpl == NULL) { warningstream << "Client: Could not find X11 Display in ExposedVideoData" << std::endl; @@ -215,9 +236,6 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) << " window properties" << std::endl; - - Window x11_win = reinterpret_cast(exposedData.OpenGLLinux.X11Window); - // Set application name and class hints. For now name and class are the same. XClassHint *classhint = XAllocClassHint(); classhint->res_name = const_cast(name.c_str()); @@ -398,9 +416,26 @@ bool RenderingEngine::setXorgWindowIconFromPath(const std::string &icon_file) img->drop(); icon_f->drop(); - const video::SExposedVideoData &video_data = driver->getExposedVideoData(); + const video::SExposedVideoData exposedData = driver->getExposedVideoData(); +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + SDL_Window *window = reinterpret_cast(exposedData.OpenGLSDL.Window); + + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(window, &info); + + if (info.subsystem != SDL_SYSWM_X11) { + delete[] icon_buffer; + return false; + } + + Display *x11_dpl = info.info.x11.display; + Window x11_win = info.info.x11.window; +#else Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display; + Window x11_win = (Window)video_data.OpenGLLinux.X11Window; +#endif if (x11_dpl == NULL) { warningstream << "Could not find x11 display for setting its icon." @@ -409,8 +444,6 @@ bool RenderingEngine::setXorgWindowIconFromPath(const std::string &icon_file) return false; } - Window x11_win = (Window)video_data.OpenGLLinux.X11Window; - Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False); Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False); XChangeProperty(x11_dpl, x11_win, net_wm_icon, cardinal, 32, PropModeReplace, @@ -568,8 +601,21 @@ const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_ #ifndef __ANDROID__ #if defined(XORG_USED) -static float calcDisplayDensity() +static float calcDisplayDensity(irr::video::IVideoDriver *driver) { +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + const video::SExposedVideoData exposedData = driver->getExposedVideoData(); + + SDL_Window *window = reinterpret_cast(exposedData.OpenGLSDL.Window); + + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(window, &info); + + if (info.subsystem != SDL_SYSWM_X11) + return g_settings->getFloat("screen_dpi") / 96.0; +#endif + const char *current_display = getenv("DISPLAY"); if (current_display != NULL) { @@ -597,7 +643,7 @@ static float calcDisplayDensity() float RenderingEngine::getDisplayDensity() { - static float cached_display_density = calcDisplayDensity(); + static float cached_display_density = calcDisplayDensity(get_video_driver()); return cached_display_density * g_settings->getFloat("display_density_factor"); }