diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2019-09-17 15:36:26 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2019-09-17 15:36:26 -0400 |
commit | 145d74e433216f8c17475685c553321ca4cbedf3 (patch) | |
tree | 58a06bc92cf13ae9587015cd6b9fc6dd34f919ba | |
parent | 927348d9d8eb16b469c23ef32486bea5f94c5469 (diff) |
text rendering in-place; but something's missing
-rw-r--r-- | Scripts/init.lua | 3 | ||||
-rw-r--r-- | src/engine.cpp | 5 | ||||
-rw-r--r-- | src/render.hpp | 1 | ||||
-rw-r--r-- | src/text.cpp | 23 | ||||
-rw-r--r-- | src/text.hpp | 1 |
5 files changed, 29 insertions, 4 deletions
diff --git a/Scripts/init.lua b/Scripts/init.lua index 65513ec..da9ba14 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -1,4 +1,4 @@ -game.loadFont("freepixel16", "Assets/FreePixel.ttf", 16) +game.loadFont("default", "Assets/FreePixel.ttf", 16) bird = { Player = 0, @@ -9,6 +9,7 @@ bird = { 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 diff --git a/src/engine.cpp b/src/engine.cpp index 70b0b45..703b45e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -58,6 +58,10 @@ int Engine::init(void) [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(); @@ -138,6 +142,7 @@ void Engine::renderLoop(void) { entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */ while (shouldRun()) { + systems.update<TextSystem>(dt); systems.update<RenderSystem>(dt); } } diff --git a/src/render.hpp b/src/render.hpp index d74aca4..3f632f1 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -67,6 +67,7 @@ private: // Map of VBOs and their render data std::map<GLuint, RenderData> renders; + public: RenderSystem() : window(nullptr, SDL_DestroyWindow) {} diff --git a/src/text.cpp b/src/text.cpp index 186907f..1381eb2 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -1,5 +1,7 @@ #include "text.hpp" +#include "events/render.hpp" + #include <iostream> void TextSystem::configure([[maybe_unused]] entityx::EntityManager& entities, @@ -8,16 +10,30 @@ 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, @@ -105,7 +121,8 @@ void TextSystem::put(const std::string& font, 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) diff --git a/src/text.hpp b/src/text.hpp index 8efe3ae..c3479ca 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -91,6 +91,7 @@ private: FT_Library freetype; std::map<std::string, FT_Face> fonts; std::map<std::string, Font> fontData; + bool shouldUpdateVBOs; void updateVBOs(void); }; |