-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (63 loc) · 2.11 KB
/
main.cpp
File metadata and controls
77 lines (63 loc) · 2.11 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
import std;
import imgui.backend.glfw_opengl3;
namespace {
struct GlfwError {
int code = 0;
const char* description = nullptr;
};
GlfwError captureError() {
const char* description = nullptr;
const int errorCode = ImGui::Backend::GlfwOpenGL3::GetError(&description);
return GlfwError{errorCode, description};
}
int fail(const char* step, int exitCode, GlfwError error) {
std::println(
"failed at {}: GLFW error {} ({})",
step,
error.code,
error.description != nullptr ? error.description : "no GLFW error description"
);
return exitCode;
}
}
int main() {
namespace Backend = ImGui::Backend::GlfwOpenGL3;
if (!Backend::InitGlfw()) {
return fail("glfwInit", 1, captureError());
}
Backend::DefaultWindowHints();
Backend::ConfigureOpenGL(3, 3, true, false);
auto* window = Backend::CreateWindow(640, 360, "mcpp imgui minimal window");
if (window == nullptr) {
const auto error = captureError();
Backend::TerminateGlfw();
return fail("glfwCreateWindow", 2, error);
}
Backend::MakeContextCurrent(window);
Backend::SwapInterval(1);
ImGuiContext* context = ImGui::CreateContext();
ImGui::SetCurrentContext(context);
if (!Backend::Init(window)) {
const auto error = captureError();
ImGui::DestroyContext(context);
Backend::DestroyWindow(window);
Backend::TerminateGlfw();
return fail("ImGui GLFW/OpenGL3 backend init", 3, error);
}
while (!Backend::WindowShouldClose(window)) {
Backend::PollEvents();
Backend::NewFrame();
ImGui::NewFrame();
ImGui::Begin("Minimal ImGui Window");
ImGui::TextUnformatted("mcpp module import, no include in consumer code");
ImGui::End();
ImGui::Render();
Backend::RenderDrawData(ImGui::GetDrawData());
Backend::SwapBuffers(window);
}
Backend::Shutdown();
ImGui::DestroyContext(context);
Backend::DestroyWindow(window);
Backend::TerminateGlfw();
return 0;
}