]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
World can now draw
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Sat, 14 Sep 2019 07:31:40 +0000 (03:31 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Sat, 14 Sep 2019 07:31:40 +0000 (03:31 -0400)
Assets/world_normal.png
Scripts/world.lua
src/engine.cpp
src/render.cpp
src/render.hpp
src/script.hpp
src/world.hpp

index d45512a006582b7169bbddd10e2e94b4d28d16db..e5f013c2f40a4ef5c2470681892b53991c27e737 100644 (file)
Binary files a/Assets/world_normal.png and b/Assets/world_normal.png differ
index 246ece0de4accbe810fd482f31b31b6e2279af3b..6a526ddfbd6479b288392112702c94ab6b67f709 100644 (file)
@@ -72,13 +72,10 @@ world = {
                 YDepth = math.random(2,5)
                 for Y = 0,ysize-1 do
                     if Y == YGen then
-                        --self.data[Z][X][Y] = 0
                         self:setData(X, Y, Z, "grass");
                     elseif Y < YGen and Y > (YGen - YDepth) then
-                        --self.data[Z][X][Y] = 1
                         self:setData(X, Y, Z, "dirt");
                     elseif Y < YGen then
-                        --self.data[Z][X][Y] = 2
                         self:setData(X, Y, Z, "stone");
                     end
                     --print(X..","..Y..","..Z);
index 6e6a0e56ced7fa5d53fb1d46715a41c2523b1a2b..191493e8bfdb96f6e889d070ce4bd5e4dc7e63bb 100644 (file)
@@ -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();
index ceef025127081e13b798f05a2d950b89f90e74d4..5efccce4864cd3f9f381ce5e1369e139cbd185b9 100644 (file)
@@ -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;
 }
index 8dcb4349d9ca9f9eb77dbf1c3a8284cc27acd45b..82ca844d8134e3ce041f548501821be098bc3dac 100644 (file)
@@ -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)
     {
index 5c4c78011efacff1f7310cd52559dcdf731b229a..87027d58ae8c74c09fb05ac75bee1391b536386e 100644 (file)
@@ -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:
index 81e5b9d46ac9892dbadc9d95024084121f8b8606..5933306f47ba3bcfe2fc62b2e6b73199274df2ba 100644 (file)
@@ -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();