-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (77 loc) · 2.32 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (77 loc) · 2.32 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
#include<iostream>
#include<vector>
#include<algorithm>
#include<Eigen/Core>
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include"Tooldev.h"
#include"Triangle.h"
#include"Pixel.h"
#include"Poly.h"
#include"GLWindow.h"
using namespace Eigen;
class Triangle_Index {
public:
Triangle_Index(size_t ip1,size_t ip2,size_t ip3):p1_idx(ip1),p2_idx(ip2),p3_idx(ip3) {}
std::vector<size_t> get_tIndex() {
std::vector<size_t> t_idxs;
t_idxs.resize(3);
t_idxs[0] = p1_idx;
t_idxs[1] = p2_idx;
t_idxs[2] = p3_idx;
return t_idxs;
}
private:
size_t p1_idx;
size_t p2_idx;
size_t p3_idx;
};
#define WIDTH 512.0f
#define HEIGHT 512.0f
#define FOV 60.0f
#define NEARF 1.0f
#define FARF 100.0f
int main() {
LOG_INFO("===============Begin===============");
GLWindow gwindow1(WIDTH,HEIGHT,"Snow's Screen");
std::vector<Pixel> framebuffer(WIDTH * HEIGHT);
std::vector<float> depthbuffer(WIDTH * HEIGHT);
Vector3f cam(0, 0, 5);
Vector3f tar(0, 0, 0);
Vector3f up(0, 1, 0);
Matrix4f mat_VP = getmatr_VP(FOV, WIDTH, HEIGHT, NEARF, FARF, cam, tar, up);
LOG_INFO("Creat a Triangle");
// test ...
std::vector<Vertex> points = {
Vertex(-1.0f, -1.0f, -1.0f, "red"),
// 1: 前下右
Vertex(1.0f, -1.0f, -1.0f, "green"),
// 2: 前上右
Vertex(1.0f, 1.0f, -1.0f, "blue"),
// 3: 前上左
Vertex(-1.0f, 1.0f, -1.0f, "yellow"),
// 4: 后下左
Vertex(-1.0f, -1.0f, -3.0f, "cyan"),
// 5: 后下右
Vertex(1.0f, -1.0f, -3.0f, "magenta"),
// 6: 后上右
Vertex(1.0f, 1.0f, -3.0f, "white"),
// 7: 后上左
Vertex(-1.0f, 1.0f, -3.0f, "gray")
};
Poly p(points);
const Pixel& background_black = Pixel::create_black();
LOG_INFO("Init done");
LOG_INFO("Start the render loop");
LOG_INFO("Start to draw : Triangle ...");
while (!gwindow1.shouldClose()) {
for (auto& px : framebuffer) {
px.depth = 1e9;
}
std::fill(framebuffer.begin(), framebuffer.end(), background_black);
LOG_INFO("Drawing ...");
p.draw(mat_VP, framebuffer);
gwindow1.update(framebuffer);
}
LOG_INFO("===============end===============");
}