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 SkyBoxExample : public Example
{
private:
Context gl;
Lazy<Uniform<Mat4f>> projection_matrix, camera_matrix;
public:
SkyBoxExample(void)
: prog()
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
{
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix;"
"mat4 Matrix = ProjectionMatrix*CameraMatrix;"
"in vec3 Corner;"
"out vec3 vertTexCoord;"
"void main(void)"
"{"
" gl_Position = Matrix * vec4(Corner * 10.0, 1.0);"
" vertTexCoord = Corner;"
"}"
));
vs.Compile();
prog.AttachShader(vs);
"#version 330\n"
"uniform samplerCube EnvMap;"
"in vec3 vertTexCoord;"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(texture(EnvMap, normalize(vertTexCoord)).rgb, 1.0);"
"}"
));
fs.Compile();
prog.AttachShader(fs);
prog.Link();
prog.Use();
sky_box.Bind();
GLfloat sky_box_corners[8*3] = {
-1.0f,-1.0f,-1.0f,
+1.0f,-1.0f,-1.0f,
-1.0f,+1.0f,-1.0f,
+1.0f,+1.0f,-1.0f,
-1.0f,-1.0f,+1.0f,
+1.0f,-1.0f,+1.0f,
-1.0f,+1.0f,+1.0f,
+1.0f,+1.0f,+1.0f
};
corners.Bind(Buffer::Target::Array);
Buffer::Data(Buffer::Target::Array, sky_box_corners);
VertexArrayAttrib vert_attr(prog, "Corner");
GLuint sky_box_indices[6*5] = {
1, 3, 5, 7, 9,
4, 6, 0, 2, 9,
2, 6, 3, 7, 9,
4, 0, 5, 1, 9,
5, 7, 4, 6, 9,
0, 2, 1, 3, 9
};
indices.Bind(Buffer::Target::ElementArray);
Buffer::Data(Buffer::Target::ElementArray, 6*5, sky_box_indices);
gl.PrimitiveRestartIndex(9);
{
UniformSampler(prog, "EnvMap").Set(0);
Texture::Active(0);
gl.Bound(Texture::Target::CubeMap, env_map)
Texture::CubeMapFace(0),
);
Texture::CubeMapFace(1),
);
Texture::CubeMapFace(2),
);
Texture::CubeMapFace(3),
);
Texture::CubeMapFace(4),
);
Texture::CubeMapFace(5),
);
}
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.ClearDepth(1.0f);
}
void Reshape(GLuint width, GLuint height)
{
gl.Viewport(width, height);
projection_matrix.Set(
Degrees(48),
float(width)/height,
1, 100
)
);
}
{
3.0,
Degrees(-35 -
SineWave(time / 19.0) * 30)
);
camera_matrix.Set(camera);
gl.Clear().ColorBuffer().DepthBuffer();
}
{
return time < 45.0;
}
double ScreenshotTime(void) const
{
return 1.0;
}
};
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 SkyBoxExample);
}
}