diff --git a/base/VulkanTextOverlay.hpp b/base/VulkanTextOverlay.hpp index 2325c4b4..5f74598f 100644 --- a/base/VulkanTextOverlay.hpp +++ b/base/VulkanTextOverlay.hpp @@ -22,6 +22,10 @@ #include "VulkanBuffer.hpp" #include "VulkanDevice.hpp" +#if defined(__ANDROID__) +#include "vulkanandroid.h" +#endif + #include "../external/stb/stb_font_consolas_24_latin1.inl" // Defines for the STB font used @@ -116,6 +120,23 @@ public: this->frameBufferWidth = framebufferwidth; this->frameBufferHeight = framebufferheight; +#if defined(__ANDROID__) + // Scale text on Android devices with high DPI + int32_t screenDensity = vks::android::getScreenDensity(); + if (screenDensity >= ACONFIGURATION_DENSITY_XXHIGH) { + LOGD("XXHIGH"); + scale = 2.0f; + } + else if (screenDensity >= ACONFIGURATION_DENSITY_XHIGH) { + LOGD("XHIGH"); + scale = 1.5f; + } + else if (screenDensity >= ACONFIGURATION_DENSITY_HIGH) { + LOGD("HIGH"); + scale = 1.25f; + }; +#endif + cmdBuffers.resize(framebuffers.size()); prepareResources(); prepareRenderPass(); diff --git a/base/vulkanandroid.cpp b/base/vulkanandroid.cpp index 7c0ce23c..ff599691 100644 --- a/base/vulkanandroid.cpp +++ b/base/vulkanandroid.cpp @@ -281,6 +281,15 @@ namespace vks { dlclose(libVulkan); } + + int32_t getScreenDensity() + { + AConfiguration* config = AConfiguration_new(); + AConfiguration_fromAssetManager(config, androidApp->activity->assetManager); + int32_t density = AConfiguration_getDensity(config); + AConfiguration_delete(config); + return density; + } } } diff --git a/base/vulkanandroid.h b/base/vulkanandroid.h index afde52c5..63748c20 100644 --- a/base/vulkanandroid.h +++ b/base/vulkanandroid.h @@ -24,6 +24,7 @@ #include #include +#include #include // Missing from the NDK @@ -158,6 +159,8 @@ namespace vks bool loadVulkanLibrary(); void loadVulkanFunctions(VkInstance instance); void freeVulkanLibrary(); + /** @brief Returns the density of the device screen (in DPI) */ + int32_t getScreenDensity(); } }