Mag*_*ick 3 c++ opengl multiple-monitors glfw
这是我的简单代码.
#include <iostream>
#include <GLFW/glfw3.h>
int main() {
    int count;
    GLFWmonitor** monitors = glfwGetMonitors(&count); 
    std::cout << count << std::endl;
    return 0;
}
由于某种原因,它一直告诉我有零监视器.我假设0意味着确实存在1.但我有两台其他显示器连接到我的电脑.当我进入系统偏好时,我可以清楚地看到其他两个显示器.但我不知道为什么它一直告诉我零.我不知道问题是什么.
我猜你glfwInit()在做其他事之前需要打电话.
从glfw文档:
int glfwInit(void)
此函数初始化GLFW库.在可以使用大多数GLFW功能之前,必须初始化GLFW,并且在程序终止之前,应终止GLFW以释放在初始化期间或之后分配的任何资源.
如果此函数失败,则在返回之前调用glfwTerminate.如果成功,则应在程序退出之前调用glfwTerminate.
成功初始化后但在终止之前对此函数的其他调用将成功,但不会执行任何操作.
如果成功则返回GL_TRUE,如果发生错误则返回GL_FALSE.