Set dpi scaling to solve display errot when using high dpi displayer

This commit is contained in:
dijunkun
2024-07-01 16:31:39 +08:00
parent 7f25f7426c
commit e63b384d1e
3 changed files with 14 additions and 5 deletions

View File

@@ -4,15 +4,10 @@ int Render::MainWindow() {
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(main_window_width_, main_window_height_), ImGui::SetNextWindowSize(ImVec2(main_window_width_, main_window_height_),
ImGuiCond_Always); ImGuiCond_Always);
ImGui::Begin("Render", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
MenuWindow(); MenuWindow();
LocalWindow(); LocalWindow();
RemoteWindow(); RemoteWindow();
ImGui::End();
return 0; return 0;
} }

View File

@@ -241,6 +241,15 @@ int Render::Run() {
io.Fonts->Build(); io.Fonts->Build();
SDL_GL_GetDrawableSize(main_window_, &main_window_width_real_,
&main_window_height_real_);
dpi_scaling_w_ = (float)main_window_width_real_ / (float)main_window_width_;
dpi_scaling_h_ = (float)main_window_width_real_ / (float)main_window_width_;
LOG_INFO("Use dpi scaling [{}x{}]", dpi_scaling_w_, dpi_scaling_h_);
SDL_RenderSetScale(main_renderer_, dpi_scaling_w_, dpi_scaling_h_);
// Setup Dear ImGui style // Setup Dear ImGui style
// ImGui::StyleColorsDark(); // ImGui::StyleColorsDark();
ImGui::StyleColorsLight(); ImGui::StyleColorsLight();

View File

@@ -124,6 +124,11 @@ class Render {
int menu_window_height_ = 30; int menu_window_height_ = 30;
int local_window_width_ = 350; int local_window_width_ = 350;
int main_window_width_real_ = 960;
int main_window_height_real_ = 540;
float dpi_scaling_w_ = 1.0f;
float dpi_scaling_h_ = 1.0f;
int texture_width_ = 1280; int texture_width_ = 1280;
int texture_height_ = 720; int texture_height_ = 720;