Repository navigation
Expand file tree
/
Copy pathtopViewScreenQuad.cpp
More file actions
58 lines (52 loc) · 1.81 KB
/
Copy pathtopViewScreenQuad.cpp
File metadata and controls
58 lines (52 loc) · 1.81 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
#include "topViewScreenQuad.hpp"
#include "glDebug.hpp"
TopViewScreenQuad::TopViewScreenQuad(Framebuffer *fb)
: Drawable("shaders/framebufferVertexShader.glsl", "shaders/framebufferFragmentShader.glsl")
, fb(fb) {
SetBuffer();
shader.Uniform1i("screenTexture", 1);
}
void TopViewScreenQuad::SetBuffer() {
BindVbo();
SetBufferData();
SetBufferAttributes();
UnbindVbo();
}
void TopViewScreenQuad::SetBufferData() {
float screenRatio = (float)Window::width / (float)Window::height;
float topViewXsize = 0.6f;
float topViewYsize = ((topViewXsize * fb->GetResHeight()) /
(float)fb->GetResWidth()) * screenRatio;
GLfloat topViewQuad[] {
-1 + topViewXsize, 1.0f, 0.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, 1 - topViewYsize, 0.0f, 0.0f, 0.0f,
-1.0f, 1 - topViewYsize, 0.0f, 0.0f, 0.0f,
-1 + topViewXsize, 1 - topViewYsize, 0.0f, 1.0f, 0.0f,
-1 + topViewXsize, 1.0f, 0.0f, 1.0f, 1.0f
};
GL_CHECK(glBufferData(
GL_ARRAY_BUFFER,
sizeof(topViewQuad),
&topViewQuad,
GL_STATIC_DRAW
));
}
void TopViewScreenQuad::SetBufferAttributes() {
BindVao();
GL_CHECK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0));
GL_CHECK(glEnableVertexAttribArray(0));
GL_CHECK(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat),
(GLvoid*)(3 * sizeof(GLfloat))));
GL_CHECK(glEnableVertexAttribArray(1));
UnbindVao();
}
void TopViewScreenQuad::Draw() {
shader.Use();
GL_CHECK(glDisable(GL_DEPTH_TEST));
BindVao();
GL_CHECK(glActiveTexture(GL_TEXTURE1));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, fb->GetColorTexture()));
GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, 6));
UnbindVao();
}