繁体   English   中英

glfw window 没有标题栏

[英]glfw window with no title bar

我正在尝试找到一种在窗口模式和全屏模式之间切换我的 window 的方法。 除了一个问题,我已经成功完成了。 标题栏不工作。 您也不能移动 window。 没有这段代码,一切正常。

设置全屏方法:

void Window::setFullscreen(bool fullscreen)
{
    GLFWmonitor* monitor = glfwGetPrimaryMonitor();
    const GLFWvidmode* mode = glfwGetVideoMode(monitor);

    if (fullscreen) {
        glfwSetWindowMonitor(m_window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
        glViewport(0, 0, mode->width, mode->height);
    }

    if (!fullscreen) {
        glfwSetWindowMonitor(m_window, nullptr, 0, 0, m_width, m_height, GLFW_DONT_CARE);
        glViewport(0, 0, m_width, m_height);
    }
}

代码的结果:

代码的结果

不确定您是否仍在寻找答案,但是,我这里的代码解决了您最初遇到的相同问题。

在更改为全屏模式之前,保存 window position 和大小。

    int xPos, yPos, width, height; //have somewhere stored out of function scope.
    glfwGetWindowPos(windowPtr, &xPos, &yPos);
    glfwGetWindowSize(windowPtr, &width, &height);

然后当从全屏切换回窗口模式时,应用保存的位置和大小属性。

    glfwSetWindowMonitor(windowPtr, nullptr, xPos, yPos, width, height, 0); //Refresh rate is ignored without an active monitor.

@tomasantunes 帮我解决这个问题。

在 setFullscreen 中,我将 window 设置为 0、0 或屏幕左上角。 标题栏实际上并没有消失,只是在屏幕外。 因此,如果我将 window 设置为 100, 100,我会返回标题栏。 犯这种愚蠢的错误真是太愚蠢了。

if (!fullscreen) {
    glfwSetWindowMonitor(m_window, nullptr, 0, 0, m_width, m_height, GLFW_DONT_CARE); // I set the position to 0,0 in the 3rd and 4th parameter
    glViewport(0, 0, m_width, m_height);
}

固定代码:

if (!fullscreen) {
    glfwSetWindowMonitor(m_window, nullptr, 100, 100, m_width, m_height, GLFW_DONT_CARE); // I set the position to 100, 100 
    glViewport(0, 0, m_width, m_height);
}

新结果:

修复的结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM