-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitgame.cpp
More file actions
90 lines (68 loc) · 2.75 KB
/
initgame.cpp
File metadata and controls
90 lines (68 loc) · 2.75 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
#include "controls.cpp"
void reshapeWindow (GLFWwindow* window, int width, int height){
int fbwidth=width, fbheight=height;
glfwGetFramebufferSize(window, &fbwidth, &fbheight);
GLfloat fov = 90.0f;
glViewport (0, 0, (GLsizei) fbwidth, (GLsizei) fbheight);
Matrices.projection = glm::frustum(-77.0f, 77.0f, -60.0f, 60.0f, 150.0f, 500.0f);
}
GLFWwindow* initGLFW (int width, int height)
{
GLFWwindow* window; // window desciptor/handle
glfwSetErrorCallback(error_callback);
if (!glfwInit()) {
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(width, height, "Sample OpenGL 3.3 Application", NULL, NULL);
if (!window) {
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval( 1 );
/* --- register callbacks with GLFW --- */
/* Register function to handle window resizes */
/* With Retina display on Mac OS X GLFW's FramebufferSize
is different from WindowSize */
glfwSetFramebufferSizeCallback(window, reshapeWindow);
glfwSetWindowSizeCallback(window, reshapeWindow);
/* Register function to handle window close */
glfwSetWindowCloseCallback(window, quit);
/* Register function to handle keyboard input */
glfwSetKeyCallback(window, keyboard); // general keyboard input
glfwSetCharCallback(window, keyboardChar); // simpler specific character handling
/* Register function to handle mouse click */
glfwSetMouseButtonCallback(window, mouseButton); // mouse button clicks
return window;
}
/* Initialize the OpenGL rendering properties */
/* Add all the models to be created here */
void initGL (GLFWwindow* window, int width, int height)
{
/* Objects should be created before any other gl function and shaders */
// Create the models
createCircle (); // Generate the VAO, VBOs, vertices data & copy into the array buffer
createRectangle ();
createPerson();
createPlatform();
chances();
// Create and compile our GLSL program from the shaders
programID = LoadShaders( "Sample_GL.vert", "Sample_GL.frag" );
// Get a handle for our "MVP" uniform
Matrices.MatrixID = glGetUniformLocation(programID, "MVP");
reshapeWindow (window, width, height);
// Background color of the scene
glClearColor (0.2f, 0.2f, 0.8f, 0.0f); // R, G, B, A
glClearDepth (1.0f);
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);
cout << "VENDOR: " << glGetString(GL_VENDOR) << endl;
cout << "RENDERER: " << glGetString(GL_RENDERER) << endl;
cout << "VERSION: " << glGetString(GL_VERSION) << endl;
cout << "GLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
}