-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
102 lines (75 loc) · 2.43 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
// Execution command on MacOS
// /usr/bin/clang++ -std=c++17 -ILibraries/include -g **.cpp glad.cc -o Main -LLibraries/lib -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit && ./Main
// GLM Reference: https://openframeworks.cc//documentation/glm/detail_func_geometric/#!show_glm::cross
#include "Model.h"
#include "Helpers/Mathematics.h"
#include <cmath>
#include "Globals.h"
#include "World.h"
static void glfwError( int id, const char *description )
{
std::cout << description << std::endl;
}
int main()
{
glfwSetErrorCallback( &glfwError );
// Init GLFW
glfwInit();
// Tell GLFW which version we are using
// For Windows/Linux
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
// //glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// For MacOS
// https://www.glfw.org/faq.html#14---what-platforms-are-supported-by-glfw
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 2 );
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
// Create window object
GLFWwindow* window = glfwCreateWindow( WIDTH, HEIGHT, WINDOW_NAME, NULL, NULL );
if ( window == NULL )
{
std::cout << "Failed to initialize GLFW windows!\n";
glfwTerminate();
return -1;
}
// Use created GLFW window
glfwMakeContextCurrent( window );
// Load GLAD so it configures OpenGL
gladLoadGL();
srand( time( NULL ) );
// Enables the depth buffer
glEnable( GL_DEPTH_TEST );
//glViewport( 0, 0, WIDTH, HEIGHT );
World world( *window, WIDTH, HEIGHT );
//std::cout << "\nWorld Constructed.";
world.Start();
// For terminal to show the lines correctly
std::cout << "\n\n";
// Only close when user decides to close the window
while ( !glfwWindowShouldClose( window ) )
{
glClearColor(
Globals::kBG_COLOR_R,
Globals::kBG_COLOR_G,
Globals::kBG_COLOR_B,
Globals::kBG_COLOR_A
);
// Clear the depth buffer and the color buffer bit
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
world.Update();
if( !world.ShouldPlayWorld ) break;
glfwSwapBuffers( window );
// Process all the events
glfwPollEvents(); // If not done window will go to not responding
}
world.Destroy();
// Destroy Window
glfwDestroyWindow( window );
// End GLFW
glfwTerminate();
// std::cin.get();
return 0;
}