Shows the basic usage of OGLplus by drawing a blue triangle (using GLSL 120).
Copyright 2008-2013 Matus Chochlik. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
namespace oglplus {
class TriangleExample : public Example
{
private:
Context gl;
public:
TriangleExample(void)
{
#version 120\n \
attribute vec3 Position; \
void main(void) \
{ \
gl_Position = vec4(Position, 1.0); \
} \
")).Compile();
#version 120\n \
void main(void) \
{ \
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); \
} \
")).Compile();
prog.AttachShader(vs).AttachShader(fs);
prog.Link().Use();
triangle.Bind();
GLfloat triangle_verts[9] = {
0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f,-1.0f, 0.0f
};
verts.Bind(Buffer::Target::Array);
Buffer::Data(Buffer::Target::Array, triangle_verts);
(prog|"Position").Setup<Vec3f>().Enable();
gl.ClearColor(0.5f, 0.5f, 0.5f, 0.0f);
}
void Reshape(GLuint width, GLuint height)
{
gl.Viewport(width, height);
}
{
gl.Clear().ColorBuffer();
}
};
void setupExample(ExampleParams& ){ }
std::unique_ptr<ExampleThread> makeExampleThread(
Example& ,
unsigned ,
const ExampleParams&
){ return std::unique_ptr<ExampleThread>(); }
std::unique_ptr<Example> makeExample(const ExampleParams& )
{
return std::unique_ptr<Example>(new TriangleExample);
}
}