如何使用GLFW在当前监视器上创建全屏窗口

时间:2014-01-29 02:45:40

标签: opengl glfw

使用glfwCreateWindow创建一个包含GLFW3的窗口:

GLFWwindow* glfwCreateWindow ( int width,
                               int height,
                               const char *title,
                               GLFWmonitor *monitor,
                               GLFWwindow *share 
                             ) 

如果monitor参数不是NULL,则在给定监视器上以全屏模式创建窗口。可以通过致电glfwGetPrimaryMonitor来接收主监视器,或者选择glfwGetMonitors的结果之一。但是如何在当前监视器上创建一个全屏窗口,即窗口当前以窗口模式运行的监视器?似乎无法接收当前使用的监视器。有glfwGetWindowMonitor,但它只在全屏模式下以窗口模式NULL返回显示器。

3 个答案:

答案 0 :(得分:8)

您可以使用glfwGetWindowPos / glfwGetWindowSize找到当前的监视器。 此函数返回包含更大窗口区域的监视器。

var audio1 = new Audio('audio/babai.wav');
var audio2 = new Audio('audio/lalaki.wav');
var audio3 = new Audio('audio/aso.wav');

答案 1 :(得分:0)

在讨论IRC之后,似乎无法使用GLFW检索当前活动的监视器(如在监视器中当前正在绘制窗口)。因此,无法在当前监视器上创建全屏窗口。

编辑尽管没有GLFW功能可以直接实现这一点,但Shmo的答案提供了一个优雅的解决方案。

答案 2 :(得分:0)

这里是Shmo's answer,已移植到LWJGL:

/** Determines the current monitor that the specified window is being displayed on.
 * If the monitor could not be determined, the primary monitor will be returned.
 * 
 * @param window The window to query
 * @return The current monitor on which the window is being displayed, or the primary monitor if one could not be determined
 * @author <a href="https://stackoverflow.com/a/31526753/2398263">Shmo</a><br>
 * Ported to LWJGL by Brian_Entei */
@NativeType("GLFWmonitor *")
public static final long glfwGetCurrentMonitor(long window) {
    int[] wx = {0}, wy = {0}, ww = {0}, wh = {0};
    int[] mx = {0}, my = {0}, mw = {0}, mh = {0};
    int overlap, bestoverlap;
    long bestmonitor;
    PointerBuffer monitors;
    GLFWVidMode mode;

    bestoverlap = 0;
    bestmonitor = glfwGetPrimaryMonitor();// (You could set this back to NULL, but I'd rather be guaranteed to get a valid monitor);

    glfwGetWindowPos(window, wx, wy);
    glfwGetWindowSize(window, ww, wh);
    monitors = glfwGetMonitors();

    while(monitors.hasRemaining()) {
        long monitor = monitors.get();
        mode = glfwGetVideoMode(monitor);
        glfwGetMonitorPos(monitor, mx, my);
        mw[0] = mode.width();
        mh[0] = mode.height();

        overlap =
                Math.max(0, Math.min(wx[0] + ww[0], mx[0] + mw[0]) - Math.max(wx[0], mx[0])) *
                Math.max(0, Math.min(wy[0] + wh[0], my[0] + mh[0]) - Math.max(wy[0], my[0]));

        if (bestoverlap < overlap) {
            bestoverlap = overlap;
            bestmonitor = monitor;
        }
    }

    return bestmonitor;
}