-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
140 lines (121 loc) · 4.13 KB
/
Main.cpp
File metadata and controls
140 lines (121 loc) · 4.13 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <glad/gl.h>
#include <GLFW/glfw3.h>
#include "EditorApp.h"
#include "ResourceManager.h"
#include "CrashLogger.h"
#include "UserDataManager.h"
#include "Workspace.h"
using namespace Voltray::Utils;
using Voltray::Editor::EditorApp;
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#include <limits.h>
#endif
// Increase stack size for debug builds
#ifdef _WIN32
#pragma comment(linker, "/STACK:8388608") // 8MB stack
#endif
int main()
{
#ifdef _WIN32
SetUnhandledExceptionFilter([](PEXCEPTION_POINTERS exInfo) -> LONG
{
CrashLogger::LogCrash(exInfo);
return EXCEPTION_EXECUTE_HANDLER; });
#endif
CrashLogger::Initialize();
try
{
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
// Start in windowed mode with reasonable size
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); // Start maximized instead of fake fullscreen
GLFWwindow *window = glfwCreateWindow(1280, 720, "Voltray Editor", nullptr, nullptr);
if (!window)
{
glfwTerminate();
return -1;
}
// Add F11 key callback to toggle fullscreen modes
glfwSetKeyCallback(window, [](GLFWwindow *window, int key, int scancode, int action, int mods)
{
(void)scancode; // Suppress unused parameter warning
(void)mods; // Suppress unused parameter warning
if (key == GLFW_KEY_F11 && action == GLFW_PRESS) {
static bool isFullscreen = false; // Start in windowed mode
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
if (isFullscreen) {
// Switch to windowed mode
glfwSetWindowMonitor(window, nullptr, 100, 100, 1280, 720, 0);
} else {
// Switch to exclusive fullscreen
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
}
isFullscreen = !isFullscreen;
} });
glfwMakeContextCurrent(window);
if (!gladLoadGL(glfwGetProcAddress))
{
glfwDestroyWindow(window);
glfwTerminate();
return -1;
}
// Initialize ResourceManager first (required by UserDataManager)
#ifdef _WIN32
char exePath[MAX_PATH];
GetModuleFileNameA(nullptr, exePath, MAX_PATH);
ResourceManager::Initialize(exePath);
#else
char exePath[PATH_MAX];
readlink("/proc/self/exe", exePath, PATH_MAX);
ResourceManager::Initialize(exePath);
#endif
// Initialize UserDataManager after ResourceManager
if (!UserDataManager::Initialize())
{
std::cerr << "Failed to initialize UserDataManager" << std::endl;
glfwDestroyWindow(window);
glfwTerminate();
return -1;
}
// Initialize WorkspaceManager
if (!WorkspaceManager::Initialize())
{
std::cerr << "Failed to initialize WorkspaceManager" << std::endl;
glfwDestroyWindow(window);
glfwTerminate();
return -1;
}
// Initialize and run editor
EditorApp editor;
editor.Init(window);
while (!glfwWindowShouldClose(window))
{
editor.RenderUI();
glfwSwapBuffers(window);
glfwPollEvents();
}
editor.Shutdown();
glfwDestroyWindow(window);
glfwTerminate();
}
catch (const std::exception &e)
{
CrashLogger::LogException(e.what());
}
catch (...)
{
CrashLogger::LogException("Unknown exception");
}
return 0;
}