OGLplus のエラーハンドリング

OGLplus では、OpenGL でエラーが発生した場合に、例外をスローします。
スローした例外から詳細な情報(ソースファイルの位置や OpenGLAPIなど)を取得することが出来ます。

[ソース]

#include <vector>
#include <iostream>

#include <GL/glew.h>
#include <oglplus/gl.hpp>
#include <oglplus/context.hpp>
#include <oglplus/shader.hpp>
#include <GL/Glut.h>

namespace glp = oglplus;
typedef glp::Context glc;


int
main(int argc, char *argv[]) try{
    
    // Shader を使うために初期化
    glutCreateWindow("");
    auto err = glewInit();
    if (err != GLEW_OK){
        std::cout << "Error:" << glewGetErrorString(err) << std::endl;
    }
    
    glp::VertexShader vs;

    // 適当にエラーを履かせてみる
    // vs.Source(R"delimiter(
    //     #version 330
    //     in vec3 Position;
    //     void main(void){
    //         gl_Position = vec4(Position, 1.0);
    //     }
    // )delimiter");
    
    // コンパイル
    vs.Compile();
    std::cout << "SUCCESS" << std::endl;
    
    return 0;
}
catch(glp::Error const& error){
    std::cout << error.what() << std::endl;
    std::cout << "GLSymbol          " << error.GLSymbol          () << std::endl;
    std::cout << "File              " << error.File              () << std::endl;
    std::cout << "Func              " << error.Func              () << std::endl;
    std::cout << "Line              " << error.Line              () << std::endl;
    std::cout << "ClassName         " << error.ClassName         () << std::endl;
    std::cout << "ObjectDescription " << error.ObjectDescription () << std::endl;
}

[出力]

OpenGL shading language compilation error
GLSymbol          CompileShader
File              D:/opengl/oglplus/include/oglplus/shader.hpp
Func              Compile
Line              220
ClassName         Shader
ObjectDescription 

[OGLplus]

  • 0.7.0