glfw window 没有标题栏

glfw window with no title bar

我正在尝试找到一种在 windowed 模式和全屏模式之间切换我的 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);
    }
}

代码结果:

@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);
}

新结果:

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

在更改为full-screen模式之前,保存window位置和大小。

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

然后当从 full-screen 变回 windowed 模式时,应用保存的位置和大小属性。

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