【问题标题】:Declaring important oglplus objects throws the exception oglplus::MissingFunction声明重要的 oglplus 对象会引发异常 oglplus::MissingFunction
【发布时间】:2016-07-26 05:17:55
【问题描述】:

我想使用带有 C++ OpenGL 包装库 oglplus 的 OpenGL 创建 C++ 程序,但我无法让使用 oglplus 的程序运行,因为当我声明某些 oglplus 对象时,总是会抛出 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::VertexShader
  • oglplus::FragmentShader
  • oglplus::程序
  • oglplus::程序
  • oglplus::VertexArray
  • oglplus::缓冲区

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

【问题讨论】:

    标签: c++ opengl exception graphics oglplus


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-23
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多