-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
113 lines (87 loc) · 3.38 KB
/
main.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "imgui.h"
#include "imgui_internal.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "imnodes.h"
#include "3rdparty/imnodes/imnodes.h"
#include "editor.hpp"
#include "node.hpp"
GLFWwindow* initializeWindow() {
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW!" << std::endl;
return nullptr;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Node Editor", nullptr, nullptr);
if (!window) {
std::cerr << "Failed to create GLFW window!" << std::endl;
glfwTerminate();
return nullptr;
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable V-Sync
if (glewInit() != GLEW_OK) {
std::cerr << "Failed to initialize GLEW!" << std::endl;
return nullptr;
}
glViewport(0, 0, 1280, 720);
return window;
}
void setupDockSpace() {
// ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(), ImGuiDockNodeFlags_None);
/* if (ImGui::DockBuilderGetNode(ImGui::GetMainViewport()->ID) == NULL) {
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGui::DockBuilderRemoveNode(dockspace_id); // Reset
ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_None);
ImGui::DockBuilderSetNodeSize(dockspace_id, ImGui::GetMainViewport()->Size);
ImGuiID dock_main_id = dockspace_id;
ImGuiID dock_id_top = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Up, 0.7f, nullptr, &dock_main_id);
ImGuiID dock_id_bottom = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Down, 0.3f, nullptr, &dock_main_id);
ImGui::DockBuilderDockWindow("Viewport", dock_id_top);
ImGui::DockBuilderDockWindow("Node Editor", dock_id_bottom);
ImGui::DockBuilderFinish(dockspace_id);
}*/
}
int main() {
GLFWwindow* window = initializeWindow();
if (!window) return -1;
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
//io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 330"); // GLSL verze 3.3
ImNodes::CreateContext();
NodeEditor editor;
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
editor.show();
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
// Cleanup
ImNodes::DestroyContext();
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}