Shows the basic usage of OGLplus by drawing a simple triangle.
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 TriangleExample : public Example
{
private:
Context gl;
public:
TriangleExample(void)
{
vs.Source(" \
#version 330\n \
in vec3 Position; \
in vec3 Color; \
out vec4 vertColor; \
void main(void) \
{ \
gl_Position = vec4(Position, 1.0); \
vertColor = vec4(Color, 1.0); \
} \
");
vs.Compile();
fs.Source(" \
#version 330\n \
in vec4 vertColor; \
out vec4 fragColor; \
void main(void) \
{ \
fragColor = vertColor; \
} \
");
fs.Compile();
prog.AttachShader(vs);
prog.AttachShader(fs);
prog.Link();
prog.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, 9, triangle_verts);
VertexArrayAttrib(prog,
"Position").Setup<GLfloat>(3).
Enable();
GLfloat triangle_colors[9] = {
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, 9, triangle_colors);
VertexArrayAttrib(prog,
"Color").Setup<GLfloat>(3).
Enable();
gl.ClearColor(1.0f, 1.0f, 1.0f, 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);
}
}