-game.loadFont("freepixel16", "Assets/FreePixel.ttf", 16)
+game.loadFont("default", "Assets/FreePixel.ttf", 16)
bird = {
Player = 0,
end,
MoveLeftReleased = function(self)
self.Velocity.x = self.Velocity.x + 100
+ game.puts("default", self.Position.x, self.Position.y, "Hey.")
end,
MoveRightPressed = function(self)
self.Velocity.x = self.Velocity.x + 100
[this](std::string name, std::string file, int size) {
systems.system<TextSystem>().get()->loadFont(name, file, size);
});
+ script->addToGameNamespace("puts",
+ [this](std::string name, float x, float y, std::string text) {
+ systems.system<TextSystem>().get()->put(name, x, y, text);
+ });
script->init();
{
entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */
while (shouldRun()) {
+ systems.update<TextSystem>(dt);
systems.update<RenderSystem>(dt);
}
}
// Map of VBOs and their render data
std::map<GLuint, RenderData> renders;
+
public:
RenderSystem() :
window(nullptr, SDL_DestroyWindow) {}
#include "text.hpp"
+#include "events/render.hpp"
+
#include <iostream>
void TextSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
if (FT_Init_FreeType(&freetype) != 0) {
// TODO handle error
}
+
+ shouldUpdateVBOs = false;
}
/**
* Draws the text for all entities.
*/
void TextSystem::update([[maybe_unused]] entityx::EntityManager& entites,
- [[maybe_unused]] entityx::EventManager& events,
+ entityx::EventManager& events,
[[maybe_unused]] entityx::TimeDelta dt)
{
- // TODO render each Text component's text
+ if (shouldUpdateVBOs) {
+ shouldUpdateVBOs = false;
+ updateVBOs();
+
+ for (auto& data : fontData) {
+ auto& d = data.second;
+ if (d.text.size() == 0)
+ continue;
+
+ // TODO make normal
+ events.emit<NewRenderEvent>(d.vbo, d.tex, 0, d.buffer.size());
+ }
+ }
}
void TextSystem::loadFont(const std::string& name,
if (fontData.find(font) == fontData.end())
return;
- fontData[font].text.emplace_back(text, x, y);
+ fontData[font].text.emplace_back(text, x, y, -9.0f);
+ shouldUpdateVBOs = true;
}
void TextSystem::updateVBOs(void)
FT_Library freetype;
std::map<std::string, FT_Face> fonts;
std::map<std::string, Font> fontData;
+ bool shouldUpdateVBOs;
void updateVBOs(void);
};