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);
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();
);
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);
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 *
//glClearColor(0.6, 0.8, 1.0, 0.0);
camPos = glm::vec3(0.0f, 0.0f, 0.5f);
+ glGenBuffers(1, &world_vbo);
return 0;
}
#include <glm/gtc/noise.hpp>
#include "shader.hpp"
+#include "world.hpp"
class RenderSystem : public entityx::System<RenderSystem>
{
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)
{
entityx::EntityManager& manager;
+ // TODO possibly emit events to spawn worlds instead of passing the
+ // world system around like a toy
WorldSystem &worldSystem;
public:
float posX, posY, posZ;
float texX, texY;
float transparency;
-};
+}__attribute__((packed));
struct WorldMaterial
{
/* 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();
}
World* addWorld(sol::object);
+ World* current() {return currentWorld;};
void cleanup()
{
worlds.clear();