-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.d
53 lines (42 loc) · 1.48 KB
/
app.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import std.stdio;
import teraflop.game : Game;
import teraflop.input;
import teraflop.math;
void main()
{
writeln("Teraflop Triangle Example");
new Triangle().run();
}
private final class Triangle : Game {
import std.typecons : Flag, No, Yes;
import teraflop.async : Event;
import teraflop.ecs : System, World;
import teraflop.graphics : Color, Material, Mesh, Shader, ShaderStage, VertexPosColor;
alias ExitEvent = Event!(Flag!"force");
ExitEvent onExit;
this() {
super("Triangle");
onExit ~= (Flag!"force" force) => {
if (active && force) exit();
}();
}
override void initializeWorld(scope World world) {
// Exit the app with the escape key
world.resources.add(onExit);
auto input = world.resources.get!Input;
input.map.bind("exit").keyboardPressed(KeyboardKey.escape);
this.add(System.from!exitOnEscape);
auto shaders = [
new Shader(ShaderStage.vertex, "examples/triangle/assets/shaders/triangle.vs.spv"),
new Shader(ShaderStage.fragment, "examples/triangle/assets/shaders/triangle.fs.spv")
];
world.spawn(new Material(shaders, No.depthTest), new Mesh!VertexPosColor([
VertexPosColor(vec3f(0.0f, -0.5f, 0), Color.red.vec3f),
VertexPosColor(vec3f(0.5f, 0.5f, 0), Color.green.vec3f),
VertexPosColor(vec3f(-0.5f, 0.5f, 0), Color.blue.vec3f),
], [0, 1, 2]));
}
static void exitOnEscape(scope const InputEventAction event, scope ExitEvent exit) {
if (event.action == "exit") exit(Yes.force);
}
}