1 #include "BlockModel.hpp"
2 #include "EntityModel.hpp"
3 #include "OutlineModel.hpp"
4 #include "SpriteModel.hpp"
12 void EntityModel::Update(const Buffer &buf) noexcept {
14 if (buf.tex_coords.size() < buf.vertices.size()) {
15 std::cerr << "EntityModel: not enough tex coords!" << std::endl;
17 if (buf.colors.size() < buf.vertices.size()) {
18 std::cerr << "EntityModel: not enough colors!" << std::endl;
20 if (buf.normals.size() < buf.vertices.size()) {
21 std::cerr << "EntityModel: not enough normals!" << std::endl;
26 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
27 vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
28 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
29 vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
30 vao.PushIndices(ATTRIB_INDEX, buf.indices);
34 void EntityModel::Draw() const noexcept {
35 vao.DrawTriangleElements();
39 void BlockModel::Update(const Buffer &buf) noexcept {
41 if (buf.tex_coords.size() < buf.vertices.size()) {
42 std::cerr << "BlockModel: not enough tex coords!" << std::endl;
44 if (buf.colors.size() < buf.vertices.size()) {
45 std::cerr << "BlockModel: not enough colors!" << std::endl;
47 if (buf.lights.size() < buf.vertices.size()) {
48 std::cerr << "BlockModel: not enough lights!" << std::endl;
53 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
54 vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
55 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
56 vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
57 vao.PushIndices(ATTRIB_INDEX, buf.indices);
61 void BlockModel::Draw() const noexcept {
62 vao.DrawTriangleElements();
66 void OutlineModel::Update(const Buffer &buf) noexcept {
68 if (buf.colors.size() < buf.vertices.size()) {
69 std::cerr << "OutlineModel: not enough colors!" << std::endl;
74 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
75 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
76 vao.PushIndices(ATTRIB_INDEX, buf.indices);
80 void OutlineModel::Draw() noexcept {
81 glEnable(GL_LINE_SMOOTH);
83 vao.DrawLineElements();
87 void SpriteModel::Buffer::LoadRect(
89 const glm::vec2 &pivot,
90 const glm::vec2 &tex_begin,
91 const glm::vec2 &tex_end
96 vertices.emplace_back( -pivot.x, -pivot.y, 0.0f);
97 vertices.emplace_back(w-pivot.x, -pivot.y, 0.0f);
98 vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
99 vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
101 coords.emplace_back(tex_begin.x, tex_begin.y);
102 coords.emplace_back(tex_end.x, tex_begin.y);
103 coords.emplace_back(tex_begin.x, tex_end.y);
104 coords.emplace_back(tex_end.x, tex_end.y);
106 indices.assign({ 0, 2, 1, 1, 2, 3 });
110 void SpriteModel::Update(const Buffer &buf) noexcept {
112 if (buf.coords.size() < buf.vertices.size()) {
113 std::cerr << "SpriteModel: not enough coords!" << std::endl;
118 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
119 vao.PushAttribute(ATTRIB_TEXCOORD, buf.coords);
120 vao.PushIndices(ATTRIB_INDEX, buf.indices);
124 void SpriteModel::Draw() noexcept {
125 vao.DrawTriangleElements();