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)
#include <cmath>
namespace oglplus {
class WritingExample : public Example
{
private:
Context gl;
std::size_t curve_n;
public:
WritingExample(void)
{
vs.Source(
"#version 330\n"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = Position;"
"}"
);
vs.Compile();
gs.Source(
"#version 330\n"
"layout(lines) in;"
"layout(triangle_strip, max_vertices = 4) out;"
"void main(void)"
"{"
" vec4 offs = vec4(0.02, 0.01, 0.0, 0.0);"
" gl_Position = gl_in[0].gl_Position - offs;"
" EmitVertex();"
" gl_Position = gl_in[0].gl_Position + offs;"
" EmitVertex();"
" gl_Position = gl_in[1].gl_Position - offs;"
" EmitVertex();"
" gl_Position = gl_in[1].gl_Position + offs;"
" EmitVertex();"
" EndPrimitive();"
"}"
);
gs.Compile();
fs.Source(
"#version 330\n"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(0.0, 0.0, 0.0, 1.0);"
"}"
);
fs.Compile();
prog.AttachShader(vs);
prog.AttachShader(gs);
prog.AttachShader(fs);
prog.Link();
gl.Use(prog);
};
BezierCurves<Vec2f, double, 3> bezier(
std::vector<Vec2f>(
points,
points+sizeof(points)/sizeof(points[0])
)
);
gl.Bind(writing);
gl.Bind(Buffer::Target::Array, curve_verts);
{
auto data = bezier.Approximate(25);
curve_n = data.size();
gl.Current(Buffer::Target::Array).Data(data);
VertexArrayAttrib attr(prog, "Position");
attr.Enable();
}
gl.ClearColor(0.9f, 0.9f, 0.9f, 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 WritingExample);
}
}