Shows how to draw a shaded rectangle
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) \
{ \
gl_Position = vec4(Position, 0.0, 1.0); \
vertCoord = vec2( \
(Position.x + 1.0)/2.0, \
(Position.y + 1.0)/2.0 \
); \
} \
");
vs.Compile();
fs.Source(" \
#version 330\n \
in vec2 vertCoord; \
out vec4 fragColor; \
void main(void) \
{ \
fragColor = vec4( \
vertCoord.x - vertCoord.x * vertCoord.y,\
vertCoord.y - vertCoord.x * vertCoord.y,\
vertCoord.x * vertCoord.y, \
1.0 \
); \
} \
");
fs.Compile();
prog.AttachShader(vs).AttachShader(fs);
prog.Link().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<
Vec2f>();
vert_attr.Enable();
}
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);
}
}