-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.cpp
81 lines (59 loc) · 2.08 KB
/
box.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
#include <gl_shared.hpp>
#include <glfw_app.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glog/logging.h>
#include <shader.hpp>
#include <box.hpp>
using namespace gl;
using namespace glm;
int main(int argc, char** argv) {
const char* shader_path = getenv("SHADER_PATH");
if (shader_path)
{
shader::setdir(shader_path);
}
else
{
LOG(FATAL) << "missing SHADER_PATH environment variable";
}
glfw_app gltest;
{
// gl objects --------------------------------------------------------------------
glEnable(GL_DEPTH_TEST); // always
box b;
shader draw ("mesh/basic3d", "mesh/hsv3d");
draw.use();
b.init();
int w = 0, h = 0;
glClearColor(1.0, 1.0, 1.0, 1.0);
// callbacks ---------------------------------------------------------------------
gltest.set_fbsize_proc([&w, &h](int width, int height) {
w = width;
h = height;
glViewport(0, 0, width, height);
});
gltest.set_cursor_proc([&](double x, double y) {
float xnorm = x / w;
float ynorm = y / h;
draw.u2f("mouse", glm::vec2(xnorm, ynorm));
});
gltest.onkey('R', [&draw] () { draw.reload(); });
// run, with "frame" callback ----------------------------------------------------
gltest.run([&] {
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
draw.use();
mat4 model (1.0);
model = rotate(model, (float)glfwGetTime() * radians(10.0f), vec3(0.0f, 1.0f, 0.0f));
model = scale(model, vec3(0.5, 0.5, 0.5));
mat4 view = lookAt(vec3(1.2f, 1.2f, 1.2f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
mat4 proj = perspective(radians(55.0f), (float) w / (float) h, 0.10f, 10.0f);
draw.use();
draw.u44m("model", model);
draw.u44m("view", view);
draw.u44m("proj", proj);
draw.u1f("time", glfwGetTime());
b.draw();
});
}
return 0;
}