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.colors.size() < buf.vertices.size()) {
15 std::cerr << "EntityModel: not enough colors!" << std::endl;
17 if (buf.normals.size() < buf.vertices.size()) {
18 std::cerr << "EntityModel: not enough normals!" << std::endl;
23 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
24 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
25 vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
26 vao.PushIndices(ATTRIB_INDEX, buf.indices);
30 void EntityModel::Draw() const noexcept {
31 vao.DrawTriangleElements();
35 void BlockModel::Update(const Buffer &buf) noexcept {
37 if (buf.colors.size() < buf.vertices.size()) {
38 std::cerr << "BlockModel: not enough colors!" << std::endl;
40 if (buf.lights.size() < buf.vertices.size()) {
41 std::cerr << "BlockModel: not enough lights!" << std::endl;
46 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
47 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
48 vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
49 vao.PushIndices(ATTRIB_INDEX, buf.indices);
53 void BlockModel::Draw() const noexcept {
54 vao.DrawTriangleElements();
58 void OutlineModel::Update(const Buffer &buf) noexcept {
60 if (buf.colors.size() < buf.vertices.size()) {
61 std::cerr << "OutlineModel: not enough colors!" << std::endl;
66 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
67 vao.PushAttribute(ATTRIB_COLOR, buf.colors);
68 vao.PushIndices(ATTRIB_INDEX, buf.indices);
72 void OutlineModel::Draw() noexcept {
73 glEnable(GL_LINE_SMOOTH);
75 vao.DrawLineElements();
79 void SpriteModel::Buffer::LoadRect(
81 const glm::vec2 &pivot,
82 const glm::vec2 &tex_begin,
83 const glm::vec2 &tex_end
88 vertices.emplace_back( -pivot.x, -pivot.y, 0.0f);
89 vertices.emplace_back(w-pivot.x, -pivot.y, 0.0f);
90 vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
91 vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
93 coords.emplace_back(tex_begin.x, tex_begin.y);
94 coords.emplace_back(tex_end.x, tex_begin.y);
95 coords.emplace_back(tex_begin.x, tex_end.y);
96 coords.emplace_back(tex_end.x, tex_end.y);
98 indices.assign({ 0, 2, 1, 1, 2, 3 });
102 void SpriteModel::Update(const Buffer &buf) noexcept {
104 if (buf.coords.size() < buf.vertices.size()) {
105 std::cerr << "SpriteModel: not enough coords!" << std::endl;
110 vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
111 vao.PushAttribute(ATTRIB_TEXCOORD, buf.coords);
112 vao.PushIndices(ATTRIB_INDEX, buf.indices);
116 void SpriteModel::Draw() noexcept {
117 vao.DrawTriangleElements();