声明重要的 oglplus 对象会抛出异常 oglplus::MissingFunction

Declaring important oglplus objects throws the exception oglplus::MissingFunction

我想使用带有 C++ OpenGL 包装器库 oglplus 的 OpenGL 创建 C++ 程序,但是我无法将使用 oglplus 的程序用于 运行,因为当我声明某些 oglplus 对象时 oglplus::MissingFunction 异常总是抛出。

我的 OS 是 archlinux。

我的程序可以编译但不能运行。例如:

#include <cassert>
#include <iostream>

#include <GL/glew.h>
#include <GL/glut.h>

#include <oglplus/all.hpp>

int main()
{
    oglplus::VertexShader vs;   
    return 0;
}

这个程序可以编译,但是当我运行它时,抛出异常oglplus::MissingFunction。

自从我的程序编译后,我相信这意味着我已经安装了必要的包并链接了正确的库。我只是不明白为什么会抛出异常。异常的描述说,它被抛出意味着一些用于调用OpenGL函数的指针未初始化。

到目前为止,我观察到 oglplus::MissingFunction 在声明类型对象时被抛出:

关于如何解决这个问题有什么建议吗?

在您可以使用任何 OpenGL 资源之前,您需要创建一个 OpenGL 上下文。此示例显示如何使用 GLUT 设置上下文:

https://github.com/matus-chochlik/oglplus/blob/develop/example/standalone/001_hello_glut_glew.cpp

基本上,您需要这部分:

#include <iostream>

#include <GL/glew.h>
#include <GL/glut.h>

#include <oglplus/all.hpp>

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);

    GLint width = 800;
    GLint height = 150;

    glutInitWindowSize(width, height);
    glutInitWindowPosition(100,100);
    glutCreateWindow("OGLplus+GLUT+GLEW");

    if(glewInit() == GLEW_OK) try
    {
        // Your code goes here.

        return 0;
    }
    catch(oglplus::Error& err)
    {
        std::cerr << "OGLPlus error." << std::endl;
    }

    return 1;
}