-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.d
More file actions
97 lines (74 loc) · 1.95 KB
/
main.d
File metadata and controls
97 lines (74 loc) · 1.95 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
module main;
import std.stdio;
public import derelict.opengl3.gl3;
public import derelict.glfw3.glfw3;
public import derelict.util.exception;
import example, examples.all;
import graphics.all;
import utils.image;
import core.runtime;
import math.vector;
import input;
import window;
import core.sys.windows.windows;
static this()
{
if(!runModuleUnitTests())
{
}
}
void main(string[] argv)
{
try {
loadSharedLibs();
auto window = openWindow();
glfwSetCharCallback(window._glfwWindow, &unicodeCallback);
Context.initialize();
gl.enable(Capability.blend);
gl.blendState = BlendState.nonPremultiplied;
gl.enable(Capability.multisample);
Example[] examples;
//examples ~= new TriangleExample();
//examples ~= new RectangleExample();
//examples ~= new NewtonExample();
//examples ~= new MandelbrotExample();
//examples ~= new BlobEx();
//examples ~= new TextureExample();
//examples ~= new ParticleSystem();
//examples ~= new SpriteBufferExample();
examples ~= new GUIExample(window.mouseState, window.keyboardState, window.clipboard);
int activeExample = examples.length - 1;
bool wasPressed = false;
window.onUpdate =
{
if(!wasPressed && glfwGetKey(window._glfwWindow, GLFW_KEY_N) == GLFW_PRESS)
activeExample = (activeExample + 1) % examples.length;
wasPressed = glfwGetKey(window._glfwWindow, GLFW_KEY_N) == GLFW_PRESS;
};
window.onRender =
{
examples[activeExample].render(0);
};
window.run(WindowMode.pollEvents);
//window.close();
glfwTerminate();
} catch(Throwable e) {
std.stdio.writeln(e);
std.stdio.readln();
}
}
void loadSharedLibs()
{
DerelictGL3.load();
DerelictGLFW3.load();
}
auto openWindow()
{
if (!glfwInit()) throw new Exception("Failed to initialize GLFW");
glfwWindowHint(GLFW_SAMPLES, 4);
//glfwWindowHint(GLFW_DECORATED, GL_FALSE);
auto window = new Window(1280, 720, "Cloud Forest!");
//Load the opengl driver for the window.
DerelictGL3.reload();
return window;
}