Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/demo-app/demo_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ int main(int argc, char** argv) {
// polyscope::view::windowWidth = 600;
// polyscope::view::windowHeight = 800;
// polyscope::options::maxFPS = -1;
polyscope::options::verbosity = 100;
polyscope::options::verbosity = 101;
polyscope::options::enableRenderErrorChecks = true;
polyscope::options::allowHeadlessBackends = true;

Expand Down
34 changes: 25 additions & 9 deletions src/imgui_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ const unsigned int* getLatoRegularCompressedData();

void configureImGuiStyle() {

// Style
ImGuiStyle* style = &ImGui::GetStyle();
style->WindowRounding = 1 * options::uiScale;
style->FrameRounding = 1 * options::uiScale;
style->FramePadding.y = 4 * options::uiScale;
style->ScrollbarRounding = 1 * options::uiScale;
style->ScrollbarSize = 20 * options::uiScale;
*style = ImGuiStyle(); // apply the default style as a starting point

// Style
style->WindowRounding = 1;
style->FrameRounding = 1;
style->FramePadding.y = 4;
style->ScrollbarRounding = 1;
style->ScrollbarSize = 20;
style->ScaleAllSizes(options::uiScale);


// Colors
Expand Down Expand Up @@ -77,21 +80,34 @@ std::tuple<ImFontAtlas*, ImFont*, ImFont*> prepareImGuiFonts() {

ImGuiIO& io = ImGui::GetIO();

ImVec2 windowSize{static_cast<float>(view::windowWidth), static_cast<float>(view::windowHeight)};
ImVec2 bufferSize{static_cast<float>(view::bufferWidth), static_cast<float>(view::bufferHeight)};
ImVec2 imguiCoordScale = {bufferSize.x / windowSize.x, bufferSize.y / windowSize.y};

// outputs
ImFontAtlas* fontAtlas;
ImFontAtlas* fontAtlas = nullptr; // right now this is unused by the caller, but I don't want to change
// this callback signature until I'm more confident about how this
// should work. (And it might be changing in an upcoming imgui version)
ImFont* regularFont;
ImFont* monoFont;

float fontSize = 16.0 * options::uiScale;
fontSize = std::max(1.0f, std::roundf(fontSize));

{ // add regular font
ImFontConfig config;
config.RasterizerDensity = std::max(imguiCoordScale.x, imguiCoordScale.y);
regularFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(),
render::getLatoRegularCompressedSize(), options::uiScale*18.0f, &config);
render::getLatoRegularCompressedSize(),
options::uiScale * 18.0f, &config);
}

{ // add mono font
ImFontConfig config;
config.RasterizerDensity = std::max(imguiCoordScale.x, imguiCoordScale.y);
monoFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(),
render::getCousineRegularCompressedSize(), options::uiScale*16.0f, &config);
render::getCousineRegularCompressedSize(),
options::uiScale * 16.0f, &config);
}

// io.Fonts->AddFontFromFileTTF("test-font-name.ttf", 16);
Expand Down
2 changes: 1 addition & 1 deletion src/render/opengl/gl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ void GLCompiledProgram::compileGLProgram(const std::vector<ShaderStageSpecificat
if (options::verbosity > 2) {
printShaderInfoLog(h);
}
if (options::verbosity > 100) {
if (options::verbosity > 200) {
std::cout << "Program text:" << std::endl;
std::cout << s.src.c_str() << std::endl;
}
Expand Down
48 changes: 30 additions & 18 deletions src/render/opengl/gl_engine_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void GLEngineGLFW::initialize() {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// This tells GLFW to scale window size/positioning/content based on the system-reported DPI scaling factor
// However, it can lead to some confusing behaviors, for instance, on linux with scaling=200%, if the user
// However, it can lead to some confusing behaviors, for instance, on linux with scaling=200%, if the user
// sets view::windowWidth = 1280, they might get back a window with windowWidth == bufferWidth == 2560,
// which is quite confusing.
// For this reason we _do not_ set this hint. If desired, the user can specify a windowWidth = 1280*uiScale,
Expand Down Expand Up @@ -80,14 +80,6 @@ void GLEngineGLFW::initialize() {

setWindowResizable(view::windowResizable);

// Set the UI scale to account for system-requested DPI scaling
// Currently we do *not* watch for changes of this value e.g. if a window moves between
// monitors with different DPI behaviors. We could, but it would require some logic to
// avoid overwriting values that a user might have set.
if(options::uiScale < 0) { // only set from system if the value is -1, meaning not set yet
setUIScaleFromSystemDPI();
}

// === Initialize openGL
// Load openGL functions (using GLAD)
#ifndef __APPLE__
Expand Down Expand Up @@ -117,18 +109,39 @@ void GLEngineGLFW::initialize() {
// glClearDepth(1.);
}

// Set the UI scale to account for system-requested DPI scaling
// Currently we do *not* watch for changes of this value e.g. if a window moves between
// monitors with different DPI behaviors. We could, but it would require some logic to
// avoid overwriting values that a user might have set.
if (options::uiScale < 0) { // only set from system if the value is -1, meaning not set yet
setUIScaleFromSystemDPI();
}

populateDefaultShadersAndRules();
}

void GLEngineGLFW::setUIScaleFromSystemDPI() {

float xScale, dont_use_yScale;
glfwGetWindowContentScale(mainWindow, &xScale, &dont_use_yScale);

// clamp to values within [1x,4x] scaling
xScale = std::fmin(std::fmax(xScale, 1.0f), 4.0f);
// logic adapted from a helpful imgui issue here: https://github.com/ocornut/imgui/issues/6967#issuecomment-2833882081

ImVec2 windowSize{static_cast<float>(view::windowWidth), static_cast<float>(view::windowHeight)};
ImVec2 bufferSize{static_cast<float>(view::bufferWidth), static_cast<float>(view::bufferHeight)};
ImVec2 imguiCoordScale = {bufferSize.x / windowSize.x, bufferSize.y / windowSize.y};

options::uiScale = xScale;
ImVec2 contentScale;
glfwGetWindowContentScale(mainWindow, &contentScale.x, &contentScale.y);

float sx = contentScale.x / imguiCoordScale.x;
float sy = contentScale.y / imguiCoordScale.y;
options::uiScale = std::max(sx, sy);
// clamp to values within [0.5x,4x] scaling
options::uiScale = std::fmin(std::fmax(options::uiScale, 0.5f), 4.0f);

info(100, "window size: " + std::to_string(view::windowWidth) + "," + std::to_string(view::windowHeight));
info(100, "buffer size: " + std::to_string(view::bufferWidth) + "," + std::to_string(view::bufferHeight));
info(100, "imguiCoordScale: " + std::to_string(imguiCoordScale.x) + "," + std::to_string(imguiCoordScale.y));
info(100, "contentScale: " + std::to_string(contentScale.x) + "," + std::to_string(contentScale.y));
info(100, "computed uiScale: " + std::to_string(options::uiScale));
}

void GLEngineGLFW::initializeImGui() {
Expand All @@ -146,7 +159,7 @@ void GLEngineGLFW::initializeImGui() {

void GLEngineGLFW::configureImGui() {

if(options::uiScale < 0){
if (options::uiScale < 0) {
exception("uiScale is < 0. Perhaps it wasn't initialized?");
}

Expand All @@ -161,7 +174,7 @@ void GLEngineGLFW::configureImGui() {

ImFontAtlas* _unused;
std::tie(_unused, regularFont, monoFont) = options::prepareImGuiFontsCallback();

ImGui_ImplOpenGL3_CreateFontsTexture();
}

Expand All @@ -172,7 +185,6 @@ void GLEngineGLFW::configureImGui() {
}



void GLEngineGLFW::shutdown() {
checkError();
shutdownImGui();
Expand Down
Loading