]> git.tdb.fi Git - libs/demoscene.git/blob - source/launchscreen.cpp
Allow stages to define actions
[libs/demoscene.git] / source / launchscreen.cpp
1 #include <msp/gl/blend.h>
2 #include <msp/gl/framebuffer.h>
3 #include <msp/gl/renderer.h>
4 #include <msp/strings/format.h>
5 #include "launchscreen.h"
6
7 namespace Msp {
8 namespace DemoScene {
9
10 LaunchScreen::LaunchScreen(Resources &resources):
11         font(resources.get_ui_font()),
12         tech(resources.get_ui_text_technique()),
13         countdown(font, &tech),
14         countdown_value(0),
15         enter_prompt(font, &tech),
16         esc_prompt(font, &tech)
17 {
18         countdown.set_alignment(GL::Text::CENTER);
19
20         enter_prompt.set_alignment(GL::Text::CENTER);
21         enter_prompt.set_text("Press ENTER now to remain windowed");
22
23         esc_prompt.set_alignment(GL::Text::CENTER);
24         esc_prompt.set_text("Press ESC at any time to exit");
25
26         camera.set_orthographic(1920, 1080);
27         camera.set_depth_clip(-1, 1);
28 }
29
30 void LaunchScreen::set_countdown(unsigned c)
31 {
32         if(c!=countdown_value)
33         {
34                 countdown_value = c;
35                 countdown.set_text(format("Going fullscreen in %d...", countdown_value));
36         }
37 }
38
39 void LaunchScreen::render()
40 {
41         GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT);
42         GL::Bind blend(GL::Blend::alpha());
43         GL::Renderer renderer(&camera);
44         renderer.transform(GL::Matrix().scale(48).translate(0, 1.2, 0));
45         countdown.render(renderer);
46         renderer.transform(GL::Matrix::translation(0, -1.2, 0));
47         enter_prompt.render(renderer);
48         renderer.transform(GL::Matrix::translation(0, -1.2, 0));
49         esc_prompt.render(renderer);
50 }
51
52 } // namespace DemoScene
53 } // namespace Msp