dioxbow
dioxbow

Reputation: 81

GLFW initialization fails even after successful linking

I recently started learning C++, coming primarily from Java. I know the basics now, and I want to test out some graphics. Obviously, C++ doesn't have the built in graphics API that Java does, so I'm trying my hand at using GLFW. Unfortunately, I can't even get it to initialize with glfwInit(). Here's my code (it logs "Could not initialize GLFW" to the console):

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

int main() {
    if (!glfwInit()) {
        std::cout << "Could not initialize GLFW" << std::endl;
    }
    else {
        std::cout << "GLFW initialized!" << std::endl;
        glfwTerminate();
    }

    std::cin.get();
    return 0;
}

I've seen lots of similar test code before, so I'm assuming that the code is the issue. I'm also not getting any linking errors, so I think I did that properly. However, this is essentially the first time I've used a third party library with C++, so I could be making a simple mistake.

I'm using Visual Studio Community 2015, but since GLFW doesn't have any pre-built binaries for that yet, I had to build them myself with CMake. (Since I've never done that before, I repeated this whole process in Visual Studio Community 2013 with the pre-built binaries, and I got the same result.) I added my 'lib' and 'include' folders in the appropriate places in Configuration Properties -> VC++ Directories, and I added the 'glfw3.lib' and 'opengl32.lib' files in Linker -> Input -> Additional Dependencies.

I've found an abundance of posts where people have linking errors (which I don't have anymore) or can't get GLFW working even when initialization succeeds. However, I haven't been able to find anyone else with a problem quite like mine, nor do I know where to start in terms of debugging. Any help is greatly appreciated.

Upvotes: 1

Views: 5542

Answers (1)

dioxbow
dioxbow

Reputation: 81

Okay, so apparently this was a bug in GLFW. I added an error callback and it returned "No monitors found." I found this discussion of a similar issue on the GLFW github page, and the owner added a fix recently that hasn't made its way into any official release. I downloaded the master branch, built it as I had before, replaced the libs and header files, and now everything works properly.

Upvotes: 1

Related Questions