“glbinding”示例中的编译错误,该示例应该输出 OpenGL 版本

问题描述 投票:0回答:1

我想了解 OpenGL 加载器库

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’)
我做错了什么?

    操作系统:Ubuntu 22.04.3 LTS
  • 编译器:g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  • gl绑定:3.3.0
c++ opengl glfw glbinding
1个回答
0
投票
我不太熟悉 OpenGL 库,但从 C++ 编程的角度来看,问题是由于您尝试使用 cout 来打印不平凡的类型而引起的 - 在

cout<<glbinding::aux::ContextInfo::version()

,类 
glbinding::Version 的情况下
.

如果你知道类

glbinding::Version

的定义,你只需要定义一个
operator <<
的重载即可。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.