1
votes

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.

1
Are you running this through a remote connection by any chance? If you're not I would suggest turning down your compiler version for vs2015 to use 2013. This way you can still use vs2015, but your 2013 libraries will work. 2015 is new and their may be a reason glfw has not released an update to support it yet. Last I checked their next release was supposed to have it.Freddy
Try using glfwSetErrorCallback to install an error callback and see if that gives any useful information.Ross Ridge
@Freddy I'm not running through a remote connection, but I did consider that perhaps VS 2015 was the source of the problem. I tried using VS 2013 a while ago and it didn't work, but I will try again.dioxbow
@RossRidge Thanks for the tip. The error callback returns "No monitors found." I found a couple of reports of this on the GLFW github but no solution yet.dioxbow

1 Answers

1
votes

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.