-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
121 lines (102 loc) · 3.8 KB
/
main.cpp
File metadata and controls
121 lines (102 loc) · 3.8 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
#include "Window.h"
#include "core.h"
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
void error_callback(int error, const char* description) {
// Print error.
std::cerr << description << std::endl;
}
void setup_callbacks(GLFWwindow* window) {
// Set the error callback.
glfwSetErrorCallback(error_callback);
// Set the window resize callback.
glfwSetWindowSizeCallback(window, Window::resizeCallback);
// Set the key callback.
glfwSetKeyCallback(window, Window::keyCallback);
// Set the mouse and cursor callbacks
glfwSetMouseButtonCallback(window, Window::mouse_callback);
glfwSetCursorPosCallback(window, Window::cursor_callback);
}
void setup_opengl_settings() {
// Enable depth buffering.
glEnable(GL_DEPTH_TEST);
// Related to shaders and z value comparisons for the depth buffer.
glDepthFunc(GL_LEQUAL);
// Set polygon drawing mode to fill front and back of each polygon.
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Set clear color to black.
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void print_versions() {
// Get info of GPU and supported OpenGL version.
std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
std::cout << "OpenGL version supported: " << glGetString(GL_VERSION)
<< std::endl;
// If the shading language symbol is defined.
#ifdef GL_SHADING_LANGUAGE_VERSION
std::cout << "Supported GLSL version is: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
#endif
}
int main(int argc, char** argv) {
// Create the GLFW window.
GLFWwindow* window = Window::createWindow(800, 600);
if (!window) exit(EXIT_FAILURE);
// Print OpenGL and GLSL versions.
print_versions();
// Setup callbacks.
setup_callbacks(window);
// Setup OpenGL settings.
setup_opengl_settings();
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
#ifdef __EMSCRIPTEN__
ImGui_ImplGlfw_InstallEmscriptenCallbacks(window, "#canvas");
#endif
const char* glsl_version = "#version 130";
ImGui_ImplOpenGL3_Init(glsl_version);
// Initialize the shader program; exit if initialization fails.
if (!Window::initializeProgram()) exit(EXIT_FAILURE);
// Initialize objects/pointers for rendering; exit if initialization fails.
if (!Window::initializeObjects()) exit(EXIT_FAILURE);
// Load skeleton
const char* skeleton_name = nullptr;
const char* skin_name = nullptr;
if (argc == 2) { // only skeleton provided
skeleton_name = argv[1];
Window::LoadSkeleton(skeleton_name);
}
else if (argc == 3) {
skeleton_name = argv[1];
skin_name = argv[2];
Window::LoadSkeleton(skeleton_name);
Window::LoadSkeleton(skin_name);
}
else if (argc == 4) {
skeleton_name = argv[1];
skin_name = argv[2];
const char* anim_name = argv[3];
Window::LoadSkeleton(skeleton_name);
Window::LoadSkeleton(skin_name);
Window::LoadSkeleton(anim_name);
}
// Loop while GLFW window should stay open.
while (!glfwWindowShouldClose(window)) {
// Main render display callback. Rendering of objects is done here.
Window::displayCallback(window);
// Idle callback. Updating objects, etc. can be done here.
Window::idleCallback();
}
Window::cleanUp();
// Destroy the window.
glfwDestroyWindow(window);
// Terminate GLFW.
glfwTerminate();
exit(EXIT_SUCCESS);
}