-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quad.h
88 lines (81 loc) · 3.01 KB
/
Quad.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include "ggl.h"
#include "Shader.h"
#include "VertexBuffer.h"
class Quad
{
public:
VertexBuffer* mVertexBuffer;
Shader* mShader;
public:
void Init() {
mVertexBuffer = new VertexBuffer;
mVertexBuffer->Init(4);
mVertexBuffer->SetTexcoord(0, 0.0f, 0.0f);
mVertexBuffer->SetTexcoord(1, 1.0f, 0.0f);
mVertexBuffer->SetTexcoord(2, 0.0f, 1.0f);
mVertexBuffer->SetTexcoord(3, 1.0f, 1.0f);
mShader = new Shader;
}
void Render() {
glm::mat4 identity = glm::mat4(1.0f);
mVertexBuffer->SetPosition(0, -1.0f, -1.0f, 0.0f);
mVertexBuffer->SetPosition(1, 1.0f, -1.0f, 0.0f);
mVertexBuffer->SetPosition(2, -1.0f, 1.0f, 0.0f);
mVertexBuffer->SetPosition(3, 1.0f, 1.0f, 0.0f);
mVertexBuffer->Bind();
mShader->Bind(identity, identity, identity);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
mVertexBuffer->Unbind();
}
void DepthBuffer() {
mShader->SetBool("bDepth", true);
}
void ColorBuffer() {
mShader->SetBool("bDepth", false);
}
void RenderToLeftTop() {
glm::mat4 identity = glm::mat4(1.0f);
mVertexBuffer->SetPosition(0, -1.0f, 0.0f, -1.0f);
mVertexBuffer->SetPosition(1, 0.0f, 0.0f, -1.0f);
mVertexBuffer->SetPosition(2, -1.0f, 1.0f, -1.0f);
mVertexBuffer->SetPosition(3, 0.0f, 1.0f, -1.0f);
mVertexBuffer->Bind();
mShader->Bind(glm::value_ptr(identity), glm::value_ptr(identity), glm::value_ptr(identity));
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
mVertexBuffer->Unbind();
}
void RenderToRightTop() {
glm::mat4 identity = glm::mat4(1.0f);
mVertexBuffer->SetPosition(0, 0.0f, 0.0f, -1.0f);
mVertexBuffer->SetPosition(1, 1.0f, 0.0f, -1.0f);
mVertexBuffer->SetPosition(2, 0.0f, 1.0f, -1.0f);
mVertexBuffer->SetPosition(3, 1.0f, 1.0f, -1.0f);
mVertexBuffer->Bind();
mShader->Bind(identity, identity, identity);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
mVertexBuffer->Unbind();
}
void RenderToLeftBottom() {
glm::mat4 identity = glm::mat4(1.0f);
mVertexBuffer->SetPosition(0, -1.0f, -1.0f, -1.0f);
mVertexBuffer->SetPosition(1, 0.0f, -1.0f, -1.0f);
mVertexBuffer->SetPosition(2, -1.0f, 0.0f, -1.0f);
mVertexBuffer->SetPosition(3, 0.0f, 0.0f, -1.0f);
mVertexBuffer->Bind();
mShader->Bind(identity, identity, identity);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
mVertexBuffer->Unbind();
}
void RenderToRightBottom() {
glm::mat4 identity = glm::mat4(1.0f);
mVertexBuffer->SetPosition(0, 0.0f, -1.0f, -1.0f);
mVertexBuffer->SetPosition(1, 1.0f, -1.0f, -1.0f);
mVertexBuffer->SetPosition(2, 0.0f, 0.0f, -1.0f);
mVertexBuffer->SetPosition(3, 1.0f, 0.0f, -1.0f);
mVertexBuffer->Bind();
mShader->Bind(identity, identity, identity);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
mVertexBuffer->Unbind();
}
};