Copyright 2008-2014 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 RectangleExample : public Example
{
private:
Context gl;
public:
RectangleExample(void)
{
vs.Source(" \
#version 330\n \
in vec2 Position; \
out vec2 vertCoord; \
void main(void) \
{ \
vertCoord = Position; \
gl_Position = vec4(Position, 0.0, 1.0); \
} \
");
vs.Compile();
fs.Source(" \
#version 330\n \
const float radius = 0.4; \
in vec2 vertCoord; \
uniform vec2 RedCenter, GreenCenter, BlueCenter; \
out vec4 fragColor; \
void main(void) \
{ \
vec3 dist = vec3( \
distance(vertCoord, RedCenter), \
distance(vertCoord, GreenCenter), \
distance(vertCoord, BlueCenter) \
); \
fragColor = vec4( \
dist.r < radius ? 1.0 : (2*radius - dist.r) / radius, \
dist.g < radius ? 1.0 : (2*radius - dist.g) / radius, \
dist.b < radius ? 1.0 : (2*radius - dist.b) / radius, \
1.0 \
); \
} \
");
fs.Compile();
prog.AttachShader(vs);
prog.AttachShader(fs);
prog.Link();
prog.Use();
rectangle.Bind();
GLfloat rectangle_verts[8] = {
-1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, -1.0f,
1.0f, 1.0f
};
verts.Bind(Buffer::Target::Array);
Buffer::Data(Buffer::Target::Array, 8, rectangle_verts);
VertexArrayAttrib vert_attr(prog, "Position");
vert_attr.Setup<GLfloat>(2);
vert_attr.Enable();
Uniform<Vec2f>(prog,
"RedCenter").
Set(
Vec2f(-0.141f, 0.141f));
Uniform<Vec2f>(prog,
"GreenCenter").
Set(
Vec2f(0.141f, 0.141f));
Uniform<Vec2f>(prog,
"BlueCenter").
Set(
Vec2f(0.0f, -0.2f));
}
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 RectangleExample);
}
}