c++ - 以错误大小呈现的 SFML 窗口

标签 c++ macos graphics sfml

有没有人遇到这样的问题:在 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 操作系统上运行我的代码。这是我得到的结果 - 看起来比 500 x 500 小很多。

enter image description here

最佳答案

如果您的 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
}


关于c++ - 以错误大小呈现的 SFML 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57801747/

相关文章:

math - 将点积夹在四元数的 Slerp 中

c++ - 在 Visual C++ 的命令行上编译

c++ - 从函数返回堆分配的指针是不礼貌的吗?

swift - 在 Swift 4 中设置 NSMenuItem 修饰符导致 "Type of expression is ambiguous"

xcode - 在 Cocoa (Mac OS X) 中列出所有驱动器及其大小

c# - 在 MonoGame 中绘制绘图的子图像

c++ - 我如何从文件 C++ 中读取并输出它

c++ - 在 C++ main 中将浮点表作为参数传递

python - 无法安装pymssql

math - 矩阵函数——如何添加 "up"向量?