aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-14 03:31:40 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-14 03:31:40 -0400
commit534f6f57e930020eb1ad726f4de4e90cf487e584 (patch)
tree0dedd0deaa7556e6f9e8fd316017413f59de7996 /src
parent4bf539d953871dbddddcc00275ffdcaddece5091 (diff)
World can now draw
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp2
-rw-r--r--src/render.cpp26
-rw-r--r--src/render.hpp7
-rw-r--r--src/script.hpp2
-rw-r--r--src/world.hpp6
5 files changed, 37 insertions, 6 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 6e6a0e5..191493e 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -44,8 +44,8 @@ int Engine::init(void)
systems.add<GameRunSystem>();
systems.add<InputSystem>();
systems.add<PlayerSystem>(entities);
- systems.add<RenderSystem>();
systems.add<WorldSystem>();
+ systems.add<RenderSystem>(*(systems.system<WorldSystem>().get()));
systems.add<ScriptSystem>(entities, *(systems.system<WorldSystem>().get()));
systems.add<PhysicsSystem>();
systems.configure();
diff --git a/src/render.cpp b/src/render.cpp
index ceef025..5efccce 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -69,7 +69,7 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
);
glm::mat4 model = glm::mat4(1.0f);
- model = glm::scale(model, glm::vec3(2.0f));
+ model = glm::scale(model, glm::vec3(8.0f));
glUseProgram(s);
@@ -178,7 +178,28 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
5*sizeof(float), (void*)(3*sizeof(float)));
glDrawArrays(GL_TRIANGLES, 0, 6);
});
-
+
+ std::basic_string<WorldMeshData>& wm = worldSystem.current()->getMesh();
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, worldSystem.current()->getTexture());
+ glUniform1i(q, 0);
+
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, worldSystem.current()->getNormal());
+ glUniform1i(n, 1);
+
+ glBindBuffer(GL_ARRAY_BUFFER, world_vbo);
+ glBufferData(GL_ARRAY_BUFFER,
+ wm.size() * sizeof(WorldMeshData),
+ &wm.front(),
+ GL_STREAM_DRAW);
+
+ 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, wm.size());
/*************
* CLEANUP *
@@ -262,6 +283,7 @@ int RenderSystem::init(void)
//glClearColor(0.6, 0.8, 1.0, 0.0);
camPos = glm::vec3(0.0f, 0.0f, 0.5f);
+ glGenBuffers(1, &world_vbo);
return 0;
}
diff --git a/src/render.hpp b/src/render.hpp
index 8dcb434..82ca844 100644
--- a/src/render.hpp
+++ b/src/render.hpp
@@ -35,6 +35,7 @@
#include <glm/gtc/noise.hpp>
#include "shader.hpp"
+#include "world.hpp"
class RenderSystem : public entityx::System<RenderSystem>
{
@@ -48,10 +49,12 @@ private:
Shader worldShader;
glm::vec3 camPos;
+ GLuint world_vbo;
+ WorldSystem &worldSystem;
public:
- RenderSystem(void) :
- window(nullptr, SDL_DestroyWindow) {}
+ RenderSystem(WorldSystem & _ws) :
+ window(nullptr, SDL_DestroyWindow), worldSystem(_ws) {}
~RenderSystem(void)
{
diff --git a/src/script.hpp b/src/script.hpp
index 5c4c780..87027d5 100644
--- a/src/script.hpp
+++ b/src/script.hpp
@@ -50,6 +50,8 @@ private:
entityx::EntityManager& manager;
+ // TODO possibly emit events to spawn worlds instead of passing the
+ // world system around like a toy
WorldSystem &worldSystem;
public:
diff --git a/src/world.hpp b/src/world.hpp
index 81e5b9d..5933306 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -33,7 +33,7 @@ struct WorldMeshData
float posX, posY, posZ;
float texX, texY;
float transparency;
-};
+}__attribute__((packed));
struct WorldMaterial
{
@@ -100,6 +100,9 @@ public:
/* RENDERING */
void generateMesh();
+ std::basic_string<WorldMeshData>& getMesh() {return mesh;}
+ GLuint getTexture() {return registry.at(0).texture.tex;}
+ GLuint getNormal() {return registry.at(0).normal.tex;};
/* SEED */
unsigned int getSeed();
@@ -125,6 +128,7 @@ public:
}
World* addWorld(sol::object);
+ World* current() {return currentWorld;};
void cleanup()
{
worlds.clear();