-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
87 lines (70 loc) · 2.23 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
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
// Project headers
#include "camera.h"
#include "utils.h"
#include "drawing_utils.h"
#include "imgui.h"
#include "imgui_manager.h"
#include "imgui_widgets.h"
// Global variables
Camera camera;
int main() {
// Initialize GLFW and create a window
InitializeGLFW();
GLFWwindow* window = CreateWindow();
if (!window) return -1;
// Initialize GLEW and setup OpenGL settings
InitializeGLEW();
SetupOpenGLSettings();
// Setup callbacks and initialize ImGui
SetupCallbacks(window);
ImGuiManager::Init(window);
// Create grid and axes
const GridData grid = CreateGrid();
// Main render loop
double lastFrame = 0.0f, fpsTimer = 0.0f;
int frameCount = 0;
double fps = 0.0f, frameTime = 0.0f;
while (!glfwWindowShouldClose(window)) {
// Calculate delta time
const double currentFrame = glfwGetTime();
const double deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// FPS calculation
frameCount++;
fpsTimer += deltaTime;
if (fpsTimer >= 1.0f) {
fps = frameCount / fpsTimer;
frameTime = (fpsTimer / frameCount) * 1000.0f;
frameCount = 0;
fpsTimer = 0.0f;
}
// Input handling and ImGui rendering
camera.processKeyboard(window, deltaTime);
ImGuiManager::BeginFrame();
RenderImGuiWidgets(fps, frameTime);
ImGui::Render();
// Clear screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// View and projection matrices
glm::mat4 view = camera.getViewMatrix();
glm::mat4 projection = glm::perspective(glm::radians(45.0f), 1280.0f / 960.0f, 0.1f, 100.0f);
// Draw grid and axes
DrawGrid(grid, view, projection);
// Render ImGui and swap buffers
ImGuiManager::Render();
glfwSwapBuffers(window);
glfwPollEvents();
}
// Cleanup
ImGuiManager::Cleanup();
glDeleteVertexArrays(1, &grid.vao);
glDeleteBuffers(1, &grid.vbo);
glDeleteProgram(grid.shaderProgram);
glfwTerminate();
return 0;
}