-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasciiGL.hpp
95 lines (76 loc) · 2.29 KB
/
asciiGL.hpp
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
#include <vector>
#include <array>
#include <memory>
#include <ncurses.h>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat3x3.hpp>
#include <glm/mat4x4.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/scalar_constants.hpp>
namespace asciiGL {
struct Pixel {
char character;
int color;
Pixel(char ch, int col);
Pixel(char ch);
};
struct VertexInformation {
glm::vec3 position;
virtual VertexInformation * interpolate(VertexInformation * to, float amount);
bool inBounds();
};
class FragmentShaderSettings {
//light positions and such
};
class FragmentShader {
FragmentShaderSettings& settings;
public:
FragmentShader(FragmentShaderSettings& s);
virtual ~FragmentShader();
virtual Pixel compute(VertexInformation* input);
};
class VertexShaderSettings {
//transforms and the like
};
class VertexShader {
VertexShaderSettings& settings;
public:
VertexShader(VertexShaderSettings & s);
virtual ~VertexShader();
virtual VertexInformation* compute(VertexInformation* v);
};
template<typename T>
struct Buffer2D {
std::vector<std::vector<T>> buffer;
Buffer2D();
Buffer2D(int w, int h, T fill);
T& at(int x, int y);
void clear();
void fill(T element);
};
typedef std::array<VertexInformation*, 3> Triangle;
class Renderer {
std::vector<Triangle> triangles;
Buffer2D<Pixel> frameBuffer;
Buffer2D<float> depthBuffer;
int width;
int height;
VertexShader& vertexShader;
FragmentShader& fragmentShader;
std::vector<VertexInformation*> rasterize(Triangle tri);
glm::vec3 toScreenPos(glm::vec3 p);
glm::vec2 toScreenPos(glm::vec2 p);
bool depthTest(VertexInformation*);
void rasterFlatTopTri(VertexInformation * point, VertexInformation * left, VertexInformation * right);
void rasterFlatBottomTri(VertexInformation * point, VertexInformation * left, VertexInformation * right);
public:
Renderer();
Renderer(VertexShader& vs, FragmentShader& fs);
Renderer(int width, int height, VertexShader& vs, FragmentShader& fs);
void setTriangles(std::vector<Triangle> tris);
void render();
void pushFrame();//after successive render calls
};
};