久々に OGLplus を触ってみた

TL にちょろっと話が出てきたので久々に試してみました。
今は ver 0.14.0 ですかね。
かなり構造が変わったみたいで、以前から問題になっていた関数ポインタ回りが改善されていました。
これでやっと OGLplus 側のコードを変更しないでも Windows で使用できるようになりました。

[ソース]

#include <string>
#define GL_VERSION_4_1 1

#define OGLPLUS_NO_SITE_CONFIG
#define OGLPLUS_USE_GLEW 1

#include <oglplus/gl.hpp>
#include <oglplus/all.hpp>

#include <GL/Glut.h>

#include <memory>
#include <cstdlib>

namespace oglplus {

// example.hpp
struct Example
{
    virtual ~Example(void)
    { }

    // Hint for the main function whether to continue rendering
    // Implementations of the main function may choose to ignore
    // the result of this function
    virtual bool Continue(double duration)
    {
        return duration < 3.0; // [seconds]
    }

    virtual void Reshape(size_t width, size_t height) = 0;

    virtual bool UsesMouseMotion(void) const
    {
        return false;
    }

    virtual void MouseMoveNormalized(float x, float y, float aspect)
    {
    }

    virtual void MouseMove(size_t x, size_t y, size_t width, size_t height)
    {
        return MouseMoveNormalized(
            (float(x) - width * 0.5f) / (width * 0.5f),
            (float(y) - height* 0.5f) / (height* 0.5f),
            float(width)/height
        );
    }

    virtual void Render(double time) = 0;
};

std::unique_ptr<Example> makeExample(void);


// 001_triangle.cpp
class TriangleExample : public Example
{
private:
    // wrapper around the current OpenGL context
    Context gl;

    // Vertex shader
    VertexShader vs;

    // Fragment shader
    FragmentShader fs;

    // Program
    Program prog;

    // A vertex array object for the rendered triangle
    VertexArray triangle;
    // VBO for the triangle's vertices
    Buffer verts;
public:
    TriangleExample(void)
    {
        // Set the vertex shader source
        vs.Source(" \
            #version 330\n \
            in vec3 Position; \
            void main(void) \
            { \
                gl_Position = vec4(Position, 1.0); \
            } \
        ");
        // compile it
        vs.Compile();

        // set the fragment shader source
        fs.Source(" \
            #version 330\n \
            out vec4 fragColor; \
            void main(void) \
            { \
                fragColor = vec4(1.0, 0.0, 0.0, 1.0); \
            } \
        ");
        // compile it
        fs.Compile();

        // attach the shaders to the program
        prog.AttachShader(vs);
        prog.AttachShader(fs);
        // link and use it
        prog.Link();
        prog.Use();

        // bind the VAO for the triangle
        triangle.Bind();

        GLfloat triangle_verts[9] = {
            0.0f, 0.0f, 0.0f,
            1.0f, 0.0f, 0.0f,
            0.0f, 1.0f, 0.0f
        };
        // bind the VBO for the triangle vertices
        verts.Bind(Buffer::Target::Array);
        // upload the data
        Buffer::Data(Buffer::Target::Array, 9, triangle_verts);
        // setup the vertex attribs array for the vertices
        VertexAttribArray vert_attr(prog, "Position");
        vert_attr.Setup(3, DataType::Float);
        vert_attr.Enable();

        Context::ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.ClearDepth(1.0f);
    }

    void Reshape(size_t width, size_t height)
    {
        gl.Viewport(width, height);
    }

    void Render(double)
    {
        gl.Clear().ColorBuffer().DepthBuffer();

        gl.DrawArrays(PrimitiveType::Triangles, 0, 3);
    }
};

std::unique_ptr<Example> makeExample(void)
{
    return std::unique_ptr<Example>(new TriangleExample);
}


} // namespace oglplus

std::shared_ptr<oglplus::Example> example;

void
display(){
    example->Render(0.0);
    glutSwapBuffers();
    glFlush();
}

void
resize(int w, int h){
    example->Reshape(w, h);
}

void
idle(){
    glutPostRedisplay();
}

int
main(int argc, char *argv[]){
    
    // glut の初期化
    glutInit(&argc, argv);
    glutInitWindowSize(500, 500);
    glutCreateWindow(argv[0]);
    glutDisplayFunc(display);
    glutReshapeFunc(resize);
    glutIdleFunc(idle);
    glutPostRedisplay();

    // glew の初期化
    auto err = glewInit();
    if (err != GLEW_OK)
    {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }

    // glew の初期化後にインスタンスを生成
    example = oglplus::makeExample();
    
    // メインループ
    glutMainLoop();
    return 0;
}


とりあえず、手元に合った適当な OGLplus のコードで試してみました。
基本的なコードは変わってないかな?
あと直接は試してないですが、MSVC 11 Beta にも対応しているみたいですね。
うむ、いい感じに開発が進んでいる様子。