-
Notifications
You must be signed in to change notification settings - Fork 13
/
app.d
85 lines (70 loc) · 2.14 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
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
module gui.guimain;
import std.string;
import std.conv;
import derelict.opengl3.gl3;
import derelict.glfw3.glfw3;
import derelict.imgui.imgui;
import imgui_glfw;
import imgui_demo;
GLFWwindow* window;
float[3] clear_color = [0.3f, 0.4f, 0.8f];
bool showDDemoWindow;
bool showOrgDemoWindow;
void main(string[] argv) {
DerelictGL3.load();
DerelictGLFW3.load();
DerelictImgui.load();
// Setup window
window = initWindow("ImGui OpenGL3 example");
if(!window) return;
// Setup ImGui binding
igImplGlfwGL3_Init(window, true);
// Main loop
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
igImplGlfwGL3_NewFrame();
// contents
if(igButton("RUN imgui_demo (D-lang version)")) showDDemoWindow = !showDDemoWindow;
if(igButton("RUN imgui_demo (C++ version)")) showOrgDemoWindow = !showOrgDemoWindow;
if(showDDemoWindow) {
igSetNextWindowPos(ImVec2(660, 30), ImGuiCond_FirstUseEver);
imgui_demo.igShowDemoWindow(&showDDemoWindow);
}
if(showOrgDemoWindow) {
igSetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver);
derelict.imgui.imgui.igShowDemoWindow(&showOrgDemoWindow);
}
// Rendering
auto io = igGetIO();
glViewport(0, 0, cast(int)io.DisplaySize.x, cast(int)io.DisplaySize.y);
glClearColor(clear_color[0], clear_color[1], clear_color[2], 0);
glClear(GL_COLOR_BUFFER_BIT);
igRender();
glfwSwapBuffers(window);
}
// Cleanup
igImplGlfwGL3_Shutdown();
glfwTerminate();
}
GLFWwindow* initWindow(string title) {
// Setup window
glfwSetErrorCallback(&error_callback);
if (!glfwInit())
return null;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
auto window = glfwCreateWindow(1280, 720, title.toStringz(), null, null);
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
glfwInit();
DerelictGL3.reload();
return window;
}
extern(C) nothrow void error_callback(int error, const(char)* description) {
import std.stdio;
import std.conv;
try writefln("glfw err: %s ('%s')",error, to!string(description));
catch(Throwable) {}
}