Question

Here is my simple code.

#include <iostream>
#include <GLFW/glfw3.h>

int main() {

    int count;
    GLFWmonitor** monitors = glfwGetMonitors(&count); 
    std::cout << count << std::endl;
    return 0;
}

For some reason it keeps telling me that there is zeros monitors. I assume 0 means that there really is 1. But I have two other monitors attached to my computer. When I go into system preferences I can clearly see the other two monitors. But i don't know why it keeps telling me zero. I have no clue what the issue would be.

Was it helpful?

Solution

I'm guessing you need to call glfwInit() before you do anything else.

From the glfw documentation:

int glfwInit (void)

This function initializes the GLFW library. Before most GLFW functions can be used, GLFW must be initialized, and before a program terminates GLFW should be terminated in order to free any resources allocated during or after initialization.

If this function fails, it calls glfwTerminate before returning. If it succeeds, you should call glfwTerminate before the program exits.

Additional calls to this function after successful initialization but before termination will succeed but will do nothing.

Returns GL_TRUE if successful, or GL_FALSE if an error occurred.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top