-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
82 lines (62 loc) · 2.1 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
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
// Selfwritten files
#include "sandbox.h"
// Create a sandbox/world class that can hold on all shaders and objects etc.
// Headers to functions below. Want to keep main at top.
GLFWwindow* initGLFW_GLAD();
void display(GLFWwindow* window);
void initShaders();
int main(void)
{
GLFWwindow* window = nullptr;
window = initGLFW_GLAD();
if (!window)
{
// Some error happened in init function
return -1;
}
Sandbox sandbox(window);
sandbox.display();
//display(window); Now done in sandbox!
glfwTerminate();
return 0;
}
GLFWwindow* initGLFW_GLAD()
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return nullptr;
// Must have this to get right version, plus compiling frameworks for mac.
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
glfwWindowHint(GLFW_SAMPLES, 4);
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(1080, 800, "Real Time Particle Physics Simulation", NULL, NULL);
if (!window)
{
glfwTerminate();
return nullptr;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
// Think you have to init glad after OpenGL context which is the two closest above function.
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return nullptr;
}
// To validate that linking of libraries are correct
std::cout << "----GL Version:---------" << std::endl;
std::cout << glGetString(GL_VERSION) << std::endl;
std::cout << "----GLSL Version:---------" << std::endl;
std::cout << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
std::cout << "----------------------------- \n" << std::endl;
return window;
}