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)
#include <sstream>
namespace oglplus {
class RectangleExample : public Example
{
private:
Context gl;
public:
RectangleExample(void)
{
std::stringstream vs_source(
"#version 330\n"
"in vec2 Position;"
"in vec3 Color;"
"out vec3 vertColor;"
"void main(void)"
"{"
" vertColor = Color;"
" gl_Position = vec4(Position, 0.0, 1.0);"
"}"
);
vs.Source(GLSLSource::FromStream(vs_source));
vs.Compile();
std::stringstream fs_source(
"#version 330\n"
"in vec3 vertColor;"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(vertColor, 1.0);"
"}"
);
fs.Source(GLSLSource::FromStream(fs_source));
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");
GLfloat rectangle_colors[12] = {
1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
};
colors.Bind(Buffer::Target::Array);
Buffer::Data(Buffer::Target::Array, 12, rectangle_colors);
VertexArrayAttrib color_attr(prog, "Color");
}
void Reshape(GLuint width, GLuint height)
{
gl.Viewport(width, height);
}
{
}
};
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);
}
}