]> git.tdb.fi Git - libs/gl.git/blob - demos/forestpond/source/forestpond.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / demos / forestpond / source / forestpond.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/gl/sequencebuilder.h>
3 #include "forestpond.h"
4
5 using namespace std;
6 using namespace Msp;
7
8 ForestPond::ForestPond(int, char **):
9         window(display, 1920, 1080),
10         gl_device(window),
11         /* TODO InstanceArray is not compatible with ResourceManager at the moment,
12         because it requires Mesh to have its vertex format ready. */
13         resources(nullptr),
14         view(window),
15         camera(resources.get<GL::Camera>("Camera.camera")),
16         water(resources.get<GL::Object>("Water.object"), resources, { resources.get<GL::Mesh>("Terrain.mesh"), -10.0f, -3.0f, 2.0f, 6.0f })
17 {
18         window.set_title("Forest Pond");
19         window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &ForestPond::exit), 0));
20
21         GL::SequenceBuilder seq_bld(resources.get<GL::SequenceTemplate>("Forest.seq"));
22         seq_bld.set_debug_name("Main sequence");
23         seq_bld.set_renderable("content", content);
24         sequence.reset(seq_bld.build(view));
25
26         content.add(resources.get<GL::Scene>("Forest.scene"));
27         content.add(water);
28         water.set_matrix(GL::Matrix::translation(GL::Vector3(-3, 2, 0)));
29
30         view.set_content(sequence.get());
31         view.set_camera(&camera);
32 }
33
34 int ForestPond::main()
35 {
36         window.show();
37         return Application::main();
38 }
39
40 void ForestPond::tick()
41 {
42         display.tick();
43         view.render();
44 }
45
46
47 ForestPond::Resources::Resources(GL::ResourceManager *rm)
48 {
49         FS::Path base_dir = FS::get_sys_data_dir()/"demos"/"forestpond"/"data";
50         source.add_directory(base_dir);
51         source.add_directory(base_dir/"textures");
52         source.add_directory(base_dir/"exported");
53         add_source(source);
54
55         set_resource_manager(rm);
56 }