声明重要的oglplus对象会引发异常oglplus::MissingFunction

Declaring important oglplus objects throws the exception oglplus::MissingFunction

本文关键字:oglplus 异常 MissingFunction 重要的 对象 声明      更新时间:2023-10-16

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

我的操作系统是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

  • oglplus::顶点着色器
  • oglplus::FragmentShader
  • oglplus::程序
  • oglplus::程序
  • oglplus::VertexArray
  • oglplus::缓冲区

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

在使用任何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;
}