-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackgroundObject.hpp
69 lines (56 loc) · 1.56 KB
/
BackgroundObject.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
#pragma once
#include "Camera.hpp"
#include "Shader.hpp"
#include "ShaderProgram.hpp"
#include "VertexArray.hpp"
#include "ShaderBuffer.hpp"
#include "ShaderAttrib.hpp"
#include "Texture.hpp"
#include "Tuple.hpp"
struct BackgroundObject {
gl::ShaderProgram<
gl::VertexShader,
gl::FragmentShader
> program;
gl::Buffer<GL_ARRAY_BUFFER, gl::BufferElementType::VEC2> buf;
gl::Attrib<decltype(buf)> attrVertex;
gl::VertexArray<decltype(attrVertex)> vao;
using ShaderProgram = decltype(program);
using ShaderBuffer = decltype(buf);
using ShaderAttrib = decltype(attrVertex);
using VertexArray = decltype(vao);
BackgroundObject(const std::string &dir):
program({
sys::Path(dir) / sys::Path("shaders"s) / sys::Path("bg.vert"s),
sys::Path(dir) / sys::Path("shaders"s) / sys::Path("bg.frag"s)
}),
attrVertex("vertex"s, buf),
vao(attrVertex)
{}
void init() {
ShaderBuffer::init(buf);
buf.allocate<GL_STREAM_DRAW>(std::vector<float>{
-1,-1, 1,-1, 1,1,
1,1, -1,1, -1,-1,
});
VertexArray::init(vao);
VertexArray::bind(vao);
vao.enable(attrVertex);
vao.set_access(attrVertex, 0);
VertexArray::unbind();
ShaderProgram::init(program, vao);
}
void display(Camera &cam) {
ShaderProgram::use(program);
VertexArray::bind(vao);
VertexArray::draw<GL_TRIANGLES>(vao);
VertexArray::unbind();
ShaderProgram::unuse();
}
void clear() {
ShaderAttrib::clear(attrVertex);
ShaderBuffer::clear(buf);
VertexArray::clear(vao);
ShaderProgram::clear(program);
}
};