-
Notifications
You must be signed in to change notification settings - Fork 0
/
ourGL.h
65 lines (50 loc) · 1.95 KB
/
ourGL.h
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
#ifndef __OURGL_H__
#define __OURGL_H__
#include <array>
#include "geometry.h"
#include "model.h"
/**
* match unit square onto the image with width and height.
* you can read this get more: https://github.com/ssloy/tinyrenderer/wiki/Lesson-5-Moving-the-camera
*/
void viewport(const int x, const int y, const int w, const int h);
/**
* generate perpective projection, the coaff is the -1/c
* reference: https://github.com/ssloy/tinyrenderer/wiki/Lesson-4-Perspective-projection
*/
void projection(const float coeff = 0.0);
/**
* transform model which is in world coordinates into camera(eye) coordinats
* @param eye the camera(eye) location in world
* @param center the lens centric position
* @param up the camera up directory
* you can get more from this: https://github.com/ssloy/tinyrenderer/wiki/Lesson-5-Moving-the-camera
*/
void lookat(const vec3f& eye, const vec3f& center, const vec3f& up);
class Shader
{
public:
/**
* Vertex shader, it will return the coordinates appeared in screnn before perspective.
* @param iface nth face in mesh
* @param nthvert the nth vertex in face
* @return the coordinates appeared in screnn before perspective
*/
virtual vec4f vertex(const int iface, const int nthvert) = 0;
/**
* Calculating pixel color with barycentric coordinates
* @param bar the barycentric coordinates with triangle, you'd better let it keep original
* @param color the color of pixel will be returned if we don't it
* @return if we discard this pixle, true: Yes, false: No
*/
virtual bool fragment(const vec3f& bar, TGAColor& color) = 0;
};
/**
* rasterize triangle
* @param clipVerts the vertex of triangle without perspective
* @param shader shader the vertex and pixel
* @param image the image will be output
* @param zBuffer zBuffer about removeable pixel
*/
void triangle(const std::array<vec4f, 3>& clipVerts, Shader& shader, TGAImage& image, std::vector<float>& zBuffer);
#endif