-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·94 lines (71 loc) · 2.27 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·94 lines (71 loc) · 2.27 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
91
92
93
94
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#if defined(__APPLE__)
#include <Opengl/gl.h>
#define GL_SILENCE_DEPRECATION
#else
#include <GL/gl.h>
#endif
#include "src/graphics/shader.hpp"
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include "src/renderer/displaymanager.hpp"
#include "src/renderer/loader.hpp"
#include "src/renderer/renderer.hpp"
#include "src/math/mat4.hpp"
#include "src/math/quaternion.hpp"
using namespace std;
int main(int argc, const char *argv[]) {
DisplayManager &window = DisplayManager::instance();
std::vector<float> vertices{
-100.0f, 100.0f, 0.0f,
-100.0f, -100.0f, 0.0f,
100.0f, -100.0f, 0.0f,
100.0f, 100.0f, 0.0f};
std::vector<unsigned int> indices{
0, 1, 3,
3, 1, 2};
Loader loader;
Renderer renderer;
RawModel model = loader.loadToVAO(vertices, indices);
Mat4 Projection = Mat4::ortho(0.0f, 640.0f, 0.0f, 480.0f, -1.0f, 1.0f);
Mat4 View = Mat4::translate({-200.0f, 0.0f, 0.0f});
Mat4 ModelTranslation = Mat4::translate({500.0f, 200.0f, 0.0f});
Mat4 ModelRotation = Mat4::rotate({0.0f, {0.0f, 0.0f, 1.0f}});
Mat4 ModelScale = Mat4::scale({1.0f, 1.0f, 1.0f});
Mat4 Model = ModelTranslation * ModelRotation * ModelScale;
Mat4 MVP = Projection * View * Model;
Shader shader("res/shaders/main.vert", "res/shaders/main.frag");
shader.use();
shader.setUniformMat4("MVP", MVP);
float angle = 0.0f;
float lastTime = glfwGetTime();
int nbFrames = 0;
/* Loop until the user closes the window */
while (!window.isCloseRequested()) {
/* Render prepare */
renderer.prepare();
/* Render here */
ModelRotation = Mat4::rotate(Quaternion::angle_axis(angle, {0.0f, 0.0f, 1.0f}));
Model = ModelTranslation * ModelRotation * ModelScale;
MVP = Projection * View * Model;
shader.setUniformMat4("MVP", MVP);
renderer.render(model);
/* Update window */
window.update();
angle += 0.1f;
double currentTime = glfwGetTime();
nbFrames++;
if (currentTime - lastTime >= 1.0) { // If last prinf() was more than 1 sec ago
// printf and reset timer
printf("FPS: %d - %f ms/frame\n", nbFrames, 1000.0 / double(nbFrames));
nbFrames = 0;
lastTime += 1.0;
}
}
window.close();
return 0;
}