2016-07-26 70 views
1

我想创建C++程序使用OpenGL与C++ OpenGL包装库oglplus,但我不能让程序使用oglplus运行,因为当我声明某些oglplus对象oglplus :: MissingFunction异常总是抛出。声明重要的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 :: Buffer

有关如何解决此问题的任何建议?

回答

2

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