- bird = {
+game.loadFont("default", "Assets/FreePixel.ttf", 16)
+
+ player = {
Player = 0,
EventListeners = {
MoveLeftPressed = function(self)
self.Render.flipx = true;
end,
MoveLeftReleased = function(self)
- self.Velocity.x = self.Velocity.x + 100
+ game.puts("default", self.Position.x, self.Position.y, "Hey.")
+ self.Velocity.x = self.Velocity.x + 3
end,
MoveRightPressed = function(self)
- self.Velocity.x = self.Velocity.x + 100
+ self.Velocity.x = self.Velocity.x + 3
self.Render.flipx = false;
end,
MoveRightReleased = function(self)
void RenderSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
[[maybe_unused]] entityx::EventManager& events)
{
+ events.subscribe<NewRenderEvent>(*this);
+ events.subscribe<WorldMeshUpdateEvent>(*this);
+ events.subscribe<entityx::ComponentAddedEvent<Player>>(*this);
++
init();
}
5*sizeof(float), (void*)(3*sizeof(float)));
glDrawArrays(GL_TRIANGLES, 0, 6);
});
+ glUniform1i(f, 0);
+
+ // If we were given a world VBO render it
+ if (worldVBO) {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, worldTexture);
+ glUniform1i(q, 0);
+
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, worldNormal);
+ glUniform1i(n, 1);
+
+ glBindBuffer(GL_ARRAY_BUFFER, worldVBO);
+ //glBufferData(GL_ARRAY_BUFFER,
+ // wm.size() * sizeof(WorldMeshData),
+ // &wm.front(),
+ // GL_STREAM_DRAW);
- // Update all given VBOs
- for (auto& r : renders) {
+ glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE,
+ 6*sizeof(float), 0);
+ glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE,
+ 6*sizeof(float), (void*)(3*sizeof(float)));
+ glDrawArrays(GL_TRIANGLES, 0, worldVertex);
+ }
+
++ // Update all UI VBOs
++ for (auto& r : uiRenders) {
+ auto& render = r.second;
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, render.tex);
+ glUniform1i(q, 0);
+
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, render.normal);
+ glUniform1i(n, 1);
+
+ glBindBuffer(GL_ARRAY_BUFFER, r.first);
+
+ glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE,
+ 6*sizeof(float), 0);
+ glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE,
+ 6*sizeof(float), (void*)(3*sizeof(float)));
+ glDrawArrays(GL_TRIANGLES, 0, render.vertex);
+ }
+
/*************
* CLEANUP *
*************/
/************
* EVENTS *
************/
- renders.insert_or_assign(nre.vbo,
- RenderData(nre.tex, nre.normal, nre.vertex));
+
+void RenderSystem::receive(const NewRenderEvent &nre)
+{
++ uiRenders.insert_or_assign(nre.vbo,
++ UIRenderData(nre.tex, nre.normal, nre.vertex));
++}
++
+ void RenderSystem::receive(const WorldMeshUpdateEvent &wmu)
+ {
+ worldVBO = wmu.worldVBO;
+ worldVertex = wmu.numVertex;
+ worldTexture = wmu.worldTexture;
+ worldNormal = wmu.worldNormal;
+ }
+
+ void RenderSystem::receive(const entityx::ComponentAddedEvent<Player> &cae)
+ {
+ player = cae.entity;
}
+
#include "shader.hpp"
#include "world.hpp"
++#include "components/Player.hpp"
+#include "events/render.hpp"
#include "events/world.hpp"
-#include "components/Player.hpp"
+#include <map>
+
- struct RenderData
++struct UIRenderData
+{
+ GLuint tex;
+ GLuint normal;
+ unsigned int vertex;
+
- RenderData(GLuint _tex, GLuint _normal, unsigned int _vertex) :
++ UIRenderData(GLuint _tex, GLuint _normal, unsigned int _vertex) :
+ tex(_tex), normal(_normal), vertex(_vertex) {}
+};
class RenderSystem : public entityx::System<RenderSystem>,
public entityx::Receiver<RenderSystem>
Shader worldShader;
glm::vec3 camPos;
- std::map<GLuint, RenderData> renders;
+ // Map of VBOs and their render data
++ std::map<GLuint, UIRenderData> uiRenders;
++
+ GLuint worldVBO = 0;
+ unsigned int worldVertex = 0;
+ GLuint worldTexture = 0;
+ GLuint worldNormal = 0;
+ entityx::Entity player; // Save the player so we can track the camera
+
public:
RenderSystem() :
window(nullptr, SDL_DestroyWindow) {}
/************
* EVENTS *
************/
- //void receive(const WorldMeshUpdateEvent &wmu);
-
+ void receive(const WorldMeshUpdateEvent &wmu);
+ void receive(const NewRenderEvent &nre);
+ void receive(const entityx::ComponentAddedEvent<Player> &cae);
-
};
#endif // SYSTEM_RENDER_HPP_