-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
570 lines (460 loc) · 17.4 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
//Coursework P - Shantnu Singh
//Basics
#include <stdio.h>
#include <fstream>
#include <sstream>
// OpenGL (GLFW/GLEW)
#include <GL/glew.h>
#include <GLFW/glfw3.h>
// GLM (basics)
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
// Bullet Physics (basics)
#include <btBulletDynamicsCommon.h>
// tiny_obj_loader
#define TINYOBJLOADER_IMPLEMENTATION // only define in one file
#include <tiny_obj_loader.h>
// stb_image
#define STB_IMAGE_IMPLEMENTATION // only define in one file
#include <stb_image.h>
//World header file
#include "World.h"
btBroadphaseInterface* broadphase;
btDefaultCollisionConfiguration* collisionConfiguration;
btCollisionDispatcher* dispatcher;
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* dynamicsWorld;
std::vector<btRigidBody*> MovingBits; // so that can get at all bits
std::vector<btRigidBody*> StaticBits; // especially during clean up.
GLuint modelHandle;
GLuint viewHandle;
GLuint projectionHandle;
GLuint lightHandle;
GLuint texHandle;
GLuint program;
glm::vec3 lightDirection = glm::vec3(0.0f, 0.0f, 0.0f);
float zoom = WORLDSIZE * 2;
float theta = 0.0f;
struct Object {
GLuint vao;
GLuint vert_b;
int size;
glm::mat4 model;
GLuint texID;
glm::vec3 position;
};
struct Normal {
glm::vec3 normal;
glm::vec3 direction;
glm::vec2 uv;
};
Object sphere1;
Object sphere2;
Object cube1;
Object boundaryCube;
GLfloat cube_VB[] = {
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
static void error_callback(int error, const char* description) {
fputs(description, stderr);
_fgetchar();
}
GLuint LoadShader(const char * vertex_file_path, const char * fragment_file_path) {
// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
// Read the Vertex Shader code from the file
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
if (VertexShaderStream.is_open()) {
std::string Line = "";
while (getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}
else {
printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
getchar();
return 0;
}
// Read the Fragment Shader code from the file
std::string FragmentShaderCode;
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
if (FragmentShaderStream.is_open()) {
std::string Line = "";
while (getline(FragmentShaderStream, Line))
FragmentShaderCode += "\n" + Line;
FragmentShaderStream.close();
}
GLint Result = GL_FALSE;
int InfoLogLength;
// Compile Vertex Shader
printf("Compiling shader : %s\n", vertex_file_path);
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
glCompileShader(VertexShaderID);
// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if (InfoLogLength > 0) {
std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
printf("%s\n", &VertexShaderErrorMessage[0]);
}
// Compile Fragment Shader
printf("Compiling shader : %s\n", fragment_file_path);
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
glCompileShader(FragmentShaderID);
// Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if (InfoLogLength > 0) {
std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
printf("%s\n", &FragmentShaderErrorMessage[0]);
}
// Link the program
printf("Linking program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
// Check the program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if (InfoLogLength > 0) {
std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
printf("%s\n", &ProgramErrorMessage[0]);
}
glDetachShader(ProgramID, VertexShaderID);
glDetachShader(ProgramID, FragmentShaderID);
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);
return ProgramID;
}
glm::vec2 getPolar(glm::vec3 v){
float r = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
return glm::vec2(atan(v.y / v.x), acos(v.z / r));
}
glm::vec3 getPolarCoordinate(float i, float j) {
float x = cos(i)*sin(j);
float y = sin(i)*sin(j);
float z = cos(j);
return glm::vec3(x, y, z);
}
std::vector<Normal> getNormal(std::vector<glm::vec3> v) {
std::vector<glm::vec3> tempVec;
std::vector<Normal> returnThing;
for (int i = 0; i < v.size(); i += 3) {
tempVec.push_back(normalize(cross(v[i + 1] - v[i], v[i + 2] - v[i])));
tempVec.push_back(normalize(cross(v[i + 1] - v[i], v[i + 2] - v[i])));
tempVec.push_back(normalize(cross(v[i + 1] - v[i], v[i + 2] - v[i])));
}
std::vector<glm::vec2> texCoord;
for (int i = 0; i < v.size(); i++) {
texCoord.push_back(getPolar(v[i]));
}
for (int i = 0; i < v.size(); i++) {
Normal n;
n.direction = v[i];
n.normal = tempVec[i];
n.uv = texCoord[i];
returnThing.push_back(n);
}
return returnThing;
}
std::vector<Normal> generateCube(){
std::vector<glm::vec3> v;
for (int i = 0; i < 36; i++)
v.push_back(glm::vec3(cube_VB[i * 3], cube_VB[i * 3 + 1], cube_VB[i * 3 + 2]));
return getNormal(v);
}
std::vector<Normal> generateSphere(float step) {
std::vector<glm::vec3> sphereVectors;
for (float i = 0; i < glm::radians(360.0f); i += step) {
for (float j = 0; j < glm::radians(360.0f); j += step) {
//Triangle 1
sphereVectors.push_back(getPolarCoordinate(i, j));
sphereVectors.push_back(getPolarCoordinate(i + step, j));
sphereVectors.push_back(getPolarCoordinate(i + step, j + step));
//Triangle 2
sphereVectors.push_back(getPolarCoordinate(i + step, j + step));
sphereVectors.push_back(getPolarCoordinate(i, j + step));
sphereVectors.push_back(getPolarCoordinate(i, j));
}
}
return getNormal(sphereVectors);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
//Close
if ((key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GL_TRUE);
}
//Zoom
if ((key == GLFW_KEY_UP) && action == GLFW_REPEAT || action == GLFW_PRESS) {
if (zoom > 0) {
zoom -= 0.1f;
printf("%f\n", zoom);
}
}
if ((key == GLFW_KEY_DOWN) && action == GLFW_REPEAT || action == GLFW_PRESS) {
zoom += 0.1f;
printf("%f\n", zoom);
}
}
btRigidBody* SetSphere(float size, btTransform T) {
btCollisionShape* fallshape = new btSphereShape(size);
btDefaultMotionState* fallMotionState = new btDefaultMotionState(T);
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
fallshape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, fallshape, fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
fallRigidBody->setLinearVelocity(btVector3(-4, -50, -1));
fallRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(fallRigidBody);
return fallRigidBody;
}
btRigidBody* SetCube(btVector3 size, btTransform T) {
btCollisionShape* fallshape = new btBoxShape(size);
btDefaultMotionState* fallMotionState = new btDefaultMotionState(T);
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
fallshape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, fallshape, fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
fallRigidBody->setLinearVelocity(btVector3(0, -5, 0));
fallRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(fallRigidBody);
return fallRigidBody;
}
void bullet_init() {
//CREATE THE WORLD
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0., GRAVITY, 0));
//GROUND (BOTTOM)
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -WORLDSIZE, 0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
groundRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(groundRigidBody);
//TOP (CEILING)
btCollisionShape* topShape = new btStaticPlaneShape(btVector3(0, -1, 0), 1);
btDefaultMotionState* topMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, WORLDSIZE, 0)));
btRigidBody::btRigidBodyConstructionInfo topRigidBodyCI(0, topMotionState, topShape, btVector3(0, 0, 0));
btRigidBody* topRigidBody = new btRigidBody(topRigidBodyCI);
topRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(topRigidBody);
//BACK
btCollisionShape* backShape = new btStaticPlaneShape(btVector3(1, 0, 0), 1);
btDefaultMotionState* backMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(-WORLDSIZE, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo backRigidBodyCI(0, backMotionState, backShape, btVector3(0, 0, 0));
btRigidBody* backRigidBody = new btRigidBody(backRigidBodyCI);
backRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(backRigidBody);
//FRONT
btCollisionShape* frontShape = new btStaticPlaneShape(btVector3(-1, 0, 0), 1);
btDefaultMotionState* frontMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(WORLDSIZE, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo frontRigidBodyCI(0, frontMotionState, frontShape, btVector3(0, 0, 0));
btRigidBody* frontRigidBody = new btRigidBody(frontRigidBodyCI);
frontRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(frontRigidBody);
//LEFT
btCollisionShape* leftShape = new btStaticPlaneShape(btVector3(0, 0, 1), 1);
btDefaultMotionState* leftMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, -WORLDSIZE)));
btRigidBody::btRigidBodyConstructionInfo leftRigidBodyCI(0, leftMotionState, leftShape, btVector3(0, 0, 0));
btRigidBody* leftRigidBody = new btRigidBody(leftRigidBodyCI);
leftRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(leftRigidBody);
//RIGHT
btCollisionShape* rightShape = new btStaticPlaneShape(btVector3(0, 0, -1), 1);
btDefaultMotionState* rightMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, WORLDSIZE)));
btRigidBody::btRigidBodyConstructionInfo rightRigidBodyCI(0, rightMotionState, rightShape, btVector3(0, 0, 0));
btRigidBody* rightRigidBody = new btRigidBody(rightRigidBodyCI);
rightRigidBody->setRestitution(COE);
dynamicsWorld->addRigidBody(rightRigidBody);
//Sphere1
MovingBits.push_back(SetSphere(1., btTransform(btQuaternion(0, 0, 1, 1), btVector3(0, 0, 0))));
//Sphere2
MovingBits.push_back(SetSphere(1., btTransform(btQuaternion(0, 1, 0, 1), btVector3(0, -3, 0))));
//Cube1
MovingBits.push_back(SetCube(btVector3(1, 1, 1), btTransform(btQuaternion(1, 0, 0, 1), btVector3(0, 5, 0))));
}
glm::vec3 bullet_step(int i) {
btTransform trans;
btRigidBody* moveRigidBody;
int n = MovingBits.size();
moveRigidBody = MovingBits[i];
dynamicsWorld->stepSimulation(1 / 200.f, 10);
//dynamicsWorld->stepSimulation(0.01, 5);
moveRigidBody->getMotionState()->getWorldTransform(trans);
return glm::vec3(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ());
}
void bullet_close() {
/*
* This is very minimal and relies on OS to tidy up.
*/
btRigidBody* moveRigidBody;
moveRigidBody = MovingBits[0];
dynamicsWorld->removeRigidBody(moveRigidBody);
delete moveRigidBody->getMotionState();
delete moveRigidBody;
delete dynamicsWorld;
delete solver;
delete collisionConfiguration;
delete dispatcher;
delete broadphase;
}
Object bufferInit(std::vector<Normal> vp) {
Object myObj;
Normal* v = vp.data();
myObj.size = vp.size();
glGenVertexArrays(1, &myObj.vao);
glBindVertexArray(myObj.vao);
glGenBuffers(1, &myObj.vert_b);
glBindBuffer(GL_ARRAY_BUFFER, myObj.vert_b);
glBufferData(GL_ARRAY_BUFFER, vp.size() * sizeof(struct Normal), v, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(struct Normal), (GLvoid*)offsetof(struct Normal, direction));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(struct Normal), (GLvoid*)offsetof(struct Normal, normal));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(struct Normal), (GLvoid*)offsetof(struct Normal, uv));
glEnableVertexAttribArray(2);
glBindVertexArray(0);
return myObj;
}
void handleInit() {
modelHandle = glGetUniformLocation(program, "model");
viewHandle = glGetUniformLocation(program, "view");
projectionHandle = glGetUniformLocation(program, "projection");
lightHandle = glGetUniformLocation(program, "lightDirection");
texHandle = glGetUniformLocation(program, "tex");
}
void init() {
//Initialise objects
//Sphere object
std::vector<Normal> objectSphere = generateSphere(glm::radians(4.0f));
std::vector<Normal> objectCube = generateCube();
//Spheres and cubes init
sphere1 = bufferInit(objectSphere);
sphere2 = bufferInit(objectSphere);
cube1 = bufferInit(objectCube);
boundaryCube = bufferInit(objectCube);
sphere1.position = glm::vec3(0, 0, 0);
sphere2.position = glm::vec3(0, 0, 0);
cube1.position = glm::vec3(0, 0, 0);
boundaryCube.position= glm::vec3(0, 0, 0);
}
void draw() {
glm::mat4 view = glm::lookAt(glm::vec3(zoom, 0, 0), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
glm::mat4 projection = glm::perspective(glm::radians(90.0f), 16.0f / 9.0f, 0.1f, 100.0f);
glUniformMatrix4fv(viewHandle, 1, GL_FALSE, &view[0][0]);
glUniformMatrix4fv(projectionHandle, 1, GL_FALSE, &projection[0][0]);
glUniform3f(lightHandle, lightDirection.x, lightDirection.y, lightDirection.z);
//use bullet to move shapes
sphere1.position = bullet_step(0);
sphere2.position = bullet_step(1);
cube1.position = bullet_step(2);
//printf("%f\n",sphere1.position.x);
boundaryCube.model = glm::translate(glm::mat4(1), glm::vec3(0, 0, 0)) * glm::rotate(glm::mat4(1), theta, glm::vec3(1, 0, 0)) * glm::scale(glm::mat4(1), glm::vec3(WORLDSIZE*8/10, WORLDSIZE, WORLDSIZE));;
glUniformMatrix4fv(modelHandle, 1, GL_FALSE, &boundaryCube.model[0][0]);
glBindVertexArray(boundaryCube.vao);
glDrawArrays(GL_LINE_LOOP, 0, boundaryCube.size);
glBindVertexArray(0);
glFinish();
sphere1.model = glm::translate(glm::mat4(1), sphere1.position) * glm::rotate(glm::mat4(1), theta, glm::vec3(0, 1, 0));
glUniformMatrix4fv(modelHandle, 1, GL_FALSE, &sphere1.model[0][0]);
glBindVertexArray(sphere1.vao);
glDrawArrays(GL_TRIANGLES, 0, sphere1.size);
glBindVertexArray(0);
glFinish();
sphere2.model = glm::translate(glm::mat4(1), sphere2.position) * glm::rotate(glm::mat4(1), theta, glm::vec3(0, 1, 0));
glUniformMatrix4fv(modelHandle, 1, GL_FALSE, &sphere2.model[0][0]);
glBindVertexArray(sphere2.vao);
glDrawArrays(GL_TRIANGLES, 0, sphere2.size);
glBindVertexArray(0);
glFinish();
cube1.model = glm::translate(glm::mat4(1), cube1.position) * glm::rotate(glm::mat4(1), theta, glm::vec3(0, 1, 0));
glUniformMatrix4fv(modelHandle, 1, GL_FALSE, &cube1.model[0][0]);
glBindVertexArray(cube1.vao);
glDrawArrays(GL_TRIANGLES, 0, cube1.size);
glBindVertexArray(0);
glFinish();
}
int main(){
glfwSetErrorCallback(error_callback);
glfwInit();
GLFWwindow* window;
window = glfwCreateWindow(1920 / 2, 1080 / 2, "Hello", NULL, NULL);
if (!window) {
printf("Failed to open window");
glfwTerminate();
return 0;
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
glewInit();
program = LoadShader("shader.vert", "shader.frag");
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
bullet_init();
handleInit();
init();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_TEXTURE_2D);
glEnable(GL_CULL_FACE);
while (!glfwWindowShouldClose(window)) {
glUseProgram(program);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
bullet_close();
return 0;
}