【问题标题】:SFML window rendered in wrong sizeSFML 窗口以错误的大小呈现
【发布时间】:2020-01-08 03:15:18
【问题描述】:

有没有人遇到过这样的问题:在 SFML 中运行基本窗口设置会呈现一个比实际作为参数传递的窗口尺寸更小的窗口。我不确定问题是什么:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!");
    sf::Event event;
    while(window.isOpen()) {
        while(window.pollEvent(event)) {
            if(event.type == sf::Event::Closed)
                window.close();
        }
    }
    return 0;
}

我在 mac os 上运行我的代码。这是我得到的结果 - 看起来比 500 x 500 小很多。

【问题讨论】:

  • 在“关于本机”中检查显示器的分辨率。 500x500 在视网膜显示器上非常小。
  • 是的,我有一个 2880 x 1800 的 Retina 显示屏。是否有解决此问题的标准方法?

标签: c++ macos graphics sfml


【解决方案1】:

如果您的 Mac 是高分辨率 Retina 显示器,您必须找到一种方法来缩放窗口以匹配它。例如,与 3840 x 2160 显示器上的窗口相比,1280 x 720 显示器中的 500x500 窗口将非常大。你可能会用这样的东西来做到这一点:

void scaleWindow(int& screenWidth, int& screenHeight, float portion){
    screenWidth *portion;
    screenHeight *portion;
}

main(){
    int windowWidth     = 1920;
    int windowHeight    = 1080;
    float scale         = 0.5
    scaleWindow(windowWidth, windowHeight, scale) // Half your current screen size

    //make window here
}


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    相关资源
    最近更新 更多