Bläddra i källkod

shader tests, chunk / world rendering tests

Kajetan Johannes Hammerle 5 år sedan
förälder
incheckning
e9ab0262bd
13 ändrade filer med 261 tillägg och 166 borttagningar
  1. 4 1
      Makefile
  2. 17 8
      client/Client.cpp
  3. 4 2
      client/Client.h
  4. 4 4
      engine/Mesh.cpp
  5. 6 1
      engine/Mesh.h
  6. 17 1
      engine/Wrapper.cpp
  7. 4 0
      engine/Wrapper.h
  8. 3 30
      shader/postFragment.fs
  9. 2 2
      shader/vertex.vs
  10. 136 114
      world/Chunk.cpp
  11. 2 3
      world/Chunk.h
  12. 39 0
      world/World.cpp
  13. 23 0
      world/World.h

+ 4 - 1
Makefile

@@ -11,7 +11,7 @@ game_client: MainClient.cpp\
 	Clock.o DirectRenderer.o KeyManager.o Mesh.o MouseManager.o Shader.o Texture.o Utils.o Wrapper.o\
 	Matrix3D.o Matrix3DStack.o StackOverflow.o StackUnderflow.o Vector3D.o\
 	Client.o\
-	Chunk.o
+	Chunk.o World.o
 	g++ $(VERSION) -o $@ MainClient.cpp *.o $(LDFLAGS)
 	
 # ------------------------------------------------------------------------------	
@@ -58,6 +58,9 @@ Client.o: client/Client.h client/Client.cpp
 	
 Chunk.o: world/Chunk.h world/Chunk.cpp
 	g++ $(VERSION) -c world/Chunk.cpp -o $@
+	
+World.o: world/World.h world/World.cpp
+	g++ $(VERSION) -c world/World.cpp -o $@
 
 # ------------------------------------------------------------------------------	
 # Math

+ 17 - 8
client/Client.cpp

@@ -3,7 +3,7 @@
 
 using namespace std;
 
-Client::Client() : chunk(0, 0)
+Client::Client()
 {    
     position.set(0, 0, -2);
     shader.setCamera(position.getX(), position.getY(), position.getZ(), 0, 0);
@@ -20,6 +20,8 @@ Client::Client() : chunk(0, 0)
     keyManager.map(KEY_CAM_UP, GLFW_KEY_U);
     keyManager.map(KEY_CAM_DOWN, GLFW_KEY_J);
     
+    keyManager.map(KEY_CAM_TEST, GLFW_KEY_T);
+    
     mouseManager.map(MOUSE_LEFT, GLFW_MOUSE_BUTTON_1);
 }
 
@@ -42,9 +44,18 @@ void Client::tick()
         ticker = 0;
     }
     
+    if(keyManager.isDown(KEY_CAM_TEST))
+    {
+        Engine::setLineMode(true);
+    }
+    else
+    {
+        Engine::setLineMode(false);
+    }
+    
     shader.storeCamera();
     
-    float factor = 0.5f;
+    float factor = 2.0f;
     if(keyManager.isDown(KEY_LEFT))
     {
         position.addMul(shader.getLeft(), factor);
@@ -78,11 +89,11 @@ void Client::tick()
     {
         lengthAngle -= 2;
     }
-    if(keyManager.isDown(KEY_CAM_UP))
+    if(keyManager.isDown(KEY_CAM_UP) && widthAngle < 88)
     {
         widthAngle += 2;
     }
-    if(keyManager.isDown(KEY_CAM_DOWN))
+    if(keyManager.isDown(KEY_CAM_DOWN) && widthAngle > -88)
     {
         widthAngle -= 2;
     }
@@ -104,7 +115,7 @@ void Client::renderTick(float lag)
     shader.setTextureEnabled(false);
     shader.setUseBlending(false);
     shader.setNormalsEnabled(true);
-    chunk.renderTick(shader, directRenderer, lag);
+    world.renderTick(shader, directRenderer, lag);
     
     shader.set2DMode();
     shader.setToIdentity();
@@ -112,10 +123,8 @@ void Client::renderTick(float lag)
     shader.setTextMode();
     
     string wusi;
-    float y = 30;
     wusi = "FPS: " + to_string(fps.getUpdatesPerSecond());
-    y = directRenderer.drawString(30, y, false, wusi);
-    y = directRenderer.drawString(30, y, true, wusi);
+    directRenderer.drawString(10, 10, true, wusi);
 }
 
 void Client::onKeyEvent(int key, int scancode, int action, int mods)

+ 4 - 2
client/Client.h

@@ -7,7 +7,7 @@
 #include "../engine/Clock.h"
 #include "../engine/Shader.h"
 #include "../engine/DirectRenderer.h"
-#include "../world/Chunk.h"
+#include "../world/World.h"
 
 using namespace std;
 
@@ -34,6 +34,8 @@ private:
     static const int KEY_CAM_UP = 8;
     static const int KEY_CAM_DOWN = 9;
     
+    static const int KEY_CAM_TEST = 10;
+    
     static const int MOUSE_LEFT = 0;
     
     Clock tps;
@@ -42,7 +44,7 @@ private:
     KeyManager keyManager;
     MouseManager mouseManager;
     
-    Chunk chunk;
+    World world;
     
     Shader shader;
     DirectRenderer directRenderer;

+ 4 - 4
engine/Mesh.cpp

@@ -4,10 +4,6 @@
 
 using namespace std;
 
-Mesh::Mesh()
-{
-}
-
 Mesh::Mesh(int mode)
 {
     // position
@@ -146,6 +142,10 @@ void Mesh::build()
 
 void Mesh::draw()
 {
+    if(vertices == 0)
+    {
+        return;
+    }
     glBindVertexArray(vba);
     glBindBuffer(GL_ARRAY_BUFFER, vbo);
     glDrawArrays(GL_TRIANGLES, 0, vertices);

+ 6 - 1
engine/Mesh.h

@@ -7,7 +7,6 @@
 class Mesh
 {
 public:
-    Mesh();
     Mesh(int mode);
     Mesh(const Mesh& orig);
     virtual ~Mesh();
@@ -45,5 +44,11 @@ private:
     float* data = nullptr;
 };
 
+class ChunkMesh : public Mesh
+{
+public:
+    ChunkMesh() : Mesh(Mesh::COLOR | Mesh::NORMAL) {};
+};
+
 #endif
 

+ 17 - 1
engine/Wrapper.cpp

@@ -27,6 +27,8 @@ int Engine::scale = 1;
 int Engine::width = 0;
 int Engine::height = 0;
 
+bool Engine::lineMode = false;
+
 bool Engine::init(int width, int height, const char* name)
 {
     Engine::width = width;
@@ -157,7 +159,16 @@ void Engine::start(IClient* client)
         glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
         glEnable(GL_DEPTH_TEST);
-        Engine::client->renderTick((float) lag / NANOS_PER_TICK);
+        if(lineMode)
+        {
+            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+            Engine::client->renderTick((float) lag / NANOS_PER_TICK);
+            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+        }
+        else
+        {
+            Engine::client->renderTick((float) lag / NANOS_PER_TICK);
+        }
         
         // draw textured framebuffer
         glActiveTexture(GL_TEXTURE1);
@@ -520,4 +531,9 @@ void Engine::destroyPostData()
 {
     glDeleteVertexArrays(1, &postVba);
     glDeleteBuffers(1, &postVbo);
+}
+
+void Engine::setLineMode(bool mode)
+{
+    lineMode = mode;
 }

+ 4 - 0
engine/Wrapper.h

@@ -47,6 +47,8 @@ public:
     static void setMatrix(GLint location, const GLfloat* m);
     static void setInt(GLint location, GLint i);
     static void setFloat(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);
+    
+    static void setLineMode(bool mode);
 private:
     static const uint64_t NANOS_PER_TICK = 50000000;
     static const int MAX_TICKS_PER_FRAME = 5;
@@ -85,6 +87,8 @@ private:
     static int scale;
     static int width;
     static int height;
+    
+    static bool lineMode;
 };
 
 #endif

+ 3 - 30
shader/postFragment.fs

@@ -1,39 +1,12 @@
 #version 430
 
 layout (binding = 1) uniform sampler2D samp;
-layout (binding = 2) uniform sampler2D depth;
+layout (binding = 2) uniform sampler2D depthSamp;
 
 in vec2 tc;
 out vec4 color;
 
-const float offset = 3.0 / 300.0;
-
-void main(void)
-{
-    /*vec2 offsets[8] = vec2[](
-        vec2(-offset,  offset), // top-left
-        vec2( 0.0f,    offset), // top-center
-        vec2( offset,  offset), // top-right
-        vec2(-offset,  0.0f),   // center-left
-        //vec2( 0.0f,    0.0f),   // center-center
-        vec2( offset,  0.0f),   // center-right
-        vec2(-offset, -offset), // bottom-left
-        vec2( 0.0f,   -offset), // bottom-center
-        vec2( offset, -offset)  // bottom-right    
-    );
-    
-    float d = texture(depth, tc).r;
-
-    float c = 0;
-    for(int i = 0; i < 8; i++)
-    {
-        //c += float(d < texture(depth, tc + offsets[i]).r);
-        c += d - texture(depth, tc + offsets[i]).r;
-    }
-
-    c *= 100;
-    
-    color = vec4(c, c, c, 1.0);*/
-    //color = texture(samp, tc) * c;
+void main(void)  
+{  
     color = texture(samp, tc);
 }

+ 2 - 2
shader/vertex.vs

@@ -29,11 +29,11 @@ void main(void)
     {
         if(abs(normal.x) == 1)
         {
-            outColor = outColor * 0.5;
+            outColor = outColor * 0.8;
         }
         if(abs(normal.z) == 1)
         {
-            outColor = outColor * 0.75;
+            outColor = outColor * 0.9;
         }
     }
     

+ 136 - 114
world/Chunk.cpp

@@ -1,36 +1,38 @@
 #include "Chunk.h"
 #include <cstdlib>
+#include <cmath>
 
 Chunk::Chunk(int chunkX, int chunkZ) : chunkX(chunkX), chunkZ(chunkZ)
 {
-    mesh = new Mesh*[HEIGHT_PARTIONS];
+    mesh = new ChunkMesh[HEIGHT_PARTIONS];
     for(int i = 0; i < HEIGHT_PARTIONS; i++)
     {
-        mesh[i] = new Mesh(Mesh::COLOR | Mesh::NORMAL);
         dirty[i] = true;
     }
-    for(int y = 0; y < HEIGHT; y++)
+    for(int z = 0; z < DEPTH; z++)
     {
         for(int x = 0; x < WIDTH; x++)
         {
-            for(int z = 0; z < DEPTH; z++)
+            int maxY = (int) (sin((x + chunkX * WIDTH) * 0.3) * 20 + 22) + (sin((z + chunkZ * DEPTH) * 0.3) * 20 + 22);
+            if(maxY > HEIGHT)
+            {
+                maxY = HEIGHT;
+            }
+            
+            for(int y = 0; y < maxY; y++)
             {
-                blocks[y][x][z] = (rand() < RAND_MAX / 2);
+                blocks[y][x][z] = 1;
+            }
+            for(int y = maxY; y < HEIGHT; y++)
+            {
+                blocks[y][x][z] = 0;
             }
         }
     }
 }
 
-Chunk::Chunk(const Chunk& orig)
-{
-}
-
 Chunk::~Chunk()
 {
-    for(int i = 0; i < HEIGHT_PARTIONS; i++)
-    {
-        delete mesh[i];
-    }
     delete[] mesh;
 }
 
@@ -46,6 +48,8 @@ unsigned short Chunk::getBlock(int x, int y, int z)
 
 void Chunk::renderTick(Shader& shader, DirectRenderer& dr, float lag)
 {
+    shader.translateTo(chunkX * WIDTH, 0, chunkZ * DEPTH);
+    shader.updateModelMatrix();
     for(int i = 0; i < HEIGHT_PARTIONS; i++)
     {
         if(dirty[i])
@@ -53,16 +57,16 @@ void Chunk::renderTick(Shader& shader, DirectRenderer& dr, float lag)
             buildChunk(i);
             dirty[i] = false;
         }
-        mesh[i]->draw();
+        mesh[i].draw();
     }
 }
 
 void Chunk::buildChunk(int partionY)
 {    
-    cout << "BUILD " << partionY << endl;
-    Mesh& m = *mesh[partionY];
+    Mesh& m = mesh[partionY];
     
-    for(int y = 0; y < HEIGHT; y++)
+    int max = (partionY + 1) * PARTION_HEIGHT;
+    for(int y = partionY * PARTION_HEIGHT; y < max; y++)
     {
         for(int x = 0; x < WIDTH; x++)
         {
@@ -76,129 +80,147 @@ void Chunk::buildChunk(int partionY)
                     }
                     
                     // bottom
-                    //m.addTexture(0.125f, 0.0f);
-                    //m.addTexture(0.1875f, 0.0f);
-                    //m.addTexture(0.125f, 0.0625f);
-                    //m.addTexture(0.1875f, 0.0f);
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.125f, 0.0625f);
-                    
-                    for(int i = 0; i < 6; i++)
+                    if(y <= 0 || blocks[y - 1][x][z] != 1)
                     {
-                        m.addNormal(0.0f, -1.0f, 0.0f);
+                        //m.addTexture(0.125f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0f);
+                        //m.addTexture(0.125f, 0.0625f);
+                        //m.addTexture(0.1875f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.125f, 0.0625f);
+
+                        for(int i = 0; i < 6; i++)
+                        {
+                            m.addNormal(0.0f, -1.0f, 0.0f);
+                        }
+
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
                     }
 
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
-
                     // top
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.25f, 0.0625f);
-                    //m.addTexture(0.3125f, 0.0f);
-                    //m.addTexture(0.3125f, 0.0f);
-                    //m.addTexture(0.25f, 0.0625f);
-                    //m.addTexture(0.3125f, 0.0625f);
-                    
-                    for(int i = 0; i < 6; i++)
+                    if(y + 1 >= HEIGHT || blocks[y + 1][x][z] != 1)
                     {
-                        m.addNormal(0.0f, 1.0f, 0.0f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.25f, 0.0625f);
+                        //m.addTexture(0.3125f, 0.0f);
+                        //m.addTexture(0.3125f, 0.0f);
+                        //m.addTexture(0.25f, 0.0625f);
+                        //m.addTexture(0.3125f, 0.0625f);
+
+                        for(int i = 0; i < 6; i++)
+                        {
+                            m.addNormal(0.0f, 1.0f, 0.0f);
+                        }
+
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
                     }
 
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
-
                     // right
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.25f, 0.0625f);
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.1875f, 0.0f);
-                    //m.addTexture(0.25f, 0.0f);
-                    
-                    for(int i = 0; i < 6; i++)
+                    if(x + 1 >= WIDTH || blocks[y][x + 1][z] != 1)
                     {
-                        m.addNormal(1.0f, 0.0f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.25f, 0.0625f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.1875f, 0.0f);
+                        //m.addTexture(0.25f, 0.0f);
+
+                        for(int i = 0; i < 6; i++)
+                        {
+                            m.addNormal(1.0f, 0.0f, 0.0f);
+                        }
+
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
                     }
 
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
-
                     // left
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.1875f, 0.0f);
-                    
-                    for(int i = 0; i < 6; i++)
+                    if(x <= 0 || blocks[y][x - 1][z] != 1)
                     {
-                        m.addNormal(-1.0f, 0.0f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0f);
+
+                        for(int i = 0; i < 6; i++)
+                        {
+                            m.addNormal(-1.0f, 0.0f, 0.0f);
+                        }
+
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 0.0f);
                     }
 
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 0.0f);
-
                     // back
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.1875f, 0.0f);
-                    
-                    for(int i = 0; i < 6; i++)
+                    if(z + 1 >= DEPTH || blocks[y][x][z + 1] != 1)
                     {
-                        m.addNormal(0.0f, 0.0f, -1.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.1875f, 0.0f);
+
+                        for(int i = 0; i < 6; i++)
+                        {
+                            m.addNormal(0.0f, 0.0f, -1.0f);
+                        }
+
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
                     }
 
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 1.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 1.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 1.0f);
-
                     // front
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.25f, 0.0f);
-                    //m.addTexture(0.25f, 0.0625f);
-                    //m.addTexture(0.1875f, 0.0625f);
-                    //m.addTexture(0.1875f, 0.0f);
-                    //m.addTexture(0.25f, 0.0f);
-                    
-                    for(int i = 0; i < 6; i++)
+                    if(z <= 0 || blocks[y][x][z - 1] != 1)
                     {
-                        m.addNormal(0.0f, 0.0f, 1.0f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.25f, 0.0f);
+                        //m.addTexture(0.25f, 0.0625f);
+                        //m.addTexture(0.1875f, 0.0625f);
+                        //m.addTexture(0.1875f, 0.0f);
+                        //m.addTexture(0.25f, 0.0f);
+
+                        for(int i = 0; i < 6; i++)
+                        {
+                            m.addNormal(0.0f, 0.0f, 1.0f);
+                        }
+
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
+                        m.addPosition(x + 0.0f, y + 1.0f, z + 0.0f);
+                        m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
                     }
-
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 0.0f, z + 0.0f);
-                    m.addPosition(x + 0.0f, y + 1.0f, z + 0.0f);
-                    m.addPosition(x + 1.0f, y + 1.0f, z + 0.0f);
                 }
             }
         }
     }
     
-    m.build();  
+    m.build();
 }
 

+ 2 - 3
world/Chunk.h

@@ -9,7 +9,6 @@ class Chunk
 {
 public:
     Chunk(int chunkX, int chunkZ);
-    Chunk(const Chunk& orig);
     virtual ~Chunk();
     
     void setBlock(int x, int y, int z, unsigned short block);
@@ -19,7 +18,7 @@ public:
     
     // chunk constants
     static const int PARTION_HEIGHT = 16;
-    static const int HEIGHT_PARTIONS = 1;
+    static const int HEIGHT_PARTIONS = 16;
     
     static const int WIDTH = 16;
     static const int HEIGHT = PARTION_HEIGHT * HEIGHT_PARTIONS;
@@ -36,7 +35,7 @@ private:
     
     unsigned short blocks[HEIGHT][WIDTH][DEPTH];
     bool dirty[HEIGHT_PARTIONS];
-    Mesh** mesh;
+    ChunkMesh* mesh;
 };
 
 #endif

+ 39 - 0
world/World.cpp

@@ -0,0 +1,39 @@
+#include "World.h"
+
+World::World()
+{
+    chunks = new Chunk**[chunkX];
+    for(int x = 0; x < chunkX; x++)
+    {
+        chunks[x] = new Chunk*[chunkZ];
+        for(int z = 0; z < chunkZ; z++)
+        {
+            chunks[x][z] = new Chunk(x, z);
+        }
+    }
+}
+
+World::~World()
+{
+    for(int x = 0; x < chunkX; x++)
+    {
+        for(int z = 0; z < chunkZ; z++)
+        {
+            delete chunks[x][z];
+        }
+        delete[] chunks[x];
+    }
+    delete[] chunks;
+}
+
+void World::renderTick(Shader& shader, DirectRenderer& dr, float lag)
+{
+    for(int x = 0; x < chunkX; x++)
+    {
+        for(int z = 0; z < chunkZ; z++)
+        {
+            chunks[x][z]->renderTick(shader, dr, lag);
+        }
+    }
+}
+

+ 23 - 0
world/World.h

@@ -0,0 +1,23 @@
+#ifndef WORLD_H
+#define WORLD_H
+
+#include "../engine/Shader.h"
+#include "../engine/DirectRenderer.h"
+#include "Chunk.h"
+
+class World
+{
+public:
+    World();
+    virtual ~World();
+    
+    void renderTick(Shader& shader, DirectRenderer& dr, float lag);
+private:
+    const int chunkX = 16;
+    const int chunkZ = 16;
+    
+    Chunk*** chunks;
+};
+
+#endif
+