-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
101 lines (69 loc) · 3.05 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
101
#include "Engine.h"
#include "Camera.h"
// https://developer.valvesoftware.com/wiki/Source_BSP_File_Format
// https://gist.github.com/aylaylay/9d910fa144b56ca7d0dc
// messsssyyyyyy
// minor todo: add comments to main
int main()
{
bsp map ("de_dust2.bsp");
Engine gl;
gl.openWindow ("BSP");
//glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glfwSetInputMode (gl.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
Camera PlayerCamera (1280, 720, gl.window);
map.LoadMapDetails(PlayerCamera.GetCameraPosition());
GLuint vao;
glGenVertexArrays (1, &vao);
glBindVertexArray (vao);
GLuint vbo;
glGenBuffers (1, &vbo);
glBindBuffer (GL_ARRAY_BUFFER, vbo);
glBufferData (GL_ARRAY_BUFFER, (sizeof(float) * 3) * map.vertices.size(), &map.vertices[0], GL_STATIC_DRAW);
GLuint normalVBO;
glGenBuffers (1, &normalVBO);
glBindBuffer (GL_ARRAY_BUFFER, normalVBO);
glBufferData (GL_ARRAY_BUFFER, (sizeof (float) * 3) * map.mapNormals.size(), &map.mapNormals[0], GL_STATIC_DRAW);
GLuint ebo;
glGenBuffers (1, &ebo);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (GLuint) * map.indices.size(), &map.indices[0], GL_STATIC_DRAW);
GLuint shader = gl.CreateShader ("basic_shader.vert", "basic_shader.frag");
glUseProgram (shader);
glBindBuffer (GL_ARRAY_BUFFER, vbo);
GLint posAttrib = glGetAttribLocation (shader, "position");
glEnableVertexAttribArray (posAttrib);
glVertexAttribPointer (posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer (GL_ARRAY_BUFFER, normalVBO);
GLint nPosAttrib = glGetAttribLocation (shader, "nColor");
glEnableVertexAttribArray (nPosAttrib);
glVertexAttribPointer (nPosAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer (GL_ARRAY_BUFFER, vbo);
GLint view = glGetUniformLocation (shader, "view");
glUniformMatrix4fv (view, 1, GL_FALSE, glm::value_ptr (PlayerCamera.GetView()));
GLint projection = glGetUniformLocation (shader, "projection");
glUniformMatrix4fv (projection, 1, GL_FALSE, glm::value_ptr (PlayerCamera.GetProjection()));
glm::mat4 Model (1.0f);
Model = glm::rotate (Model, 90.0f, glm::vec3 (1, 0, 1));
GLint model = glGetUniformLocation (shader, "model");
glUniformMatrix4fv (model, 1, GL_FALSE, glm::value_ptr (Model));
float LastTime = glfwGetTime();
while (!glfwWindowShouldClose (gl.window))
{
float DeltaTime = glfwGetTime() - LastTime;
LastTime = glfwGetTime();
PlayerCamera.Tick (DeltaTime, gl.window);
glUniformMatrix4fv (view, 1, GL_FALSE, glm::value_ptr (PlayerCamera.GetView()));
glUniformMatrix4fv (projection, 1, GL_FALSE, glm::value_ptr (PlayerCamera.GetProjection()));
glUniformMatrix4fv (model, 1, GL_FALSE, glm::value_ptr (glm::mat4 (1.0f)));
if (glfwGetKey (gl.window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose (gl.window, GL_TRUE);
glClearColor (0.8f , 0.8f , 0.8f , 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffer.
glDrawElements (GL_TRIANGLES, map.indices.size(), GL_UNSIGNED_INT, 0);
glfwSwapBuffers (gl.window);
glfwPollEvents ();
}
glfwTerminate();
return 0;
}