glbinding
是如何工作的,但我无法编译我的非常基本的示例,这是他们的 cubescape
示例的简化版本:
#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;
}
}
罪魁祸首是这行:
cout << "OpenGL Version: " << glbinding::aux::ContextInfo::version() << endl;
编译器抱怨这一行,之后,像往常一样,输出大量有关尝试找到“操作符”的正确实现失败的信息。 <<’:
error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘glbinding::Version’)
我做错了什么?
cout<<glbinding::aux::ContextInfo::version()
,类
glbinding::Version
的情况下.如果你知道类
glbinding::Version
的定义,你只需要定义一个
operator <<
的重载即可。