I wanted to understand how the OpenGL loader library glbinding
works, but I couldn't compile my very basic example, which is a reduced version of their cubescape
example:
#include <iostream>
#include <GLFW/glfw3.h>
#include <glbinding/glbinding.h>
#include <glbinding-aux/ContextInfo.h>
using std::cout;
using std::endl;
int main()
{
if (glfwInit())
{
// ------ create window
auto const windowPtr = glfwCreateWindow(640, 480, "tc0001", nullptr, nullptr);
if (windowPtr)
{
glfwHideWindow(windowPtr);
glfwMakeContextCurrent(windowPtr);
glbinding::initialize(glfwGetProcAddress, false);
cout << "OpenGL Version: " << glbinding::aux::ContextInfo::version() << endl;
cout << "OpenGL Vendor: " << glbinding::aux::ContextInfo::vendor() << endl;
cout << "OpenGL Renderer: " << glbinding::aux::ContextInfo::renderer() << endl;
// ------ destroy window
glfwDestroyWindow(windowPtr);
}
else
{
cout << "glfwCreateWindow error" << endl;
}
glfwTerminate();
}
else
{
cout << "glfwInit error" << endl;
}
}
The culprit is the line:
cout << "OpenGL Version: " << glbinding::aux::ContextInfo::version() << endl;
The compiler complains about this line, and after that, as usual, outputs a lot of information about failed attempts to find a right implementation of the ‘operator<<’:
error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘glbinding::Version’)
What am I doing wrong?
I'm answering my own question... A simple fix has helped me to overcome this problem. It was enough to place the GLFW
include after all the glbinding
includes:
#include <glbinding/glbinding.h>
#include <glbinding-aux/ContextInfo.h>
#include <glbinding-aux/types_to_string.h>
#include <GLFW/glfw3.h> // <=== must be after 'glbinding' includes
That's strange, but nevertheless it worked.