浏览代码

recoding / refactoring for the most of the client code, framebuffer test

Kajetan Johannes Hammerle 5 年之前
父节点
当前提交
240ded2c84
共有 94 个文件被更改,包括 1787 次插入4217 次删除
  1. 61 0
      client/Game.cpp
  2. 28 0
      client/Game.h
  3. 196 153
      client/GameClient.cpp
  4. 1 64
      client/GameClient.h
  5. 2 13
      client/Main.cpp
  6. 63 0
      client/Utils.cpp
  7. 8 0
      client/Utils.h
  8. 0 39
      client/engine/Clock.cpp
  9. 0 25
      client/engine/Clock.h
  10. 0 236
      client/engine/DirectRenderer.cpp
  11. 0 51
      client/engine/DirectRenderer.h
  12. 0 254
      client/engine/Mesh.cpp
  13. 0 66
      client/engine/Mesh.h
  14. 0 69
      client/engine/MouseManager.cpp
  15. 0 38
      client/engine/MouseManager.h
  16. 0 70
      client/engine/Shader.cpp
  17. 0 32
      client/engine/Shader.h
  18. 0 34
      client/engine/Texture.h
  19. 0 6
      client/engine/Utils.cpp
  20. 0 67
      client/engine/Utils.h
  21. 0 292
      client/engine/Wrapper.cpp
  22. 0 127
      client/engine/Wrapper.h
  23. 0 51
      client/engine/shader/FramebufferRectangle.cpp
  24. 0 21
      client/engine/shader/FramebufferRectangle.h
  25. 0 91
      client/engine/shader/OverlayShader.cpp
  26. 0 34
      client/engine/shader/OverlayShader.h
  27. 0 73
      client/engine/shader/SSAOBlurShader.cpp
  28. 0 29
      client/engine/shader/SSAOBlurShader.h
  29. 0 136
      client/engine/shader/SSAOShader.cpp
  30. 0 45
      client/engine/shader/SSAOShader.h
  31. 0 187
      client/engine/shader/ShaderProgram.cpp
  32. 0 31
      client/engine/shader/ShaderProgram.h
  33. 0 72
      client/engine/shader/WorldPostShader.cpp
  34. 0 31
      client/engine/shader/WorldPostShader.h
  35. 0 159
      client/engine/shader/WorldShader.cpp
  36. 0 42
      client/engine/shader/WorldShader.h
  37. 4 2
      client/input/Keys.cpp
  38. 7 7
      client/input/Keys.h
  39. 99 0
      client/input/MouseButtons.cpp
  40. 70 0
      client/input/MouseButtons.h
  41. 126 0
      client/math/Camera.cpp
  42. 56 0
      client/math/Camera.h
  43. 0 242
      client/math/Camera3D.cpp
  44. 0 58
      client/math/Camera3D.h
  45. 35 39
      client/math/Matrix.cpp
  46. 8 12
      client/math/Matrix.h
  47. 0 32
      client/math/Matrix3DStack.cpp
  48. 0 21
      client/math/Matrix3DStack.h
  49. 27 0
      client/math/MatrixStack.cpp
  50. 21 0
      client/math/MatrixStack.h
  51. 25 0
      client/math/Plane.cpp
  52. 21 0
      client/math/Plane.h
  53. 0 29
      client/math/Plane3D.cpp
  54. 0 21
      client/math/Plane3D.h
  55. 0 19
      client/math/StackOverflow.cpp
  56. 0 19
      client/math/StackOverflow.h
  57. 0 19
      client/math/StackUnderflow.cpp
  58. 0 19
      client/math/StackUnderflow.h
  59. 139 0
      client/math/Vector.cpp
  60. 47 0
      client/math/Vector.h
  61. 0 157
      client/math/Vector3D.cpp
  62. 0 50
      client/math/Vector3D.h
  63. 0 101
      client/rendering/ChunkRenderer.cpp
  64. 0 30
      client/rendering/ChunkRenderer.h
  65. 0 50
      client/rendering/ClientChunkProvider.cpp
  66. 0 23
      client/rendering/ClientChunkProvider.h
  67. 116 0
      client/rendering/FontRenderer.cpp
  68. 31 0
      client/rendering/FontRenderer.h
  69. 169 0
      client/rendering/Framebuffer.cpp
  70. 44 0
      client/rendering/Framebuffer.h
  71. 47 0
      client/rendering/Mesh.cpp
  72. 42 0
      client/rendering/Mesh.h
  73. 113 0
      client/rendering/Shader.cpp
  74. 35 0
      client/rendering/Shader.h
  75. 23 51
      client/rendering/Texture.cpp
  76. 37 0
      client/rendering/Texture.h
  77. 0 171
      client/rendering/block/BlockRenderer.cpp
  78. 0 73
      client/rendering/block/BlockRenderer.h
  79. 0 41
      client/rendering/block/BlockRenderers.cpp
  80. 0 21
      client/rendering/block/BlockRenderers.h
  81. 0 133
      client/rendering/entity/EntityRenderer.cpp
  82. 0 26
      client/rendering/entity/EntityRenderer.h
  83. 0 20
      client/rendering/gui/GUI.cpp
  84. 0 26
      client/rendering/gui/GUI.h
  85. 0 10
      client/rendering/gui/GUIs.h
  86. 0 38
      client/rendering/gui/StartMenu.cpp
  87. 0 18
      client/rendering/gui/StartMenu.h
  88. 1 1
      meson.build
  89. 13 0
      resources/shader/test2Fragment.fs
  90. 13 0
      resources/shader/test2Vertex.vs
  91. 11 0
      resources/shader/testFragment.fs
  92. 16 0
      resources/shader/testVertex.vs
  93. 13 0
      resources/shader/textFragment.fs
  94. 19 0
      resources/shader/textVertex.vs

+ 61 - 0
client/Game.cpp

@@ -0,0 +1,61 @@
+#include <sstream>
+
+#include "client/Game.h"
+
+Game::Game() : texture("resources/textures.png")
+{
+    m.add({0, 0, 0.9, 0, 0, 1, 0, 0});
+    m.add({0, 1, 0.9, 0, 1, 1, 0, 0});
+    m.add({1, 0, 0.9, 1, 0, 1, 0, 0});
+    m.build();
+}
+
+void Game::tick(const Keys& keys, const MouseButtons& mButtons, Camera& cam)
+{
+    (void) mButtons;
+    
+    if(keys.down.isDown())
+    {
+        pos.addMul(cam.getFlatBack(), 0.1f);
+    }
+    if(keys.up.isDown())
+    {
+        pos.addMul(cam.getFlatFront(), 0.1f);
+    }
+    if(keys.left.isDown())
+    {
+        pos.addMul(cam.getFlatLeft(), 0.1f);
+    }
+    if(keys.right.isDown())
+    {
+        pos.addMul(cam.getFlatRight(), 0.1f);
+    }
+    if(keys.jump.isDown())
+    {
+        pos.addMul(cam.getFlatUp(), 0.1f);
+    }
+    if(keys.sneak.isDown())
+    {
+        pos.addMul(cam.getFlatDown(), 0.1f);
+    }
+
+    cam.storePosition();
+    cam.setPosition(pos, 0, 0);
+}
+
+void Game::renderWorld(float lag, MatrixStack& stack, Shader& sh)
+{
+    (void) lag;
+    (void) stack;
+    (void) sh;
+    texture.bind(0);
+    m.draw();
+}
+
+void Game::renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr)
+{
+    (void) lag;
+    stack.get().scale(2.0f, 2.0f, 2.0f);
+    sh.setMatrix("model", stack.get().getValues());
+    fr.drawString(0, 0, "Das ist ein Test");
+}

+ 28 - 0
client/Game.h

@@ -0,0 +1,28 @@
+#ifndef GAME_H
+#define GAME_H
+
+#include "client/input/Keys.h"
+#include "client/input/MouseButtons.h"
+#include "client/rendering/Shader.h"
+#include "client/math/MatrixStack.h"
+#include "client/math/Camera.h"
+#include "client/rendering/Mesh.h"
+#include "client/rendering/Texture.h"
+#include "client/rendering/FontRenderer.h"
+
+class Game
+{
+public:
+    Game();
+    
+    void tick(const Keys& keys, const MouseButtons& mButtons, Camera& cam);
+    void renderWorld(float lag, MatrixStack& stack, Shader& sh);
+    void renderTextOverlay(float lag, MatrixStack& stack, Shader& sh, FontRenderer& fr);
+    
+private:
+    Vector pos;
+    Mesh m;
+    Texture texture;
+};
+
+#endif

+ 196 - 153
client/GameClient.cpp

@@ -2,10 +2,21 @@
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>
 #include <unordered_map>
+#include <cmath>
 
-#include "GameClient.h"
 #include "common/utils/Types.h"
-#include "client/Keys.h"
+#include "client/GameClient.h"
+#include "client/input/Keys.h"
+#include "client/input/MouseButtons.h"
+#include "client/rendering/Shader.h"
+#include "client/rendering/FontRenderer.h"
+#include "client/rendering/Mesh.h"
+#include "client/rendering/Framebuffer.h"
+#include "client/Utils.h"
+#include "client/math/Camera.h"
+#include "client/math/Matrix.h"
+#include "client/math/MatrixStack.h"
+#include "client/Game.h"
 
 struct InternGameClient
 {
@@ -30,8 +41,62 @@ static const float lagFactor = 1.0f / NANOS_PER_TICK;
 static u64 timeFactor = 1;
 static int width = 0;
 static int height = 0;
+static bool resize = false;
+static float fovY = 60.0f;
+static float nearClip = 0.1f;
+static float farClip = 1000.0f;
 static InternGameClient client;
 static Keys keys;
+static MouseButtons mButtons;
+
+struct Shaders
+{
+    Shaders() : 
+        world("resources/shader/testVertex.vs", "resources/shader/testFragment.fs"),
+        text("resources/shader/textVertex.vs", "resources/shader/textFragment.fs")
+    {
+    }
+    
+    Shader world;
+    Shader text;
+    
+    bool isValid() const
+    {
+        return world.isValid() && text.isValid();
+    }
+};
+
+struct Framebuffers
+{
+    Framebuffers(u32 w, u32 h) : worldBuffer(w, h, Framebuffer::COLOR)
+    {
+    }
+    
+    void resize(u32 w, u32 h) const
+    {
+        worldBuffer.resize(w, h);
+    }
+    
+    bool isValid() const
+    {
+        return worldBuffer.isValid();
+    }
+    
+    Framebuffer worldBuffer;
+};
+
+struct InternGame
+{
+    Game game;
+    Camera cam;
+    MatrixStack model;
+    FontRenderer fontRenderer;
+};
+
+static u64 getTimeNanos()
+{
+    return glfwGetTimerValue() * timeFactor;
+}
 
 static bool initGLFW()
 {
@@ -95,33 +160,151 @@ static void initCallbacks()
             keys.release(key);
         }
     });
-    //glfwSetMouseButtonCallback(window, onMouseClick);
-    //glfwSetFramebufferSizeCallback(window, onWindowResize); 
-    //glfwSetCursorPosCallback(window, onMouseMove);
+    // GLFWwindow* w, int button, int action, int mods
+    glfwSetMouseButtonCallback(client.window, [](GLFWwindow*, int button, int action, int)
+    {
+        if(action == GLFW_PRESS)
+        {
+            mButtons.press(button);
+        }
+        else if(action == GLFW_RELEASE)
+        {
+            mButtons.release(button);
+        }
+    });
+    // GLFWwindow* w, double xpos, double ypos
+    glfwSetCursorPosCallback(client.window, [](GLFWwindow*, double x, double y)
+    {
+        mButtons.move(x, y);
+    });
+    // GLFWwindow* w, int width, int height
+    glfwSetFramebufferSizeCallback(client.window, [](GLFWwindow*, int w, int h)
+    {
+        glViewport(0, 0, w, h);
+        width = w;
+        height = h;
+        resize = true;
+    });
 }
 
-static void tick()
+static void tick(InternGame& game)
 {
-    std::cout << keys.down << std::endl;
     keys.tick();
+    mButtons.tick();
+    game.game.tick(keys, mButtons, game.cam);
+    mButtons.postTick();
 }
 
-static void renderTick(float /*lag*/)
+static void renderWorld(float lag, Shaders& shaders, InternGame& game)
 {
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glEnable(GL_DEPTH_TEST);
+    // use world program
+    shaders.world.use();
+    // send projection matrix
+    float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
+    float q = 1.0f / tan;
+    float aspect = (float) width / height;
+    float proj[] = 
+    {
+        q / aspect, 0.0f, 0.0f, 0.0f,
+        0.0f, q, 0.0f, 0.0f,
+        0.0f, 0.0f, (nearClip + farClip) / (nearClip - farClip), -1.0f,
+        0.0f, 0.0f, (2.0f * nearClip * farClip) / (nearClip - farClip), 0.0f
+    };
+    shaders.world.setMatrix("proj", proj);
+    // send view matrix
+    game.cam.update(lag);
+    const Vector right = game.cam.getRight();
+    const Vector up = game.cam.getUp();
+    const Vector back = game.cam.getBack();
+    const Vector pos = game.cam.getPosition();
+    float view[] = 
+    {
+        right.getX(), up.getX(), back.getX(), 0.0f,
+        right.getY(), up.getY(), back.getY(), 0.0f,
+        right.getZ(), up.getZ(), back.getZ(), 0.0f,
+        right.dotInverse(pos), up.dotInverse(pos), back.dotInverse(pos), 1.0f
+    };
+    shaders.world.setMatrix("view", view);
+    // clear and send model matrix
+    game.model.clear();
+    shaders.world.setMatrix("model", game.model.get().getValues());
+    // call high level world renderer
+    game.game.renderWorld(lag, game.model, shaders.world);
 }
 
-static u64 getTimeNanos()
+static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game)
 {
-    return glfwGetTimerValue() * timeFactor;
+    glDisable(GL_DEPTH_TEST);
+    shaders.text.use();
+    
+    Matrix m;
+    shaders.text.setMatrix("proj", m.getValues());
+    m.translate(-1.0f, 1.0f, 0.0f);
+    m.scale(2.0f / width, -2.0f / height, 1.0f);
+    shaders.text.setMatrix("view", m.getValues());
+    game.model.clear();
+    game.model.get().scale(2.0f, 2.0f, 2.0f);
+    shaders.text.setMatrix("model", game.model.get().getValues());
+    
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    glBlendEquation(GL_FUNC_ADD);
+    game.game.renderTextOverlay(lag, game.model, shaders.text, game.fontRenderer);
+    glDisable(GL_BLEND);
+}
+
+static void renderTick(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb)
+{
+    if(resize)
+    {
+        fb.resize(width, height);
+        resize = false;
+    }
+    fb.worldBuffer.bind();
+    renderWorld(lag, shaders, game);
+    glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+    renderTextOverlay(lag, shaders, game);
 }
 
 static void loop()
 {
+    Shaders shaders;
+    if(!shaders.isValid())
+    {
+        return;
+    }
+    Framebuffers framebuffers(width, height);
+    if(!framebuffers.isValid())
+    {
+        return;
+    }
+    InternGame game;
+    
+    Shader sh("resources/shader/test2Vertex.vs", "resources/shader/test2Fragment.fs");
+    Mesh m;
+    m.add({-1, -1, 0, 0, 0, 0, 0, 0});
+    m.add({-1,  1, 0, 0, 1, 0, 0, 0});
+    m.add({ 1,  1, 0, 1, 1, 0, 0, 0});
+    m.add({-1, -1, 0, 0, 0, 0, 0, 0});
+    m.add({ 1, -1, 0, 1, 0, 0, 0, 0});
+    m.add({ 1,  1, 0, 1, 1, 0, 0, 0});
+    m.build();
+    
     u64 lastTime = getTimeNanos();
     u64 lag = 0;
     while(!glfwWindowShouldClose(client.window))
     {
-        renderTick(lag * lagFactor);
+        renderTick(lag * lagFactor, shaders, game, framebuffers);
+        framebuffers.worldBuffer.bindColorTexture(1);
+        sh.use();
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+        glBlendEquation(GL_FUNC_ADD);
+        m.draw();
+        glDisable(GL_BLEND);
         glfwSwapBuffers(client.window);
         
         u64 newTime = getTimeNanos();
@@ -131,7 +314,7 @@ static void loop()
         while(lag >= NANOS_PER_TICK)
         {
             lag -= NANOS_PER_TICK;
-            tick();
+            tick(game);
         }
         glfwPollEvents();
     }
@@ -146,144 +329,4 @@ void GameClient::start(int w, int h, const char* windowName)
     initCallbacks();
     glfwShowWindow(client.window);
     loop();
-}
-
-/*#include <iostream>
-#include <cmath>
-
-#include "client/GameClient.h"
-#include "common/block/Blocks.h"
-#include "client/rendering/block/BlockRenderers.h"
-#include "client/rendering/entity/EntityRenderer.h"
-#include "client/rendering/gui/StartMenu.h"
-
-using namespace std;
-
-GameClient::GameClient()
-{    
-    BlockRegistry::registerBlocks();
-    BlockRenderers::init();
-
-    keyManager.map(KEY_LEFT, GLFW_KEY_A);
-    keyManager.map(KEY_RIGHT, GLFW_KEY_D);
-    keyManager.map(KEY_UP, GLFW_KEY_W);
-    keyManager.map(KEY_DOWN, GLFW_KEY_S);
-    keyManager.map(KEY_JUMP, GLFW_KEY_SPACE);
-    keyManager.map(KEY_SNEAK, GLFW_KEY_LEFT_SHIFT);
-    
-    keyManager.map(KEY_TEST, GLFW_KEY_T);
-    
-    mouseManager.map(MOUSE_LEFT, GLFW_MOUSE_BUTTON_1);
-    
-    activeGUI = new StartMenu();
-}
-
-GameClient::~GameClient()
-{
-    if(activeGUI != nullptr)
-    {
-        delete activeGUI;
-    }
-}
-
-void GameClient::tick()
-{
-    tps.update();
-    
-    diffMouseY = 0;
-    diffMouseX = 0;
-    
-    mouseManager.tick();
-    keyManager.tick();
-    
-    if(activeGUI != nullptr)
-    {
-        GUI* newGUI = activeGUI->tick(keyManager, mouseManager);
-        if(newGUI != activeGUI)
-        {
-            delete activeGUI;
-            activeGUI = newGUI;
-        }
-    }
-}
-
-void GameClient::render3DTick(float lag)
-{
-    fps.update();
-}
-
-void GameClient::render2DTick(float lag)
-{
-    if(activeGUI != nullptr)
-    {
-        activeGUI->render2DTick(shader, directRenderer, lag);
-    }
-    
-    Engine::setMixMode();
-    shader.setToIdentity();
-    shader.updateModelMatrix();
-    
-    string wusi;
-    wusi = "FPS: " + to_string(fps.getUpdatesPerSecond());
-    float y = directRenderer.drawString(10, 10, true, wusi);
-    wusi = "TPS: " + to_string(tps.getUpdatesPerSecond());
-    directRenderer.drawString(10, y, true, wusi);
-}
-
-void GameClient::onKeyEvent(int key, int scancode, int action, int mods)
-{
-    if(action == GLFW_PRESS)
-    {
-        keyManager.press(key);
-    }
-    else if(action == GLFW_RELEASE)
-    {
-        keyManager.release(key);
-    }
-}
-
-double GameClient::transformMouse(double x)
-{
-    if(x >= -MOUSE_BORDER && x <= MOUSE_BORDER)
-    {
-        return x * x * x;
-    }
-    else if(x >= MOUSE_BORDER)
-    {
-        const double k = (3 * MOUSE_BORDER * MOUSE_BORDER);
-        const double y = MOUSE_BORDER * MOUSE_BORDER * MOUSE_BORDER;
-        const double d = y - k * MOUSE_BORDER;
-        return k * x + d;
-    }
-    else
-    {
-        const double k = (3 * MOUSE_BORDER * MOUSE_BORDER);
-        const double y = -MOUSE_BORDER * MOUSE_BORDER * MOUSE_BORDER;
-        const double d = y - k * MOUSE_BORDER;
-        return k * x + d;
-    }
-}
-
-void GameClient::onMouseMove(double x, double y)
-{
-    if(mouseTrapped)
-    {
-        diffMouseX = transformMouse(oldMouseX - x) * (1 / (MOUSE_BORDER * MOUSE_BORDER * 3));
-        diffMouseY = transformMouse(oldMouseY - y) * (1 / (MOUSE_BORDER * MOUSE_BORDER * 3));
-        oldMouseX = x;
-        oldMouseY = y;
-    }
-}
-
-void GameClient::onMouseClick(int button, int action, int mods)
-{
-    if(action == GLFW_PRESS)
-    {
-        mouseManager.press(button);
-    }
-    else if(action == GLFW_RELEASE)
-    {
-        mouseManager.release(button);
-    }
-}*/
-
+}

+ 1 - 64
client/GameClient.h

@@ -8,67 +8,4 @@ namespace GameClient
     void start(int width, int height, const char* windowName);
 }
 
-// these two are not needed here but prevent further errors
-/*#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-#include "client/engine/KeyManager.h"
-#include "client/engine/MouseManager.h"
-#include "client/engine/Clock.h"
-#include "client/engine/Shader.h"
-#include "client/engine/DirectRenderer.h"
-#include "client/rendering/gui/GUIs.h"
-#include "client/rendering/gui/GUI.h"
-
-#include "common/world/IChunkProvider.h"
-
-using namespace std;
-
-class GameClient : public IClient
-{
-public:
-    GameClient();
-    virtual ~GameClient();
-    
-    void tick() override;
-    void render3DTick(float lag) override;
-    void render2DTick(float lag) override;
-    
-    void onKeyEvent(int key, int scancode, int action, int mods) override;
-    void onMouseMove(double x, double y) override;
-    void onMouseClick(int button, int action, int mods) override;
-private:
-    double transformMouse(double in);
-    
-    static const int KEY_LEFT = 0;
-    static const int KEY_RIGHT = 1;
-    static const int KEY_UP = 2;
-    static const int KEY_DOWN = 3;
-    static const int KEY_JUMP = 4;
-    static const int KEY_SNEAK = 5;
-    
-    static const int KEY_TEST = 10;
-    
-    static const int MOUSE_LEFT = 0;
-    
-    double oldMouseX = 0;
-    double oldMouseY = 0;
-    double diffMouseX = 0;
-    double diffMouseY = 0;
-    bool mouseTrapped = true;
-    const double MOUSE_BORDER = 1.0;
-    
-    Clock tps;
-    Clock fps;
-    
-    KeyManager keyManager;
-    MouseManager mouseManager;
-    
-    Shader shader;
-    DirectRenderer directRenderer;
-    
-    GUI* activeGUI = nullptr;
-};*/
-
-#endif
-
+#endif

+ 2 - 13
client/Main.cpp

@@ -1,18 +1,7 @@
-#include "GameClient.h"
-
-//#include "client/engine/Wrapper.h"
-//#include "client/GameClient.h"
-#include "client/Keys.h"
+#include "client/GameClient.h"
 
 int main(int /*argc*/, char** /*argv*/) 
 {
     GameClient::start(1024, 620, "Test");   
-    /*if(!Engine::init(1024, 620, "Test"))
-    {
-       return 0; 
-    }
-    GameClient client;
-    Engine::start(&client);*/
     return 0;
-}
-
+}

+ 63 - 0
client/Utils.cpp

@@ -0,0 +1,63 @@
+#include <GL/glew.h>
+#include <iostream>
+#include <iomanip>
+
+#include "client/Utils.h"
+
+bool checkAndPrintError(const char* message)
+{
+    GLenum error = glGetError();
+    switch(error)
+    {
+        case GL_NO_ERROR: 
+            return false;
+        case GL_INVALID_ENUM: 
+            std::cout << message << ": an unacceptable value is specified for an enumerated argument.\n";
+            break;
+        case GL_INVALID_VALUE: 
+            std::cout << message << ": a numeric argument is out of range.\n";
+            break;
+        case GL_INVALID_OPERATION: 
+            std::cout << message << ": the specified operation is not allowed in the current state.\n";
+            break;
+        case GL_INVALID_FRAMEBUFFER_OPERATION: 
+            std::cout << message << ": the framebuffer object is not complete.\n";
+            break;
+        case GL_OUT_OF_MEMORY: 
+            std::cout << message << ": there is not enough memory left to execute the command.\n";
+            break;
+        case GL_STACK_UNDERFLOW: 
+            std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to underflow.\n";
+            break;
+        case GL_STACK_OVERFLOW: 
+            std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to overflow.\n";
+            break;
+        default:
+            std::cout << message << ": unknown OpenGL error: " << error << "\n";
+    }
+    return true;
+}
+
+float interpolate(float lag, float from, float to)
+{
+    return from + lag * (to - from);
+}
+
+void printMatrix(const float* data)
+{
+    std::cout << "MatrixData\n(\n";
+    std::cout << std::fixed << std::setprecision(5);
+    for(int i = 0; i < 4; i++)
+    {
+        std::cout << std::setw(15);
+        std::cout << data[i] << ", ";
+        std::cout << std::setw(15);
+        std::cout << data[i + 4] << ", ";
+        std::cout << std::setw(15);
+        std::cout << data[i + 8] << ", ";
+        std::cout << std::setw(15);
+        std::cout << data[i + 12] << "\n";
+    }
+    std::cout << std::defaultfloat;
+    std::cout << ")\n";
+}

+ 8 - 0
client/Utils.h

@@ -0,0 +1,8 @@
+#ifndef UTILS_H
+#define UTILS_H
+
+bool checkAndPrintError(const char* message);
+float interpolate(float lag, float from, float to);
+void printMatrix(const float* data);
+
+#endif

+ 0 - 39
client/engine/Clock.cpp

@@ -1,39 +0,0 @@
-#include "client/engine/Clock.h"
-
-Clock::Clock()
-{
-    for(int i = 0; i < SIZE; i++)
-    {
-        time[i] = 0;
-    }
-}
-
-Clock::Clock(const Clock& orig)
-{
-}
-
-Clock::~Clock()
-{
-}
-
-void Clock::update()
-{
-    uint64_t t = glfwGetTimerValue();
-    time[index] = t - oldTime;
-    oldTime = t;
-    
-    sum += time[index];
-    index = (index + 1) & (SIZE - 1);
-    sum -= time[index];
-}
-
-double Clock::getUpdatesPerSecond() const
-{
-    return (1000000000.0 * (SIZE - 1)) / sum;
-}
-
-uint64_t Clock::getCurrentTime() const
-{
-    return time[(index - 1) & (SIZE - 1)];
-}
-

+ 0 - 25
client/engine/Clock.h

@@ -1,25 +0,0 @@
-#ifndef CLOCK_H
-#define CLOCK_H
-
-#include <GLFW/glfw3.h>
-
-class Clock
-{
-public:
-    Clock();
-    Clock(const Clock& orig);
-    virtual ~Clock();
-    
-    uint64_t getCurrentTime() const;
-    void update();
-    double getUpdatesPerSecond() const;
-private:
-    static const int SIZE = 64;
-    uint64_t oldTime = 0;
-    uint64_t time[SIZE];
-    uint64_t sum = 0;
-    unsigned int index = 0;
-};
-
-#endif
-

+ 0 - 236
client/engine/DirectRenderer.cpp

@@ -1,236 +0,0 @@
-#include <cmath>
-
-#include "client/engine/DirectRenderer.h"
-
-DirectRenderer::DirectRenderer()
-{
-    glGenVertexArrays(1, &vba);
-    glGenBuffers(1, &vbo);
-
-    glBindVertexArray(vba);
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-
-    glEnableVertexAttribArray(0);
-    glVertexAttribPointer(0, 3, GL_FLOAT, false, 24, (GLvoid*) 0);
-
-    glEnableVertexAttribArray(1);  
-    glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, 24, (GLvoid*) 12);
-    
-    glEnableVertexAttribArray(2);  
-    glVertexAttribPointer(2, 2, GL_FLOAT, false, 24, (GLvoid*) 16);
-}
-
-DirectRenderer::DirectRenderer(const DirectRenderer& orig)
-{
-}
-
-DirectRenderer::~DirectRenderer()
-{
-    glDeleteVertexArrays(1, &vba);
-    glDeleteBuffers(1, &vbo);
-}
-
-void DirectRenderer::drawRectangle(float minX, float minY, float maxX, float maxY, float tMinX, float tMinY, float tMaxX, float tMaxY, IntColor c)
-{
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-        
-    if(offset + OBJECT_LENGTH >= BUFFER_LENGTH)
-    {
-        offset = 0;
-        glBufferData(GL_ARRAY_BUFFER, BUFFER_LENGTH, NULL, GL_STREAM_DRAW);
-    }
-    float* buffer = (float*) glMapBufferRange(GL_ARRAY_BUFFER, offset, OBJECT_LENGTH, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
-    if(buffer == NULL)
-    {
-        return;
-    }
-
-    buffer[0] = minX;
-    buffer[1] = maxY;
-    buffer[2] = 0.0f;
-    buffer[3] = *((float*) (&c));
-    buffer[4] = tMinX;
-    buffer[5] = tMaxY;
-    
-    buffer[6] = maxX;
-    buffer[7] = maxY;
-    buffer[8] = 0.0f;
-    buffer[9] = *((float*) (&c));
-    buffer[10] = tMaxX;
-    buffer[11] = tMaxY;
-    
-    buffer[12] = minX;
-    buffer[13] = minY;
-    buffer[14] = 0.0f;
-    buffer[15] = *((float*) (&c));
-    buffer[16] = tMinX;
-    buffer[17] = tMinY;
-    
-    buffer[18] = maxX;
-    buffer[19] = minY;
-    buffer[20] = 0.0f;
-    buffer[21] = *((float*) (&c));
-    buffer[22] = tMaxX;
-    buffer[23] = tMinY;
-
-    glUnmapBuffer(GL_ARRAY_BUFFER);
-
-    glBindVertexArray(vba);
-    glDrawArrays(GL_TRIANGLE_STRIP, offset / (OBJECT_LENGTH / 4), 4);
-    offset += OBJECT_LENGTH;
-}
-
-void DirectRenderer::drawRectangle(float minX, float minY, float maxX, float maxY, IntColor c)
-{
-    drawRectangle(minX, minY, maxX, maxY, 0.0f, 0.0f, 0.0f, 0.0f, c);
-}
-
-void DirectRenderer::drawRectangle(float minX, float minY, float maxX, float maxY, float tMinX, float tMinY, float tMaxX, float tMaxY)
-{
-    drawRectangle(minX, minY, maxX, maxY, tMinX, tMinY, tMaxX, tMaxY, 0);
-}
-
-float DirectRenderer::drawString(float x, float y, bool shadow, string& s)
-{
-    int size = s.length() * OBJECT_LENGTH * (shadow + 1);
-    
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-        
-    if(offset + size >= BUFFER_LENGTH)
-    {
-        offset = 0;
-        glBufferData(GL_ARRAY_BUFFER, BUFFER_LENGTH, NULL, GL_STREAM_DRAW);
-    }
-    
-    float* buffer = (float*) glMapBufferRange(GL_ARRAY_BUFFER, offset, size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
-    if(buffer == NULL)
-    {
-        return y;
-    }
-
-    int index = 0;
-    if(shadow)
-    {
-        addString(x + SHADOW_STEP, y + SHADOW_STEP, index, buffer, Color::DARK_COLORS, s);
-    }
-    y = addString(x, y, index, buffer, Color::COLORS, s);
-
-    glUnmapBuffer(GL_ARRAY_BUFFER);
-
-    glBindVertexArray(vba);
-    FONTS[min(Engine::getScale() - 1, FONTS_LENGTH - 1)].bind();
-    glDrawArrays(GL_TRIANGLE_STRIP, offset / (OBJECT_LENGTH / 4), (index + 1) / 6);
-    offset += size;
-    
-    return y;
-}
-
-float DirectRenderer::addString(float x, float y, int& index, float* data, const IntColor* color, string& s)
-{
-    int l = min((int) s.length(), static_cast<int>(MAX_STRING_LENGTH));
-    
-    //x = roundf(x / GameEngine::scale) * GameEngine::scale;
-    //y = roundf(y / GameEngine::scale) * GameEngine::scale;
-        
-    float oldX = x;
-    float currentColor = *((float*) (&(color[Color::COLOR_AMOUNT - 1])));
-
-    for(int pos = 0; pos < l; pos++)
-    {
-        char c = s[pos];
-        if(c == COLOR_CHAR)
-        {
-            pos++;
-            if(pos < l)
-            {
-                int index = s[pos] - 'a';
-                if(index >= 0 && index < Color::COLOR_AMOUNT)
-                {
-                    currentColor = *((float*) (&(color[index])));
-                }
-            }
-            continue;
-        }
-        else if(c == '\n')
-        {
-            y += FONT_SIZE + LINE_STEP;
-            x = oldX;
-            continue;
-        }
-
-        float tMinX = (c & 0xF) * 0.0625f;
-        float tMinY = (c >> 4) * 0.0625f;
-        float tMaxX = tMinX + 0.0625f;
-        float tMaxY = tMinY + 0.0625f;
-        float maxX = x + FONT_SIZE;
-        float maxY = y + FONT_SIZE;
-        
-        data[index++] = x;
-        data[index++] = maxY;
-        data[index++] = 0.0f;
-        data[index++] = currentColor;
-        data[index++] = tMinX;
-        data[index++] = tMaxY;
-        
-        data[index++] = maxX;
-        data[index++] = maxY;
-        data[index++] = 0.0f;
-        data[index++] = currentColor;
-        data[index++] = tMaxX;
-        data[index++] = tMaxY;
-        
-        data[index++] = x;
-        data[index++] = y;
-        data[index++] = 0.0f;
-        data[index++] = currentColor;
-        data[index++] = tMinX;
-        data[index++] = tMinY;
-        
-        data[index++] = maxX;
-        data[index++] = y;
-        data[index++] = 0.0f;
-        data[index++] = currentColor;
-        data[index++] = tMaxX;
-        data[index++] = tMinY;
-        
-        x += FONT_SIZE;
-    }
-    return y + FONT_SIZE + LINE_STEP;
-}
-
-void DirectRenderer::getStringSize(float& width, float& height, string& s)
-{
-    int l = min((int) s.length(), static_cast<int>(MAX_STRING_LENGTH));
-    
-    width = 0.0f;
-    height = FONT_SIZE + LINE_STEP;
-        
-    float currentWidth = 0.0f;
-
-    for(int pos = 0; pos < l; pos++)
-    {
-        char c = s[pos];
-        if(c == COLOR_CHAR)
-        {
-            pos++;
-            continue;
-        }
-        else if(c == '\n')
-        {
-            if(currentWidth > width)
-            {
-                width = currentWidth;
-            }
-            height += FONT_SIZE + LINE_STEP;
-            currentWidth = 0.0f;
-            continue;
-        }
-
-        currentWidth += FONT_SIZE;
-    }
-    
-    if(currentWidth > width)
-    {
-        width = currentWidth;
-    }
-}

+ 0 - 51
client/engine/DirectRenderer.h

@@ -1,51 +0,0 @@
-#ifndef DIRECTRENDERER_H
-#define DIRECTRENDERER_H
-
-#include "client/engine/Wrapper.h"
-#include "client/math/Matrix3D.h"
-#include "client/engine/Texture.h"
-#include "client/engine/Utils.h"
-
-using namespace std;
-
-class DirectRenderer
-{
-public:
-    DirectRenderer();
-    DirectRenderer(const DirectRenderer& orig);
-    virtual ~DirectRenderer();
-    
-    void drawRectangle(float minX, float minY, float maxX, float maxY, float tMinX, float tMinY, float tMaxX, float tMaxY, IntColor c);
-    void drawRectangle(float minX, float minY, float maxX, float maxY, IntColor c);
-    void drawRectangle(float minX, float minY, float maxX, float maxY, float tMinX, float tMinY, float tMaxX, float tMaxY);
-    
-    float drawString(float x, float y, bool shadow, string& s);
-    void getStringSize(float& width, float& height, string& s);
-    
-private:
-    float addString(float x, float y, int& index, float* data, const IntColor* color, string& s);
-    
-    static const int FONTS_LENGTH = 3;
-    Texture FONTS[FONTS_LENGTH]
-    {
-        Texture("resources/font8x8.png"), Texture("resources/font16x16.png"), Texture("resources/font24x24.png")
-    };
-    
-    static const char COLOR_CHAR = '&';
-
-    static const unsigned int FONT_SIZE = 8;
-    static const unsigned int LINE_STEP = 1;
-    static const unsigned int SHADOW_STEP = 1;
-    static const unsigned int MAX_STRING_LENGTH = 1024;
-    
-    static const int OBJECT_LENGTH = 96;
-    static const int BUFFER_LENGTH = 256 * 1024 * OBJECT_LENGTH;
-
-    GLuint vba = 0;
-    GLuint vbo = 0;
-
-    unsigned int offset = BUFFER_LENGTH - OBJECT_LENGTH;
-};
-
-#endif
-

+ 0 - 254
client/engine/Mesh.cpp

@@ -1,254 +0,0 @@
-#include <cstring>
-#include <iostream>
-
-#include "client/engine/Mesh.h"
-
-using namespace std;
-
-Mesh::Mesh(int mode)
-{
-    // position
-    positionStartIndex = vertexSize;
-    vertexSize += 3;
-    
-    // color
-    if(mode & COLOR)
-    {
-        colorStartIndex = vertexSize;
-        vertexSize += 4;
-    }
-    
-    // texture
-    if(mode & TEXTURE)
-    {
-        textureStartIndex = vertexSize;
-        vertexSize += 2;
-    }
-    
-    // normal
-    if(mode & NORMAL)
-    {
-        normalStartIndex = vertexSize;
-        vertexSize += 3;
-    }
-    
-    data = new float[dataSize * vertexSize];
-    
-    glGenVertexArrays(1, &vba);
-    glBindVertexArray(vba);
-    
-    glGenBuffers(1, &vbo);
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-
-    glVertexAttribPointer(0, 3, GL_FLOAT, 0, sizeof(float) * vertexSize, (GLvoid*) (sizeof(float) * positionStartIndex));
-    glEnableVertexAttribArray(0);
-
-    glVertexAttribPointer(1, 4, GL_FLOAT, 0, sizeof(float) * vertexSize, (GLvoid*) (sizeof(float) * colorStartIndex));
-    glEnableVertexAttribArray(1);     
-    
-    glVertexAttribPointer(2, 2, GL_FLOAT, 0, sizeof(float) * vertexSize, (GLvoid*) (sizeof(float) * textureStartIndex));
-    glEnableVertexAttribArray(2);  
-    
-    glVertexAttribPointer(3, 3, GL_FLOAT, 0, sizeof(float) * vertexSize, (GLvoid*) (sizeof(float) * normalStartIndex));
-    glEnableVertexAttribArray(3);
-}
-
-Mesh::~Mesh()
-{
-    delete[] data;
-    glDeleteVertexArrays(1, &vba);
-    glDeleteBuffers(1, &vbo);
-}
-
-void Mesh::ensureCapacity(unsigned int index)
-{
-    if(index >= dataSize)
-    {
-        float* newData = new float[dataSize * 2 * vertexSize];
-        memcpy(newData, data, sizeof(float) * dataSize * vertexSize);
-        delete[] data;
-        data = newData;
-        dataSize *= 2;
-    }
-}
-
-void Mesh::addPosition(float x, float y, float z)
-{
-    ensureCapacity(positionIndex);
-    unsigned int index = positionStartIndex +  positionIndex * vertexSize;
-    data[index] = x;
-    data[index + 1] = y;
-    data[index + 2] = z;
-    positionIndex++;
-}
-
-void Mesh::addColor(float r, float g, float b, float a)
-{
-    ensureCapacity(colorIndex);
-    unsigned int index = colorStartIndex +  colorIndex * vertexSize;
-    data[index] = r;
-    data[index + 1] = g;
-    data[index + 2] = b;
-    data[index + 3] = a;
-    colorIndex++;
-}
-
-void Mesh::addTexture(float tx, float ty)
-{
-    ensureCapacity(textureIndex);
-    unsigned int index = textureStartIndex +  textureIndex * vertexSize;
-    data[index] = tx;
-    data[index + 1] = ty;
-    textureIndex++;
-}
-
-void Mesh::addNormal(float nx, float ny, float nz)
-{
-    ensureCapacity(normalIndex);
-    unsigned int index = normalStartIndex +  normalIndex * vertexSize;
-    data[index] = nx;
-    data[index + 1] = ny;
-    data[index + 2] = nz;
-    normalIndex++;
-}
-
-void Mesh::build(bool print)
-{
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-   
-    vertices = positionIndex;
-    
-    if(print)
-    {
-        cout << "______________" << vertices << " " << vertexSize << endl;
-        for(unsigned int i = 0; i < vertices; i++)
-        {
-            cout << "----------vert " << i << endl;
-            unsigned int index = i * vertexSize;
-            for(unsigned int j = 0; j < vertexSize; j++)
-            {
-                cout << data[index + j] << " " << endl;
-            }
-        }
-    }
-    
-    glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertexSize * vertices, data, GL_STATIC_DRAW);
-    
-    positionIndex = 0;
-    colorIndex = 0;
-    textureIndex = 0;
-    normalIndex = 0;
-}
-
-void Mesh::draw()
-{
-    if(vertices == 0)
-    {
-        return;
-    }
-    glBindVertexArray(vba);
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-    glDrawArrays(GL_TRIANGLES, 0, vertices);
-}
-
-void Mesh::draw(unsigned int start, unsigned int count)
-{
-    if(vertices == 0 || start == 0 || start >= vertices || start + count > vertices)
-    {
-        return;
-    }
-    glBindVertexArray(vba);
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-    glDrawArrays(GL_TRIANGLES, start, count);
-}
-
-NormalTextureMesh::NormalTextureMesh() : Mesh(Mesh::NORMAL | Mesh::TEXTURE)
-{
-}
-
-void NormalTextureMesh::addTriangle(
-        float p1x, float p1y, float p1z, float p1nx, float p1ny, float p1nz, float p1texX, float p1texY, 
-        float p2x, float p2y, float p2z, float p2nx, float p2ny, float p2nz, float p2texX, float p2texY, 
-        float p3x, float p3y, float p3z, float p3nx, float p3ny, float p3nz, float p3texX, float p3texY)
-{
-    addPosition(p1x, p1y, p1z);
-    addPosition(p2x, p2y, p2z);
-    addPosition(p3x, p3y, p3z);
-    
-    addNormal(p1nx, p1ny, p1nz);
-    addNormal(p2nx, p2ny, p2nz);
-    addNormal(p3nx, p3ny, p3nz);
-    
-    addTexture(p1texX, p1texY);
-    addTexture(p2texX, p2texY);
-    addTexture(p3texX, p3texY);
-}
-
-void NormalTextureMesh::addCuboid(float sx, float sy, float sz, float ex, float ey, float ez,
-        float topTexStartX, float topTexStartY, float topTexEndX, float topTexEndY, 
-        float bottomTexStartX, float bottomTexStartY, float bottomTexEndX, float bottomTexEndY, 
-        float northTexStartX, float northTexStartY, float northTexEndX, float northTexEndY, 
-        float southTexStartX, float southTexStartY, float southTexEndX, float southTexEndY, 
-        float eastTexStartX, float eastTexStartY, float eastTexEndX, float eastTexEndY, 
-        float westTexStartX, float westTexStartY, float westTexEndX, float westTexEndY)
-{
-    // bottom side
-    addTriangle(
-            sx, sy, sz, 0.0f, -1.0f, 0.0f, bottomTexStartX, bottomTexStartY,
-            ex, sy, sz, 0.0f, -1.0f, 0.0f, bottomTexEndX, bottomTexStartY,
-            sx, sy, ez, 0.0f, -1.0f, 0.0f, bottomTexStartX, bottomTexEndY);
-    addTriangle(
-            ex, sy, sz, 0.0f, -1.0f, 0.0f, bottomTexEndX, bottomTexStartY,
-            ex, sy, ez, 0.0f, -1.0f, 0.0f, bottomTexEndX, bottomTexEndY,
-            sx, sy, ez, 0.0f, -1.0f, 0.0f, bottomTexStartX, bottomTexEndY);
-    
-    // top side
-    addTriangle(
-            sx, ey, sz, 0.0f, 1.0f, 0.0f, topTexStartX, topTexStartY,
-            sx, ey, ez, 0.0f, 1.0f, 0.0f, topTexStartX, topTexEndY,
-            ex, ey, sz, 0.0f, 1.0f, 0.0f, topTexEndX, topTexStartY);
-    addTriangle(
-            ex, ey, sz, 0.0f, 1.0f, 0.0f, topTexEndX, topTexStartY,
-            sx, ey, ez, 0.0f, 1.0f, 0.0f, topTexStartX, topTexEndY,
-            ex, ey, ez, 0.0f, 1.0f, 0.0f, topTexEndX, topTexEndY);
-    
-    // north side
-    addTriangle(
-            ex, sy, sz, 1.0f, 0.0f, 0.0f, northTexStartX, northTexEndY,
-            ex, ey, ez, 1.0f, 0.0f, 0.0f, northTexEndX, northTexStartY,
-            ex, sy, ez, 1.0f, 0.0f, 0.0f, northTexEndX, northTexEndY);
-    addTriangle(
-            ex, sy, sz, 1.0f, 0.0f, 0.0f, northTexStartX, northTexEndY,
-            ex, ey, sz, 1.0f, 0.0f, 0.0f, northTexStartX, northTexStartY,
-            ex, ey, ez, 1.0f, 0.0f, 0.0f, northTexEndX, northTexStartY);
-    
-    // south side
-    addTriangle(
-            sx, sy, sz, -1.0f, 0.0f, 0.0f, southTexStartX, southTexEndY,
-            sx, sy, ez, -1.0f, 0.0f, 0.0f, southTexEndX, southTexEndY,
-            sx, ey, ez, -1.0f, 0.0f, 0.0f, southTexEndX, southTexStartY);
-    addTriangle(
-            sx, sy, sz, -1.0f, 0.0f, 0.0f, southTexStartX, southTexEndY,
-            sx, ey, ez, -1.0f, 0.0f, 0.0f, southTexEndX, southTexStartY,
-            sx, ey, sz, -1.0f, 0.0f, 0.0f, southTexStartX, southTexStartY);
-    
-    // east side
-    addTriangle(
-            sx, sy, ez, 0.0f, 0.0f, 1.0f, eastTexStartX, eastTexEndY,
-            ex, sy, ez, 0.0f, 0.0f, 1.0f, eastTexEndX, eastTexEndY,
-            ex, ey, ez, 0.0f, 0.0f, 1.0f, eastTexEndX, eastTexStartY);
-    addTriangle(
-            sx, sy, ez, 0.0f, 0.0f, 1.0f, eastTexStartX, eastTexEndY,
-            ex, ey, ez, 0.0f, 0.0f, 1.0f, eastTexEndX, eastTexStartY,
-            sx, ey, ez, 0.0f, 0.0f, 1.0f, eastTexStartX, eastTexStartY);
-    
-    // west side
-    addTriangle(
-            sx, sy, sz, 0.0f, 0.0f, -1.0f, westTexStartX, westTexEndY,
-            ex, ey, sz, 0.0f, 0.0f, -1.0f, westTexEndX, westTexStartY,
-            ex, sy, sz, 0.0f, 0.0f, -1.0f, westTexEndX, westTexEndY);
-    addTriangle(
-            sx, sy, sz, 0.0f, 0.0f, -1.0f, westTexStartX, westTexEndY,
-            sx, ey, sz, 0.0f, 0.0f, -1.0f, westTexStartX, westTexStartY,
-            ex, ey, sz, 0.0f, 0.0f, -1.0f, westTexEndX, westTexStartY);
-}

+ 0 - 66
client/engine/Mesh.h

@@ -1,66 +0,0 @@
-#ifndef MESH_H
-#define MESH_H
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-class Mesh
-{
-public:
-    Mesh(int mode);
-    virtual ~Mesh();
-    
-    void addPosition(float x, float y, float z);
-    void addColor(float r, float g, float b, float a);
-    void addTexture(float tx, float ty);
-    void addNormal(float nx, float ny, float nz);
-    
-    void build(bool print = false);
-    void draw();
-    void draw(unsigned int start, unsigned int count);
-    
-    static const int COLOR = 1;
-    static const int TEXTURE = 2;
-    static const int NORMAL = 4;
-private:
-    void ensureCapacity(unsigned int index);
-    
-    GLuint vba = 0;
-    GLuint vbo = 0;
-    
-    unsigned int positionStartIndex = 0;
-    unsigned int colorStartIndex = 0;
-    unsigned int textureStartIndex = 0;
-    unsigned int normalStartIndex = 0;
-    
-    unsigned int positionIndex = 0;
-    unsigned int colorIndex = 0;
-    unsigned int textureIndex = 0;
-    unsigned int normalIndex = 0;
-    
-    unsigned int vertexSize = 0;
-    unsigned int vertices = 0;
-    unsigned int dataSize = 3;
-    
-    float* data = nullptr;
-};
-
-class NormalTextureMesh : public Mesh
-{
-public:
-    NormalTextureMesh();
-    
-    void addTriangle(float p1x, float p1y, float p1z, float p1nx, float p1ny, float p1nz, float p1texX, float p1texY, 
-            float p2x, float p2y, float p2z, float p2nx, float p2ny, float p2nz, float p2texX, float p2texY, 
-            float p3x, float p3y, float p3z, float p3nx, float p3ny, float p3nz, float p3texX, float p3texY);
-    void addCuboid(float sx, float sy, float sz, float ex, float ey, float ez,
-            float topTexStartX, float topTexStartY, float topTexEndX, float topTexEndY, 
-            float bottomTexStartX, float bottomTexStartY, float bottomTexEndX, float bottomTexEndY, 
-            float northTexStartX, float northTexStartY, float northTexEndX, float northTexEndY, 
-            float southTexStartX, float southTexStartY, float southTexEndX, float southTexEndY, 
-            float eastTexStartX, float eastTexStartY, float eastTexEndX, float eastTexEndY, 
-            float westTexStartX, float westTexStartY, float westTexEndX, float westTexEndY);
-};
-
-#endif
-

+ 0 - 69
client/engine/MouseManager.cpp

@@ -1,69 +0,0 @@
-#include "client/engine/MouseManager.h"
-
-MouseManager::MouseManager()
-{
-    for(int i = 0; i < NUMBER_OF_BUTTONS; i++)
-    {
-        mappingArray[i] = 0;
-    }
-}
-
-bool MouseManager::isDown(int mapping)
-{
-    return isInRange(mapping) && mouseArray[mappingArray[mapping]].down;
-}
-
-bool MouseManager::isReleased(int mapping)
-{
-    return isInRange(mapping) && mouseArray[mappingArray[mapping]].shouldRelease;
-}
-
-unsigned int MouseManager::getDownTime(int mapping)
-{
-    bool m = isInRange(mapping);
-    return m * mouseArray[mappingArray[mapping * m]].downTime;
-}
-
-void MouseManager::resetDownTime(int mapping)
-{
-    mouseArray[mappingArray[mapping * isInRange(mapping)]].downTime = 0;
-}
-
-bool MouseManager::map(int mapping, int mouse)
-{
-    bool b = isInRange(mapping) && isInRange(mouse);
-    mappingArray[mapping * b] = b * mouse;
-    return b;
-}
-
-bool MouseManager::isInRange(int i)
-{
-    return i >= 0 && i < NUMBER_OF_BUTTONS;
-}
-
-void MouseManager::tick()
-{
-    for(int i = 0; i < NUMBER_OF_BUTTONS; i++)
-    {
-        mouseArray[i].downTime += mouseArray[i].down;
-        
-        mouseArray[i].down = mouseArray[i].down && !mouseArray[i].shouldRelease;
-        mouseArray[i].downTime *= !mouseArray[i].shouldRelease;
-        mouseArray[i].shouldRelease = false;
-    }
-}
-
-void MouseManager::press(int mouse)
-{
-    int index = isInRange(mouse) * mouse;
-    mouseArray[index].down = true;
-    mouseArray[index].shouldRelease = false;
-}
-
-void MouseManager::release(int mouse)
-{
-    int index = isInRange(mouse) * mouse;
-    mouseArray[index].shouldRelease = true;
-}
-
-

+ 0 - 38
client/engine/MouseManager.h

@@ -1,38 +0,0 @@
-#ifndef MOUSE_H
-#define MOUSE_H
-
-#include <GLFW/glfw3.h>
-
-class MouseManager
-{
-public:
-    MouseManager();
-    
-    bool isDown(int mapping);
-    bool isReleased(int mapping);
-    unsigned int getDownTime(int mapping);
-    void resetDownTime(int mapping);
-    bool map(int mapping, int key);
-    
-    void tick();
-    void press(int button);
-    void release(int button);
-    
-private:
-    static const int NUMBER_OF_BUTTONS = GLFW_MOUSE_BUTTON_LAST + 1;
-    
-    bool isInRange(int i);
-    
-    struct Mouse
-    {
-        bool down = false;
-        bool shouldRelease = false;
-        unsigned int downTime = 0;
-    };
-    
-    Mouse mouseArray[NUMBER_OF_BUTTONS];
-    int mappingArray[NUMBER_OF_BUTTONS];
-};
-
-#endif
-

+ 0 - 70
client/engine/Shader.cpp

@@ -1,70 +0,0 @@
-#include <cmath>
-
-#include "client/engine/Shader.h"
-#include "client/engine/Utils.h"
-#include "client/engine/Wrapper.h"
-
-void Shader::pop()
-{
-    model.pop();
-}
-
-void Shader::push()
-{
-    model.push();
-}
-
-void Shader::setToIdentity()
-{
-    model.get().setToIdentity();
-}
-
-void Shader::scale(float sx, float sy, float sz)
-{
-    model.get().scale(sx, sy, sz);
-}
-
-void Shader::translate(float tx, float ty, float tz)
-{
-    model.get().translate(tx, ty, tz);
-}
-
-void Shader::translateX(float tx)
-{
-    model.get().translateX(tx);
-}
-
-void Shader::translateY(float ty)
-{
-    model.get().translateY(ty);
-}
-
-void Shader::translateZ(float tz)
-{
-    model.get().translateZ(tz);
-}
-
-void Shader::translateTo(float tx, float ty, float tz)
-{
-    model.get().translateTo(tx, ty, tz);
-}
-
-void Shader::rotateX(float degrees)
-{
-    model.get().rotateX(degrees);
-}
-
-void Shader::rotateY(float degrees)
-{
-    model.get().rotateY(degrees);
-}
-
-void Shader::rotateZ(float degrees)
-{
-    model.get().rotateZ(degrees);
-}
-
-void Shader::updateModelMatrix()
-{
-    Engine::setModelMatrix(model.get().getValues());
-}

+ 0 - 32
client/engine/Shader.h

@@ -1,32 +0,0 @@
-#ifndef CAMERA_H
-#define CAMERA_H
-
-#include "client/math/Plane3D.h"
-#include "client/math/Vector3D.h"
-#include "client/math/Matrix3D.h"
-#include "client/math/Matrix3DStack.h"
-
-class Shader
-{
-public:
-    void pop();
-    void push();
-    void setToIdentity();
-    void scale(float sx, float sy, float sz);
-    void translate(float tx, float ty, float tz);
-    void translateX(float tx);
-    void translateY(float ty);
-    void translateZ(float tz);
-    void translateTo(float tx, float ty, float tz);
-    void rotateX(float degrees);
-    void rotateY(float degrees);
-    void rotateZ(float degrees);
-    
-    void updateModelMatrix();
-
-private:
-    Matrix3DStack model;
-};
-
-#endif
-

+ 0 - 34
client/engine/Texture.h

@@ -1,34 +0,0 @@
-#ifndef TEXTURE_H
-#define TEXTURE_H
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-#include <iostream>
-
-using namespace std;
-
-class Texture
-{
-public:
-    Texture(const char* path);
-    virtual ~Texture();
-    
-    void bind();
-    bool isLoaded();
-private:
-    bool load(const char* path);
-    bool load(const char* path, FILE* file);
-    void initGL();
-    
-    bool loaded = false;
-    
-    unsigned int width = 0;
-    unsigned int height = 0;
-    unsigned int* data = nullptr;
-    
-    GLuint texture = 0;
-};
-
-#endif
-
-

+ 0 - 6
client/engine/Utils.cpp

@@ -1,6 +0,0 @@
-#include "client/engine/Utils.h"
-
-float interpolate(float lag, float from, float to)
-{
-    return from + lag * (to - from);
-}

+ 0 - 67
client/engine/Utils.h

@@ -1,67 +0,0 @@
-#ifndef UTILS_H
-#define UTILS_H
-
-float interpolate(float lag, float from, float to);
-
-typedef unsigned int IntColor;
-
-namespace Color
-{
-    constexpr IntColor getColor(unsigned int r, unsigned int g, unsigned int b)
-    {
-        return ((r & 0xFF) << 0) | ((g & 0xFF) << 8) | ((b & 0xFF) << 16) | 0xFF000000;
-    }
-
-    constexpr IntColor getDarkerColor(unsigned int r, unsigned int g, unsigned int b)
-    {
-        r *= 0.5;
-        g *= 0.5;
-        b *= 0.5;
-        return ((r & 0xFF) << 0) | ((g & 0xFF) << 8) | ((b & 0xFF) << 16) | 0xFF000000;
-    }
-
-    constexpr int COLOR_AMOUNT = 16;
-    
-    constexpr IntColor COLORS[COLOR_AMOUNT]
-    {
-        getColor(0, 0, 0),
-        getColor(0, 0, 170),
-        getColor(0, 170, 0),
-        getColor(0, 170, 170),
-        getColor(170, 0, 0),
-        getColor(170, 0, 170),
-        getColor(255, 170, 0),
-        getColor(170, 170, 170),
-        getColor(85, 85, 85),
-        getColor(85, 85, 255),
-        getColor(85, 255, 85),
-        getColor(85, 255, 255),
-        getColor(255, 85, 85),
-        getColor(255, 85, 255),
-        getColor(255, 255, 85),
-        getColor(255, 255, 255)
-    };
-
-    constexpr IntColor DARK_COLORS[COLOR_AMOUNT]
-    {
-        getDarkerColor(0, 0, 0),
-        getDarkerColor(0, 0, 170),
-        getDarkerColor(0, 170, 0),
-        getDarkerColor(0, 170, 170),
-        getDarkerColor(170, 0, 0),
-        getDarkerColor(170, 0, 170),
-        getDarkerColor(255, 170, 0),
-        getDarkerColor(170, 170, 170),
-        getDarkerColor(85, 85, 85),
-        getDarkerColor(85, 85, 255),
-        getDarkerColor(85, 255, 85),
-        getDarkerColor(85, 255, 255),
-        getDarkerColor(255, 85, 85),
-        getDarkerColor(255, 85, 255),
-        getDarkerColor(255, 255, 85),
-        getDarkerColor(255, 255, 255)
-    };
-}
-
-#endif
-

+ 0 - 292
client/engine/Wrapper.cpp

@@ -1,292 +0,0 @@
-#include <cmath>
-#include <chrono>
-#include <thread>
-
-#include "client/engine/Wrapper.h"
-
-DummyClient DummyClient::dummy;
-
-IClient* Engine::client = &DummyClient::dummy;
-
-// window data
-GLFWwindow* Engine::window = nullptr;
-int Engine::scale = 1;
-int Engine::width = 0;
-int Engine::height = 0;
-int Engine::resizeTicks = -1;
-
-// projection data
-float Engine::fovY = 60;
-float Engine::nearClip = 0.1f;
-float Engine::farClip = 1000.0f;
-Matrix3D Engine::projMatrix;
-
-// rectangle for framebuffer drawing
-FramebufferRectangle Engine::rectangle;
-
-int Engine::stage = 0;
-// shader stage 1 - world
-WorldShader Engine::worldShader;
-// shader stage 2 - world ssao
-SSAOShader Engine::ssaoShader;
-// shader stage 3 - world ssao blur
-SSAOBlurShader Engine::ssaoBlurShader;
-// shader stage 4 - world post
-WorldPostShader Engine::worldPostShader;
-// shader stage 5 - 2D overlay
-OverlayShader Engine::overlayShader;
-
-void Engine::sleep(uint64_t nanos)
-{
-    uint64_t end = glfwGetTimerValue() + nanos - 10000;
-    // non busy wait until a close range
-    while(end > glfwGetTimerValue() + 1000000)
-    {
-        this_thread::sleep_for(chrono::nanoseconds(1000000));
-    }
-    while(end > glfwGetTimerValue() + 100000)
-    {
-        this_thread::sleep_for(chrono::nanoseconds(100000));
-    }
-    // busy wait for higher accuracy at the end
-    while(end > glfwGetTimerValue());
-}
-
-void Engine::stop()
-{
-    glfwSetWindowShouldClose(window, 1);
-}
-
-void Engine::onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods)
-{
-    client->onKeyEvent(key, scancode, action, mods);
-}
-
-void Engine::onMouseMove(GLFWwindow* w, double x, double y)
-{
-    client->onMouseMove(x, y);
-}
-
-void Engine::onMouseClick(GLFWwindow* w, int button, int action, int mods)
-{
-    client->onMouseClick(button, action, mods);
-}
-
-void Engine::onWindowResize(GLFWwindow* w, int width, int height)
-{
-    Engine::width = width;
-    Engine::height = height;
-    resizeTicks = 10;
-}
-
-void Engine::updateScale()
-{
-    scale = 1;
-    while(width / (scale + 1) >= 400 && height / (scale + 1) >= 300)
-    {
-        scale++;
-    }
-}
-
-int Engine::getScale()
-{
-    return scale;
-}
-
-int Engine::getWidth()
-{
-    return width;
-}
-
-int Engine::getHeight()
-{
-    return height;
-}
-
-float Engine::getScaledWidth()
-{
-    return (float) width / scale;
-}
-
-float Engine::getScaledHeight()
-{
-    return (float) height / scale;
-}
-
-float Engine::getFieldOfView()
-{
-    return fovY;
-}
-
-float Engine::getNearClip()
-{
-    return nearClip;
-}
-
-float Engine::getFarClip()
-{
-    return farClip;
-}
-
-void Engine::printError()
-{
-    GLenum error = glGetError();
-    switch(error)
-    {
-        case GL_NO_ERROR: 
-            //cout << "> No error has been recorded." << endl;
-            break;
-        case GL_INVALID_ENUM: 
-            cout << "> An unacceptable value is specified for an enumerated argument." << endl;
-            break;
-        case GL_INVALID_VALUE: 
-            cout << "> A numeric argument is out of range." << endl;
-            break;
-        case GL_INVALID_OPERATION: 
-            cout << "> The specified operation is not allowed in the current state." << endl;
-            break;
-        case GL_INVALID_FRAMEBUFFER_OPERATION: 
-            cout << "> The framebuffer object is not complete." << endl;
-            break;
-        case GL_OUT_OF_MEMORY: 
-            cout << "> There is not enough memory left to execute the command." << endl;
-            break;
-        case GL_STACK_UNDERFLOW: 
-            cout << "> An attempt has been made to perform an operation that would cause an internal stack to underflow." << endl;
-            break;
-        case GL_STACK_OVERFLOW: 
-            cout << "> An attempt has been made to perform an operation that would cause an internal stack to overflow." << endl;
-            break;
-        default:
-            cout << "> Unknown OpenGL error: " << error << endl;
-    }
-}
-
-void Engine::onRenderTick(float lag)
-{
-    // update projection matrix
-    float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
-    float q = 1.0f / tan;
-    float aspect = (float) width / height;
-
-    projMatrix.set(0, 0, q / aspect);
-    projMatrix.set(1, 1, q);
-    projMatrix.set(2, 2, (nearClip + farClip) / (nearClip - farClip));
-    projMatrix.set(3, 2, -1.0f);
-    projMatrix.set(2, 3, (2.0f * nearClip * farClip) / (nearClip - farClip));
-    projMatrix.set(3, 3, 0); 
-    
-    // -------------------------------------------------------------------------
-    // shader stage 1 - world
-    // -------------------------------------------------------------------------
-    stage = 1;
-    worldShader.preRender(projMatrix.getValues());
-    // call render tick for further drawing
-    client->render3DTick(lag);
-    
-    // -------------------------------------------------------------------------
-    // shader stage 2 - world ssao
-    // -------------------------------------------------------------------------
-    stage = 2;
-    ssaoShader.preRender(projMatrix.getValues());
- 
-    // bind previously generated texture data buffers
-    worldShader.bindPositionTexture(1);
-    worldShader.bindNormalTexture(2);
-    worldShader.bindColorTexture(3);
-    worldShader.bindDepthTexture(4);
-    ssaoShader.bindNoiseTexture(5);
-    
-    rectangle.draw();
-    
-    // -------------------------------------------------------------------------
-    // shader stage 3 - world ssao blur
-    // -------------------------------------------------------------------------
-    stage = 3;
-    ssaoBlurShader.preRender();
-    ssaoShader.bindTexture(6);
-    rectangle.draw();
-    
-    // -------------------------------------------------------------------------
-    // shader stage 4 - world post
-    // -------------------------------------------------------------------------
-    stage = 4;
-    worldPostShader.preRender();
-    ssaoBlurShader.bindTexture(7);
-    rectangle.draw();
-    
-    // -------------------------------------------------------------------------
-    // shader stage 5 - 2D overlay
-    // -------------------------------------------------------------------------
-    stage = 5;
-    overlayShader.preRender();
-    worldPostShader.bindTexture(0);
-    rectangle.draw();
-    overlayShader.setViewMatrix();
-    
-    setMixMode();
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glBlendEquation(GL_FUNC_ADD);
-    client->render2DTick(lag);
-    glDisable(GL_BLEND);
-}
-
-void Engine::setViewMatrix(const float* data)
-{
-    if(stage == 1)
-    {
-        worldShader.setViewMatrix(data);
-    }
-}
-
-void Engine::setModelMatrix(const float* data)
-{
-    if(stage == 1)
-    {
-        worldShader.setModelMatrix(data);
-    }
-    else if(stage == 5)
-    {
-        overlayShader.setModelMatrix(data);
-    }
-}
-
-void Engine::setMouseTrapped(bool mode)
-{
-    if(mode)
-    {
-        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
-    }
-    else
-    {
-        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
-    }
-}
-
-void Engine::setMixMode()
-{
-    if(stage == 5)
-    {
-        overlayShader.setUseColor(true);
-        overlayShader.setUseTexture(true);
-    }
-}
-
-void Engine::setColorMode()
-{
-    if(stage == 5)
-    {
-        overlayShader.setUseColor(true);
-        overlayShader.setUseTexture(false);
-    }
-}
-
-void Engine::setTextureMode()
-{
-    if(stage == 5)
-    {
-        overlayShader.setUseColor(false);
-        overlayShader.setUseTexture(true);
-    }
-}

+ 0 - 127
client/engine/Wrapper.h

@@ -1,127 +0,0 @@
-#ifndef WRAPPER_H
-#define WRAPPER_H
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-#include <iostream>
-
-#include "client/engine/shader/ShaderProgram.h"
-#include "client/math/Vector3D.h"
-#include "client/math/Matrix3D.h"
-#include "client/engine/shader/WorldShader.h"
-#include "client/engine/shader/SSAOShader.h"
-#include "client/engine/shader/SSAOBlurShader.h"
-#include "client/engine/shader/FramebufferRectangle.h"
-#include "client/engine/shader/WorldPostShader.h"
-#include "client/engine/shader/OverlayShader.h"
-#include "client/engine/Mesh.h"
-#include "client/engine/Shader.h"
-
-using namespace std;
-
-class IClient
-{
-public:
-    virtual ~IClient() = default;
-    virtual void tick() = 0;
-    virtual void render3DTick(float lag) = 0;
-    virtual void render2DTick(float lag) = 0;
-    virtual void onKeyEvent(int key, int scancode, int action, int mods) = 0;
-    virtual void onMouseMove(double x, double y) = 0;
-    virtual void onMouseClick(int button, int action, int mods) = 0;
-};
-
-class DummyClient : public IClient
-{
-public:
-    static DummyClient dummy;
-    
-    void tick() override { cout << "Dummy tick" << endl; };
-    void render3DTick(float lag) override { cout << "Dummy render3DTick" << endl; };
-    void render2DTick(float lag) override { cout << "Dummy render3DTick" << endl; };
-    void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; };
-    void onMouseMove(double x, double y) override { cout << "Dummy onMouseMove" << endl; };
-    void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; };
-private:
-    DummyClient() {};
-};
-
-class Engine
-{
-public:
-    static bool init(int width, int height, const char* name);
-    static void start(IClient* client);
-    static void stop();
-    
-    static void printError();
-    
-    static int getScale();
-    static int getWidth();
-    static int getHeight();
-    static float getScaledWidth();
-    static float getScaledHeight();
-    
-    static float getFieldOfView();
-    static float getNearClip();
-    static float getFarClip();
-    
-    static void setMouseTrapped(bool mode);
-    
-    static void setMixMode();
-    static void setColorMode();
-    static void setTextureMode();
-
-private:
-    friend void Shader::updateModelMatrix();
-    
-    static const uint64_t NANOS_PER_FRAME = 1000000000 / 60;
-    static const uint64_t NANOS_PER_TICK = 50000000;
-    static const int MAX_TICKS_PER_FRAME = 1;
-    
-    static void sleep(uint64_t nanos);
-    static bool initOverlayShader();   
-    
-    static void onRenderTick(float lag);
-    
-    static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods);
-    static void onMouseMove(GLFWwindow* w, double x, double y);
-    static void onMouseClick(GLFWwindow* w, int button, int action, int mods);
-    static void onWindowResize(GLFWwindow* w, int width, int height);
-    
-    static void setViewMatrix(const float* data);
-    static void setModelMatrix(const float* data);
-
-    static void updateScale();
-    
-    static IClient* client;    
-    
-    // window data
-    static GLFWwindow* window;  
-    static int scale;
-    static int width;
-    static int height;
-    static int resizeTicks;
-    
-    // projection data
-    static float fovY;
-    static float nearClip;
-    static float farClip;
-    static Matrix3D projMatrix;
-    
-    // rectangle for framebuffer drawing
-    static FramebufferRectangle rectangle;
-    
-    static int stage;
-    // shader stage 1 - world
-    static WorldShader worldShader;
-    // shader stage 2 - world ssao
-    static SSAOShader ssaoShader;
-    // shader stage 3 - world ssao blur
-    static SSAOBlurShader ssaoBlurShader;
-    // shader stage 4 - world post
-    static WorldPostShader worldPostShader;
-    // shader stage 5 - 2D overlay
-    static OverlayShader overlayShader;
-};
-
-#endif

+ 0 - 51
client/engine/shader/FramebufferRectangle.cpp

@@ -1,51 +0,0 @@
-#include "client/engine/shader/FramebufferRectangle.h"
-#include "client/engine/Wrapper.h"
-
-FramebufferRectangle::FramebufferRectangle()
-{
-}
-
-FramebufferRectangle::~FramebufferRectangle()
-{
-    glDeleteVertexArrays(1, &vba);
-    glDeleteBuffers(1, &vbo);
-}
-
-bool FramebufferRectangle::init()
-{
-    glGenVertexArrays(1, &vba);
-    glBindVertexArray(vba);
-    
-    glGenBuffers(1, &vbo);
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-
-    glVertexAttribPointer(0, 2, GL_FLOAT, 0, sizeof(float) * 4, (GLvoid*) 0);
-    glEnableVertexAttribArray(0);
-
-    glVertexAttribPointer(2, 2, GL_FLOAT, 0, sizeof(float) * 4, (GLvoid*) (sizeof(float) * 2));
-    glEnableVertexAttribArray(2);
-    
-    Engine::printError();
-    
-    float data[] = 
-    {
-        -1.0f, 1.0f, 0.0f, 1.0f, 
-        -1.0f, -1.0f, 0.0f, 0.0f,
-        1.0f, -1.0f, 1.0f, 0.0f,
-        -1.0f, 1.0f, 0.0f, 1.0f,
-        1.0f, -1.0f, 1.0f, 0.0f,
-        1.0f, 1.0f, 1.0f, 1.0f
-    };
-    
-    glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 24, data, GL_STATIC_DRAW);
-    
-    return true;
-}
-
-void FramebufferRectangle::draw()
-{
-    glBindVertexArray(vba);
-    glBindBuffer(GL_ARRAY_BUFFER, vbo);
-    glDrawArrays(GL_TRIANGLES, 0, 6);
-}
-

+ 0 - 21
client/engine/shader/FramebufferRectangle.h

@@ -1,21 +0,0 @@
-#ifndef FRAMEBUFFERRECTANGLE_H
-#define FRAMEBUFFERRECTANGLE_H
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-class FramebufferRectangle
-{
-public:
-    FramebufferRectangle();
-    virtual ~FramebufferRectangle();
-    
-    bool init();
-    void draw();
-private:
-    GLuint vba;
-    GLuint vbo;
-};
-
-#endif
-

+ 0 - 91
client/engine/shader/OverlayShader.cpp

@@ -1,91 +0,0 @@
-#include "client/engine/shader/OverlayShader.h"
-#include "client/engine/Wrapper.h"
-
-OverlayShader::OverlayShader()
-{
-}
-
-OverlayShader::~OverlayShader()
-{
-}
-
-bool OverlayShader::init()
-{
-    program.compile("resources/shader/overlayVertex.vs", "resources/shader/overlayFragment.fs");
-    if(!program.isValid())
-    {
-        return false;
-    } 
-    
-    // get uniform locations
-    unifUseTexture = glGetUniformLocation(program.getProgram(), "useTexture");
-    unifUseColor = glGetUniformLocation(program.getProgram(), "useColor");
-    unifViewMatrix = glGetUniformLocation(program.getProgram(), "viewMatrix");
-    unifModelMatrix = glGetUniformLocation(program.getProgram(), "modelMatrix");
-
-    return true;
-}
-
-void OverlayShader::preRender()
-{
-    // bind overlay shader program
-    glUseProgram(program.getProgram());
-    
-    // reset view and model matrix
-    view.setToIdentity();
-    glUniformMatrix4fv(unifViewMatrix, 1, 0, view.getValues());
-    glUniformMatrix4fv(unifModelMatrix, 1, 0, view.getValues());
-    
-    // set defaults
-    setUseTexture(true);
-    setUseColor(false);
-    
-    // reset to default framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    
-    // clear color buffer
-    glClear(GL_COLOR_BUFFER_BIT);
-    
-    // depth testing is not needed
-    glDisable(GL_DEPTH_TEST);
-}
-
-void OverlayShader::setViewMatrix()
-{
-    view.set(0, 0, (2.0f * Engine::getScale()) / Engine::getWidth());
-    view.set(0, 1, 0.0f);
-    view.set(0, 2, 0.0f);
-    view.set(0, 3, -1.0f);
-    
-    view.set(1, 0, 0.0f);
-    view.set(1, 1, (-2.0f * Engine::getScale()) / Engine::getHeight());
-    view.set(1, 2, 0.0f);
-    view.set(1, 3, 1.0f);
-    
-    view.set(2, 0, 0.0f);
-    view.set(2, 1, 0.0f);
-    view.set(2, 2, (-1.0f * Engine::getScale()) / Engine::getHeight());
-    view.set(2, 3, 0.5f);
-    
-    view.set(3, 0, 0.0f);
-    view.set(3, 1, 0.0f);
-    view.set(3, 0, 0.0f);
-    view.set(3, 3, 1.0f);
-    
-    glUniformMatrix4fv(unifViewMatrix, 1, 0, view.getValues());
-}
-
-void OverlayShader::setModelMatrix(const float* data)
-{
-    glUniformMatrix4fv(unifModelMatrix, 1, 0, data);
-}
-
-void OverlayShader::setUseTexture(bool use)
-{
-    glUniform1i(unifUseTexture, use);
-}
-
-void OverlayShader::setUseColor(bool use)
-{
-    glUniform1i(unifUseColor, use);
-}

+ 0 - 34
client/engine/shader/OverlayShader.h

@@ -1,34 +0,0 @@
-#ifndef OVERLAYSHADER_H
-#define OVERLAYSHADER_H
-
-#include "client/engine/shader/ShaderProgram.h"
-#include "client/math/Matrix3D.h"
-
-class OverlayShader
-{
-public:
-    OverlayShader();
-    virtual ~OverlayShader();
-    
-    bool init();
-    
-    void preRender();
-
-    void setViewMatrix();
-    void setModelMatrix(const float* data);
-    void setUseTexture(bool use);
-    void setUseColor(bool use);
-    
-private:
-    // shader
-    ShaderProgram program;
-    // uniform data
-    Matrix3D view;
-    // uniforms locations
-    GLint unifUseTexture = 0;
-    GLint unifUseColor = 0;
-    GLint unifViewMatrix = 0;
-    GLint unifModelMatrix = 0;
-};
-
-#endif

+ 0 - 73
client/engine/shader/SSAOBlurShader.cpp

@@ -1,73 +0,0 @@
-#include "client/engine/shader/SSAOBlurShader.h"
-#include "client/engine/Wrapper.h"
-
-SSAOBlurShader::SSAOBlurShader()
-{
-}
-
-SSAOBlurShader::~SSAOBlurShader()
-{
-    glDeleteFramebuffers(1, &framebuffer);
-    glDeleteTextures(1, &texture);
-}
-
-bool SSAOBlurShader::init()
-{
-    program.compile("resources/shader/ssaoBlurVertex.vs", "resources/shader/ssaoBlurFragment.fs");
-    if(!program.isValid())
-    {
-        return false;
-    }
-    
-    // generate framebuffer
-    glGenFramebuffers(1, &framebuffer);
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // color texture
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    // attache color texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);  
-    
-    // check if framebuffer is okay
-    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
-    {
-	cout << "ssao blur frame buffer is not complete!" << endl;
-        return false;
-    }
-    // unbind framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
-    return true;
-}
-
-void SSAOBlurShader::resize()
-{
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-}
-
-void SSAOBlurShader::preRender()
-{
-    // bind ssao blur shader program
-    glUseProgram(program.getProgram());
-    
-    // bind ssao blur framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    //glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    
-    // clear color buffer
-    glClear(GL_COLOR_BUFFER_BIT);
-    
-    // depth testing is not needed
-    glDisable(GL_DEPTH_TEST);
-}
-
-void SSAOBlurShader::bindTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, texture);
-}

+ 0 - 29
client/engine/shader/SSAOBlurShader.h

@@ -1,29 +0,0 @@
-#ifndef SSAOBLURSHADER_H
-#define SSAOBLURSHADER_H
-
-#include "client/engine/shader/ShaderProgram.h"
-
-class SSAOBlurShader
-{
-public:
-    SSAOBlurShader();
-    virtual ~SSAOBlurShader();
-    
-    bool init();
-    void resize();
-
-    void preRender();
-    
-    void bindTexture(unsigned int textureUnit);
-    
-private:
-    // shader
-    ShaderProgram program;
-    // framebuffer
-    GLuint framebuffer = 0;
-    // textures
-    GLuint texture = 0;
-};
-
-#endif
-

+ 0 - 136
client/engine/shader/SSAOShader.cpp

@@ -1,136 +0,0 @@
-#include <random>
-
-#include "client/engine/shader/SSAOShader.h"
-#include "client/engine/Wrapper.h"
-
-SSAOShader::SSAOShader()
-{
-}
-
-SSAOShader::~SSAOShader()
-{
-    glDeleteFramebuffers(1, &framebuffer);
-    glDeleteTextures(1, &texture);
-    glDeleteTextures(1, &noiseTexture);
-}
-
-bool SSAOShader::init()
-{
-    program.compile("resources/shader/ssaoVertex.vs", "resources/shader/ssaoFragment.fs");
-    if(!program.isValid())
-    {
-        return false;
-    }
-    
-    // generate framebuffer
-    glGenFramebuffers(1, &framebuffer);
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // color texture
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    // attache color texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);  
-    
-    // check if framebuffer is okay
-    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
-    {
-	cout << "ssao frame buffer is not complete!" << endl;
-        return false;
-    }
-    // unbind framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    
-    // generate noise data
-    std::uniform_real_distribution<float> randomF(0.0, 1.0);
-    std::default_random_engine gen;
-    float noise[48];
-    for(int i = 0; i < 16; i++)
-    {
-        noise[i * 3] = randomF(gen) * 2.0 - 1.0;
-        noise[i * 3 + 1] = randomF(gen) * 2.0 - 1.0;
-        noise[i * 3 + 2] = 0.0f;
-    }  
-    
-    // noise texture
-    glGenTextures(1, &noiseTexture);
-    glBindTexture(GL_TEXTURE_2D, noiseTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 4, 4, 0, GL_RGB, GL_FLOAT, noise);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
-    
-    // get uniform locations
-    unifProjMatrix = glGetUniformLocation(program.getProgram(), "projMatrix");
-    unifNumberOfSamples = glGetUniformLocation(program.getProgram(), "numberOfSamples");
-    unifRadius = glGetUniformLocation(program.getProgram(), "radius");
-    unifWidth = glGetUniformLocation(program.getProgram(), "width");
-    unifHeight = glGetUniformLocation(program.getProgram(), "height");
-    
-    return true;
-}
-
-void SSAOShader::resize()
-{
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-}
-
-void SSAOShader::preRender(const float* projMatrix)
-{
-    // bind ssao shader program
-    glUseProgram(program.getProgram());
-    
-    // set projection matrix uniform
-    glUniformMatrix4fv(unifProjMatrix, 1, 0, projMatrix);
-    // set other uniforms
-    glUniform1i(unifNumberOfSamples, numberOfSamples);
-    glUniform1f(unifRadius, radius);
-    glUniform1i(unifWidth, Engine::getWidth());
-    glUniform1i(unifHeight, Engine::getHeight());
-    
-    // bind ssao framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // clear color buffer
-    glClear(GL_COLOR_BUFFER_BIT);
-    
-    // depth testing is not needed
-    glDisable(GL_DEPTH_TEST);
-}
-
-void SSAOShader::bindTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, texture);
-}
-
-void SSAOShader::bindNoiseTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, noiseTexture);
-}
-
-void SSAOShader::setNumberOfSamples(int amount)
-{
-    numberOfSamples = min(max(amount, 0), 64);
-}
-
-int SSAOShader::getNumberOfSamples() const
-{
-    return numberOfSamples;
-}
-
-void SSAOShader::setSampleRadius(float sampleRadius)
-{
-    numberOfSamples = min(max(sampleRadius, 0.05f), 20.0f);
-}
-
-float SSAOShader::getSampleRadius() const
-{
-    return radius;
-}

+ 0 - 45
client/engine/shader/SSAOShader.h

@@ -1,45 +0,0 @@
-#ifndef SSAOSHADER_H
-#define SSAOSHADER_H
-
-#include "client/engine/shader/ShaderProgram.h"
-
-class SSAOShader
-{
-public:
-    SSAOShader();
-    virtual ~SSAOShader();
-    
-    bool init();
-    void resize();
-
-    void preRender(const float* projMatrix);
-    
-    void bindTexture(unsigned int textureUnit);
-    void bindNoiseTexture(unsigned int textureUnit);
-    
-    void setNumberOfSamples(int amount);
-    int getNumberOfSamples() const;
-    void setSampleRadius(float sampleRadius);
-    float getSampleRadius() const;
-    
-private:
-    // shader
-    ShaderProgram program;
-    // framebuffer
-    GLuint framebuffer = 0;
-    // textures
-    GLuint texture = 0;
-    GLuint noiseTexture = 0;
-    // uniform data
-    int numberOfSamples = 32;
-    float radius = 2.5f;
-    // uniforms locations
-    GLint unifProjMatrix = 0;
-    GLint unifNumberOfSamples = 0;
-    GLint unifRadius = 0;
-    GLint unifWidth = 0;
-    GLint unifHeight = 0;
-};
-
-#endif
-

+ 0 - 187
client/engine/shader/ShaderProgram.cpp

@@ -1,187 +0,0 @@
-#include <fstream>
-#include <cstring>
-
-#include "client/engine/shader/ShaderProgram.h"
-
-ShaderProgram::ShaderProgram()
-{
-}
-
-ShaderProgram::~ShaderProgram()
-{
-    glDeleteShader(vertexShader);
-    glDeleteShader(fragmentShader);
-    glDeleteProgram(program);
-}
-
-bool ShaderProgram::isValid() const
-{
-    return valid;
-}
-
-GLuint ShaderProgram::getProgram() const
-{
-    return program;
-}
-
-void ShaderProgram::compile(const GLchar* vertexPath, const GLchar* fragmentPath)
-{
-    if(valid)
-    {
-        return;
-    }
-    GLchar* vertexData = readFile(vertexPath);
-    if(vertexData == nullptr)
-    {
-        cout << "cannot read " << vertexPath << endl;
-        return;
-    }
-    GLchar* fragmentData = readFile(fragmentPath);
-    if(fragmentData == nullptr)
-    {
-        cout << "cannot read " << fragmentPath << endl;
-        delete[] vertexData;
-        return;
-    }
-    
-    compile(vertexPath, vertexData, fragmentPath, fragmentData);
-    delete[] vertexData;
-    delete[] fragmentData;
-}
-
-GLchar* ShaderProgram::readFile(const GLchar* name)
-{
-    ifstream in;
-    in.open(name);
-    if(!in.fail())
-    {
-        int size = 128;
-        int index = 0;
-        GLchar* content = new GLchar[size];
-        
-        while(true)
-        {
-            GLchar c = in.get();
-            if(in.eof())
-            {
-                break;
-            }
-            if(index >= size - 1)
-            {
-                GLchar* newContent = new GLchar[size * 2];
-                memcpy(newContent, content, size);
-                size *= 2;
-                delete[] content;
-                content = newContent;
-            }
-            content[index] = c;
-            index++;
-        }
-        
-        content[index] = '\0';
-        index++;
-        
-        in.close();
-        return content;
-    }
-    return nullptr;
-}
-
-bool ShaderProgram::checkShaderErrors(const GLchar* name, GLuint shader)
-{
-    bool returnValue = false;
-    
-    //cout << "compiling " << name << " shader ..." << endl;
-    GLenum error = glGetError();
-    if(error)
-    {
-        cout << "compiling of " << name << " failed" << endl;
-        cout << "error: " << glGetError() << endl;
-        returnValue = true;
-    }
-    //else
-    //{
-    //    cout << "no error occured ..." << endl;
-    //}
-    
-    GLint compiled[1];
-    glGetShaderiv(shader, GL_COMPILE_STATUS, compiled);
-    if(compiled[0])
-    {
-        //cout << name << " shader successfully compiled" << endl;
-    }
-    else
-    {
-        cout << "compiling of " << name << " failed:" << endl;
-        GLchar buffer[512];
-        GLsizei bufferSize = 512;
-        GLsizei charsUsed = 0;
-        glGetShaderInfoLog(shader, bufferSize, &charsUsed, buffer);
-        // glGetProgramInfoLog should be null terminated ...
-        buffer[bufferSize - 1] = '\0';
-        cout << buffer << endl;
-        returnValue = true;
-    }
-    return returnValue;
-}
-
-void ShaderProgram::compile(const GLchar* vertexPath, const GLchar* vertexData, const GLchar* fragmentPath, const GLchar* fragmentData)
-{
-    vertexShader = glCreateShader(GL_VERTEX_SHADER);
-    glShaderSource(vertexShader, 1, &vertexData, nullptr);
-    glCompileShader(vertexShader);
-
-    if(checkShaderErrors(vertexPath, vertexShader))
-    {
-        return;
-    }    
-    
-    fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-    glShaderSource(fragmentShader, 1, &fragmentData, nullptr);
-    glCompileShader(fragmentShader);
-
-    if(checkShaderErrors(fragmentPath, fragmentShader))
-    {
-        return;
-    }    
-
-    program = glCreateProgram();
-    glAttachShader(program, vertexShader);
-    glAttachShader(program, fragmentShader);
-    glLinkProgram(program);
-    
-    //cout << "linking shaders to program ..." << endl;
-
-    GLenum error = glGetError();
-    if(error)
-    {
-        cout << "linking of " << vertexPath << " and " << fragmentPath << " failed" << endl;
-        cout << "error: " << glGetError() << endl;
-        return;
-    }
-    //else
-    //{
-    //    cout << "no error occured ..." << endl;
-    //}
-
-    GLint compiled[1];
-    glGetProgramiv(program, GL_LINK_STATUS, compiled);
-    if(compiled[0])
-    {
-        //cout << "shaders successfully linked" << endl;
-    }
-    else
-    {
-        cout << "linking of " << vertexPath << " and " << fragmentPath << " failed:" << endl;
-        GLchar buffer[512];
-        GLsizei bufferSize = 512;
-        GLsizei charsUsed = 0;
-        glGetProgramInfoLog(program, bufferSize, &charsUsed, buffer);
-        // glGetProgramInfoLog should be null terminated ...
-        buffer[bufferSize - 1] = '\0';
-        cout << buffer << endl;
-        return;
-    }
-    valid = true;
-}
-

+ 0 - 31
client/engine/shader/ShaderProgram.h

@@ -1,31 +0,0 @@
-#ifndef SHADERPROGRAM_H
-#define SHADERPROGRAM_H
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-#include <iostream>
-
-using namespace std;
-
-class ShaderProgram
-{
-public:
-    ShaderProgram();
-    virtual ~ShaderProgram();
-    
-    void compile(const GLchar* vertexPath, const GLchar* fragmentPath);
-    bool isValid() const;
-    GLuint getProgram() const;
-private:
-    GLchar* readFile(const GLchar* name);
-    bool checkShaderErrors(const GLchar* name, GLuint shader);
-    void compile(const GLchar* vertexPath, const GLchar* vertexData, const GLchar* fragmentPath, const GLchar* fragmentData);
-    
-    GLuint vertexShader = 0;
-    GLuint fragmentShader = 0;
-    GLuint program = 0;
-    bool valid = false;
-};
-
-#endif
-

+ 0 - 72
client/engine/shader/WorldPostShader.cpp

@@ -1,72 +0,0 @@
-#include "client/engine/shader/WorldPostShader.h"
-#include "client/engine/Wrapper.h"
-
-WorldPostShader::WorldPostShader()
-{
-}
-
-WorldPostShader::~WorldPostShader()
-{
-    glDeleteFramebuffers(1, &framebuffer);
-    glDeleteTextures(1, &texture);
-}
-
-bool WorldPostShader::init()
-{
-    program.compile("resources/shader/worldPostVertex.vs", "resources/shader/worldPostFragment.fs");
-    if(!program.isValid())
-    {
-        return false;
-    }
-    
-    // generate framebuffer
-    glGenFramebuffers(1, &framebuffer);
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // color texture
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Engine::getWidth(), Engine::getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    // attache color texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);  
-    
-    // check if framebuffer is okay
-    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
-    {
-	cout << "world post frame buffer is not complete!" << endl;
-        return false;
-    }
-    // unbind framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
-    return true;
-}
-
-void WorldPostShader::resize()
-{
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Engine::getWidth(), Engine::getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-}
-
-void WorldPostShader::preRender()
-{
-    // bind ssao shader program
-    glUseProgram(program.getProgram());
-    
-    // bind ssao framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // clear color buffer
-    glClear(GL_COLOR_BUFFER_BIT);
-    
-    // depth testing is not needed
-    glDisable(GL_DEPTH_TEST);
-}
-
-void WorldPostShader::bindTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, texture);
-}

+ 0 - 31
client/engine/shader/WorldPostShader.h

@@ -1,31 +0,0 @@
-#ifndef WORLDPOSTSHADER_H
-#define WORLDPOSTSHADER_H
-
-#include "client/engine/shader/ShaderProgram.h"
-
-class WorldPostShader
-{
-public:
-    WorldPostShader();
-    virtual ~WorldPostShader();
-    
-    bool init();
-    void resize();
-
-    void preRender();
-    
-    void bindTexture(unsigned int textureUnit);
-    
-private:
-    // shader
-    ShaderProgram program;
-    // framebuffer
-    GLuint framebuffer = 0;
-    // textures
-    GLuint texture = 0;
-};
-
-#endif
-
-
-

+ 0 - 159
client/engine/shader/WorldShader.cpp

@@ -1,159 +0,0 @@
-#include "client/engine/shader/WorldShader.h"
-#include "client/engine/Wrapper.h"
-
-WorldShader::WorldShader()
-{
-}
-
-WorldShader::~WorldShader()
-{
-    glDeleteFramebuffers(1, &framebuffer);
-    glDeleteTextures(1, &positionTexture);
-    glDeleteTextures(1, &normalTexture);
-    glDeleteTextures(1, &colorTexture);
-    glDeleteTextures(1, &depthTexture);
-}
-
-bool WorldShader::init()
-{
-    program.compile("resources/shader/worldVertex.vs", "resources/shader/worldFragment.fs");
-    if(!program.isValid())
-    {
-        return false;
-    }
-    
-    // generate framebuffer
-    glGenFramebuffers(1, &framebuffer);
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // position texture
-    glGenTextures(1, &positionTexture);
-    glBindTexture(GL_TEXTURE_2D, positionTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-    // attache position texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, positionTexture, 0);   
-    
-    // normal texture
-    glGenTextures(1, &normalTexture);
-    glBindTexture(GL_TEXTURE_2D, normalTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    // attache normal texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, normalTexture, 0);   
-    
-    // color texture
-    glGenTextures(1, &colorTexture);
-    glBindTexture(GL_TEXTURE_2D, colorTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Engine::getWidth(), Engine::getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    // attache color texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, colorTexture, 0);  
-    
-    // depth texture
-    glGenTextures(1, &depthTexture);
-    glBindTexture(GL_TEXTURE_2D, depthTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, Engine::getWidth(), Engine::getHeight(), 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    // attache depth texture to framebuffer
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); 
-    
-    // set color attachements for the framebuffer
-    GLuint attachments[3] = 
-    {
-        GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 
-    };
-    glDrawBuffers(3, attachments);   
-    
-    // check if framebuffer is okay
-    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
-    {
-	cout << "world frame buffer is not complete!" << endl;
-        return false;
-    }
-    // unbind framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    
-    // get uniform locations
-    unifProjMatrix = glGetUniformLocation(program.getProgram(), "projMatrix");
-    unifViewMatrix = glGetUniformLocation(program.getProgram(), "viewMatrix");
-    unifModelMatrix = glGetUniformLocation(program.getProgram(), "modelMatrix");
-    
-    return true;
-}
-
-void WorldShader::resize()
-{
-    glBindTexture(GL_TEXTURE_2D, positionTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
-   
-    glBindTexture(GL_TEXTURE_2D, normalTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, Engine::getWidth(), Engine::getHeight(), 0, GL_RGB, GL_FLOAT, NULL);
- 
-    glBindTexture(GL_TEXTURE_2D, colorTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Engine::getWidth(), Engine::getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- 
-    glBindTexture(GL_TEXTURE_2D, depthTexture);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, Engine::getWidth(), Engine::getHeight(), 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
-}
-
-void WorldShader::preRender(const float* projMatrix)
-{
-    // bind world shader program
-    glUseProgram(program.getProgram());
-    
-    // set projection matrix uniform
-    glUniformMatrix4fv(unifProjMatrix, 1, 0, projMatrix);
-
-    // all textures bind to texture unit 0
-    glActiveTexture(GL_TEXTURE0);
-    
-    // bind world framebuffer
-    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
-    
-    // clear color, depth and stencil buffer
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-    
-    // depth testing is needed
-    glEnable(GL_DEPTH_TEST);
-}
-
-void WorldShader::bindPositionTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, positionTexture);
-}
-
-void WorldShader::bindNormalTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, normalTexture);
-}
-
-void WorldShader::bindColorTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, colorTexture);
-}
-
-void WorldShader::bindDepthTexture(unsigned int textureUnit)
-{
-    glActiveTexture(GL_TEXTURE0 + textureUnit);
-    glBindTexture(GL_TEXTURE_2D, depthTexture);
-}
-
-void WorldShader::setViewMatrix(const float* data)
-{
-    glUniformMatrix4fv(unifViewMatrix, 1, 0, data);
-}
-
-void WorldShader::setModelMatrix(const float* data)
-{
-    glUniformMatrix4fv(unifModelMatrix, 1, 0, data);
-}

+ 0 - 42
client/engine/shader/WorldShader.h

@@ -1,42 +0,0 @@
-#ifndef WORLDSHADER_H
-#define WORLDSHADER_H
-
-#include "client/engine/shader/ShaderProgram.h"
-
-class WorldShader
-{
-public:
-    WorldShader();
-    virtual ~WorldShader();
-    
-    bool init();
-    void resize();
-
-    void preRender(const float* projMatrix);
-    
-    void bindPositionTexture(unsigned int textureUnit);
-    void bindNormalTexture(unsigned int textureUnit);
-    void bindColorTexture(unsigned int textureUnit);
-    void bindDepthTexture(unsigned int textureUnit);
-    
-    void setViewMatrix(const float* data);
-    void setModelMatrix(const float* data);
-    
-private:
-    // shader
-    ShaderProgram program;
-    // framebuffer
-    GLuint framebuffer = 0;
-    // textures
-    GLuint positionTexture = 0;
-    GLuint normalTexture = 0;
-    GLuint colorTexture = 0;
-    GLuint depthTexture = 0;
-    // uniforms locations
-    GLint unifProjMatrix = 0;
-    GLint unifViewMatrix = 0;
-    GLint unifModelMatrix = 0;
-};
-
-#endif
-

+ 4 - 2
client/Keys.cpp → client/input/Keys.cpp

@@ -1,6 +1,6 @@
 #include <GLFW/glfw3.h>
 
-#include "client/Keys.h"
+#include "client/input/Keys.h"
 
 bool Keys::Key::isDown() const
 {
@@ -24,12 +24,14 @@ std::ostream& operator <<(std::ostream& os, const Keys::Key& k)
     return os;
 }
 
-Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3])
+Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3]), jump(keys[4]), sneak(keys[5])
 {
     keys[0].glfwKey = GLFW_KEY_A;
     keys[1].glfwKey = GLFW_KEY_D;
     keys[2].glfwKey = GLFW_KEY_W;
     keys[3].glfwKey = GLFW_KEY_S;
+    keys[4].glfwKey = GLFW_KEY_SPACE;
+    keys[5].glfwKey = GLFW_KEY_LEFT_SHIFT;
 }
 
 void Keys::release(int key)

+ 7 - 7
client/Keys.h → client/input/Keys.h

@@ -5,12 +5,11 @@
 #include <array>
 
 #include "common/utils/Types.h"
-#include "GameClient.h"
 
-class Keys
+class Keys final
 {
 public:
-    class Key
+    class Key final
     {
     public:
         friend class Keys;
@@ -33,7 +32,7 @@ public:
     };
     
 private:
-   Key keys[4];
+   Key keys[6];
     
 public:
     Keys();
@@ -41,6 +40,8 @@ public:
     const Key& right;
     const Key& up;
     const Key& down;
+    const Key& jump;
+    const Key& sneak;
     
     void release(int key);
     void press(int key);
@@ -53,7 +54,6 @@ private:
     Keys& operator=(Keys&&) = delete;
 };
 
-std::ostream& operator<<(std::ostream& os, const Keys::Key& m);
-
-#endif
+std::ostream& operator<<(std::ostream& os, const Keys::Key& k);
 
+#endif

+ 99 - 0
client/input/MouseButtons.cpp

@@ -0,0 +1,99 @@
+#include <GLFW/glfw3.h>
+
+#include "client/input/MouseButtons.h"
+
+bool MouseButtons::MouseButton::isDown() const
+{
+    return down;
+}
+
+bool MouseButtons::MouseButton::isReleased() const
+{
+    return shouldRelease;
+}
+
+u32 MouseButtons::MouseButton::getDownTime() const
+{
+    return downTime;
+}
+
+std::ostream& operator <<(std::ostream& os, const MouseButtons::MouseButton& m)
+{
+    os << "Mouse(down: " << m.isDown() << ", release: " << m.isReleased() << 
+            ", time: " << m.getDownTime() << ")"; 
+    return os;
+}
+
+MouseButtons::MouseButtons() : primary(buttons[0]), secondary(buttons[1]), 
+        middle(buttons[2]), oldX(0), oldY(0), x(0), y(0)
+{
+    buttons[0].glfwButton= GLFW_MOUSE_BUTTON_1;
+    buttons[1].glfwButton = GLFW_MOUSE_BUTTON_2;
+    buttons[2].glfwButton = GLFW_MOUSE_BUTTON_3;
+}
+
+double MouseButtons::getOldX() const
+{
+    return oldX;
+}
+
+double MouseButtons::getOldY() const
+{
+    return oldY;
+}
+
+double MouseButtons::getX() const
+{
+    return x;
+}
+
+double MouseButtons::getY() const
+{
+    return y;
+}
+
+void MouseButtons::release(int button)
+{
+    for(MouseButton& k : buttons)
+    {
+        if(k.glfwButton == button)
+        {
+            k.shouldRelease = true;
+        }
+    }
+}
+
+void MouseButtons::press(int button)
+{
+    for(MouseButton& k : buttons)
+    {
+        if(k.glfwButton == button)
+        {
+            k.down = true;
+            k.shouldRelease = false;
+        }
+    }
+}
+
+void MouseButtons::move(double x, double y)
+{
+    MouseButtons::x = x;
+    MouseButtons::y = y;
+}
+
+void MouseButtons::tick()
+{
+    for(MouseButton& k : buttons)
+    {
+        k.downTime += k.down;
+        k.down = k.down && !k.shouldRelease;
+        k.downTime *= !k.shouldRelease;
+        k.shouldRelease = false;
+    }
+}
+
+void MouseButtons::postTick()
+{
+    oldX = x;
+    oldY = y;
+}

+ 70 - 0
client/input/MouseButtons.h

@@ -0,0 +1,70 @@
+#ifndef MOUSEBUTTONS_H
+#define MOUSEBUTTONS_H
+
+#include <iostream>
+#include <array>
+
+#include "common/utils/Types.h"
+
+class MouseButtons final
+{
+public:
+    class MouseButton final
+    {
+    public:
+        friend class MouseButtons;
+
+        bool isDown() const;
+        bool isReleased() const;
+        u32 getDownTime() const;
+      
+    private:
+        MouseButton() = default;
+        MouseButton(const MouseButton&) = delete;
+        MouseButton(MouseButton&&) = delete;
+        MouseButton& operator=(const MouseButton&) = delete;
+        MouseButton& operator=(MouseButton&&) = delete;
+    
+        int glfwButton;
+        bool down;
+        bool shouldRelease;
+        u32 downTime;
+    };
+    
+private:
+   MouseButton buttons[3];
+    
+public:
+    MouseButtons();
+    
+    double getOldX() const;
+    double getOldY() const;
+    double getX() const;
+    double getY() const;
+    
+    const MouseButton& primary;
+    const MouseButton& secondary;
+    const MouseButton& middle;
+    
+    void release(int button);
+    void press(int button);
+    void move(double x, double y);
+    void tick();
+    void postTick();
+    
+private:   
+    MouseButtons(const MouseButtons&) = delete;
+    MouseButtons& operator=(const MouseButtons&) = delete;
+    MouseButtons(MouseButtons&&) = delete;
+    MouseButtons& operator=(MouseButtons&&) = delete;
+    
+    double oldX;
+    double oldY;
+    double x;
+    double y;
+};
+
+std::ostream& operator<<(std::ostream& os, const MouseButtons::MouseButton& m);
+
+#endif
+

+ 126 - 0
client/math/Camera.cpp

@@ -0,0 +1,126 @@
+#include "client/math/Camera.h"
+#include "client/Utils.h"
+
+Camera::Camera() : oldLengthAngle(0), lengthAngle(0), oldWidthAngle(0), widthAngle(0)
+{
+
+}
+
+const Vector& Camera::getFront() const
+{
+    return front;
+}
+
+const Vector& Camera::getBack() const
+{
+    return back;
+}
+
+const Vector& Camera::getRight() const
+{
+    return right;
+}
+
+const Vector& Camera::getLeft() const
+{
+    return left;
+}
+
+const Vector& Camera::getUp() const
+{
+    return up;
+}
+
+const Vector& Camera::getDown() const
+{
+    return down;
+}
+
+const Vector& Camera::getFlatFront() const
+{
+    return flatFront;
+}
+
+const Vector& Camera::getFlatBack() const
+{
+    return flatBack;
+}
+
+const Vector& Camera::getFlatRight() const
+{
+    return flatRight;
+}
+
+const Vector& Camera::getFlatLeft() const
+{
+    return flatLeft;
+}
+
+const Vector& Camera::getFlatUp() const
+{
+    return flatUp;
+}
+
+const Vector& Camera::getFlatDown() const
+{
+    return flatDown;
+}
+
+const Vector& Camera::getPosition() const
+{
+    return interPosition;
+}
+
+void Camera::storePosition()
+{
+    oldPosition = position;
+    oldLengthAngle = lengthAngle;
+    oldWidthAngle = widthAngle;
+}
+
+void Camera::setPosition(const Vector& pos, float length, float width)
+{
+    position = pos;
+    lengthAngle = length;
+    widthAngle = width;
+}
+
+void Camera::update(float lag)
+{
+    // front
+    front.setAngles(interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
+    // back
+    back.setInverse(front);
+    // left
+    left = front;
+    left.cross(0.0f, 1.0f, 0.0f);
+    left.normalize();
+    // right
+    right.setInverse(left);
+    // up
+    up = front;
+    up.cross(right);
+    up.normalize();
+    // down
+    down.setInverse(up);
+    // interpolated position
+    interPosition = oldPosition;
+    interPosition.addMul(position, lag);
+    interPosition.addMul(oldPosition, -lag);
+    // flat front
+    flatFront = front;
+    flatFront.setY(0.0f);
+    flatFront.normalize();
+    // flat back
+    flatBack.setInverse(flatFront);
+    // flat left
+    flatLeft = flatFront;
+    flatLeft.cross(0.0f, 1.0f, 0.0f);
+    flatLeft.normalize();
+    // flat right
+    flatRight.setInverse(flatLeft);
+    // flat up
+    flatUp.set(0.0f, 1.0f, 0.0f);
+    // flat down
+    flatDown.setInverse(flatUp);
+}

+ 56 - 0
client/math/Camera.h

@@ -0,0 +1,56 @@
+#ifndef CAMERA3D_H
+#define CAMERA3D_H
+
+#include "client/math/Vector.h"
+
+class Camera final
+{
+public:
+    Camera();
+    
+    const Vector& getFront() const;
+    const Vector& getBack() const;
+    const Vector& getRight() const;
+    const Vector& getLeft() const;
+    const Vector& getUp() const;
+    const Vector& getDown() const;
+    
+    const Vector& getFlatFront() const;
+    const Vector& getFlatBack() const;
+    const Vector& getFlatRight() const;
+    const Vector& getFlatLeft() const;
+    const Vector& getFlatUp() const;
+    const Vector& getFlatDown() const;
+    
+    const Vector& getPosition() const;
+    void storePosition();
+    void setPosition(const Vector& pos, float length, float width);
+    
+    void update(float lag);
+    
+private:
+    Vector oldPosition;
+    Vector position;
+    float oldLengthAngle;
+    float lengthAngle;
+    float oldWidthAngle;
+    float widthAngle;
+    
+    Vector interPosition;
+    
+    Vector front;
+    Vector back;
+    Vector right;
+    Vector left;
+    Vector up;
+    Vector down;  
+    
+    Vector flatFront;
+    Vector flatBack;
+    Vector flatRight;
+    Vector flatLeft;
+    Vector flatUp;
+    Vector flatDown; 
+};
+
+#endif

+ 0 - 242
client/math/Camera3D.cpp

@@ -1,242 +0,0 @@
-#include <cmath>
-
-#include "client/math/Camera3D.h"
-#include "client/engine/Wrapper.h"
-#include "client/engine/Utils.h"
-
-Camera3D::Camera3D()
-{
-}
-
-Camera3D::~Camera3D()
-{
-}
-
-const Vector3D& Camera3D::getFlatFront() const
-{
-    return flatFront;
-}
-
-const Vector3D& Camera3D::getFlatBack() const
-{
-    return flatBack;
-}
-
-const Vector3D& Camera3D::getFlatRight() const
-{
-    return flatRight;
-}
-
-const Vector3D& Camera3D::getFlatLeft() const
-{
-    return flatLeft;
-}
-
-const Vector3D& Camera3D::getFlatUp() const
-{
-    return flatUp;
-}
-
-const Vector3D& Camera3D::getFlatDown() const
-{
-    return flatDown;
-}
-
-void Camera3D::addToOldLengthAngle(float f)
-{
-    oldLengthAngle += f;
-}
-
-void Camera3D::storePosition()
-{
-    oldCamera.set(camera);
-    oldLengthAngle = lengthAngle;
-    oldWidthAngle = widthAngle;
-}
-
-void Camera3D::setPosition(float x, float y, float z, float length, float width)
-{
-    camera.set(x, y, z);
-    lengthAngle = length;
-    widthAngle = width;
-}
-
-float old = 0;
-float current = 0;
-
-void Camera3D::update(float lag)
-{
-    // -------------------------------------------------------------------------
-    // calculate vectors for the view matrix
-    // -------------------------------------------------------------------------
-    
-    // front
-    front.setAngles(interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
-    
-    // back
-    back.setInverse(front);
-
-    // right
-    right.set(front);
-    right.cross(0.0f, 1.0f, 0.0f);
-    right.normalize();
-    
-    // left
-    left.setInverse(right);
-    
-    // up
-    up.set(front);
-    up.cross(left);
-    up.normalize();
-    
-    // down
-    down.setInverse(up);
-    
-    Vector3D interCamera = oldCamera;
-    interCamera.addMul(camera, lag);
-    interCamera.addMul(oldCamera, -lag);
-    
-    view.set(0, 0, right.getX());
-    view.set(0, 1, right.getY());
-    view.set(0, 2, right.getZ());
-    view.set(0, 3, right.dotInverse(interCamera));
-    
-    view.set(1, 0, up.getX());
-    view.set(1, 1, up.getY());
-    view.set(1, 2, up.getZ());
-    view.set(1, 3, up.dotInverse(interCamera));
-    
-    view.set(2, 0, back.getX());
-    view.set(2, 1, back.getY());
-    view.set(2, 2, back.getZ());
-    view.set(2, 3, back.dotInverse(interCamera));
-    
-    view.set(3, 0, 0.0f);
-    view.set(3, 1, 0.0f);
-    view.set(3, 0, 0.0f);
-    view.set(3, 3, 1.0f);
-   
-    // -------------------------------------------------------------------------
-    // calculate flat vectors for movement
-    // -------------------------------------------------------------------------
-    
-    // front
-    flatFront.set(front);
-    flatFront.setY(0.0f);
-    flatFront.normalize();
-    
-    // back
-    flatBack.setInverse(flatFront);
-
-    // right
-    flatRight.set(flatFront);
-    flatRight.cross(0.0f, 1.0f, 0.0f);
-    flatRight.normalize();
-    
-    // left
-    flatLeft.setInverse(flatRight);
-
-    // up
-    flatUp.set(0.0f, 1.0f, 0.0f);
-    
-    // down
-    flatDown.setInverse(flatUp);
-    
-    // -------------------------------------------------------------------------
-    // update frustum planes
-    // -------------------------------------------------------------------------
-    
-    // http://cgvr.informatik.uni-bremen.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html
-    float tan = tanf((0.5f * Engine::getFieldOfView()) * M_PI / 180.0f);
-    float aspect = (float) Engine::getWidth() / Engine::getHeight();
-    
-    float nearHigh = tan * Engine::getNearClip();
-    float nearWidth = nearHigh * aspect;
-
-    float farHigh = tan * Engine::getFarClip();
-    float farWidth = farHigh * aspect;
-
-    Vector3D fc = interCamera;
-    fc.addMul(front, Engine::getFarClip());
-
-    Vector3D ftl = fc;
-    ftl.addMul(left, farWidth);
-    ftl.addMul(up, farHigh);
-
-    Vector3D fbl = fc;
-    fbl.addMul(left, farWidth);
-    fbl.addMul(down, farHigh);
-
-    Vector3D fbr = fc;
-    fbr.addMul(right, farWidth);
-    fbr.addMul(down, farHigh);
-
-    Vector3D nc = interCamera;
-    nc.addMul(front, Engine::getNearClip());
-
-    Vector3D ntl = nc;
-    ntl.addMul(left, nearWidth);
-    ntl.addMul(down, nearHigh);
-
-    Vector3D ntr = nc;
-    ntr.addMul(right, nearWidth);
-    ntr.addMul(up, nearHigh);
-
-    Vector3D nbr = nc;
-    nbr.addMul(right, nearWidth);
-    nbr.addMul(down, nearHigh);
-
-    // generating planes with counter clockwise vector order
-    frustumPlanes[0].set(fbl, ftl, fbr); // far
-    frustumPlanes[1].set(ntl, ftl, fbl); // left
-    frustumPlanes[2].set(fbr, ntr, nbr); // right
-    frustumPlanes[3].set(fbl, fbr, nbr); // bottom
-    frustumPlanes[4].set(ntr, ftl, ntl); // top
-    frustumPlanes[5].set(nbr, ntr, ntl); // near
-}
-
-const float* Camera3D::getViewMatrix()
-{
-    return view.getValues();
-}
-
-bool Camera3D::isInFrustum(float x, float y, float z, float x2, float y2, float z2) const
-{
-    // some tolerance
-    x -= 1;
-    y -= 1;
-    z -= 1;
-    x2 += 1;
-    y2 += 1;
-    z2 += 1;
-    //return true;
-    // http://cgvr.informatik.uni-bremen.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html
-    // for each plane do ...
-    for(int fp = 0; fp < 6; fp++) 
-    {
-        // reset counters for corners in and out
-        int out = 0;
-        int in = 0;
-        // for each corner of the box do ...
-        // get out of the cycle as soon as a box as corners
-        // both inside and out of the frustum
-        for(int i = 0; i < 8 && (in == 0 || out == 0); i++) 
-        {
-            // is the corner outside or inside
-            if(frustumPlanes[fp].getSignedDistance(((i >> 2) & 1) ? x : x2, ((i >> 1) & 1) ? y : y2, (i & 1) ? z : z2) > 0)
-            {
-                out++;
-            }
-            else
-            {
-                in++;
-            }
-        }
-        //if all corners are out
-        if(in == 0)
-        {
-            return false;
-        }
-    }
-    return true;
-}

+ 0 - 58
client/math/Camera3D.h

@@ -1,58 +0,0 @@
-#ifndef CAMERA3D_H
-#define CAMERA3D_H
-
-#include "client/math/Vector3D.h"
-#include "client/math/Matrix3D.h"
-#include "client/math/Plane3D.h"
-
-class Camera3D
-{
-public:
-    Camera3D();
-    virtual ~Camera3D();
-    
-    bool isInFrustum(float x, float y, float z, float x2, float y2, float z2) const;
-    
-    void addToOldLengthAngle(float f);
-    
-    void storePosition();
-    void setPosition(float x, float y, float z, float length, float width);
-    
-    const Vector3D& getFlatFront() const;
-    const Vector3D& getFlatBack() const;
-    const Vector3D& getFlatRight() const;
-    const Vector3D& getFlatLeft() const;
-    const Vector3D& getFlatUp() const;
-    const Vector3D& getFlatDown() const;
-    
-    void update(float lag);
-    const float* getViewMatrix();
-private:
-    Vector3D oldCamera;
-    Vector3D camera;
-    float oldLengthAngle;
-    float lengthAngle;
-    float oldWidthAngle;
-    float widthAngle;
-    
-    Vector3D front;
-    Vector3D back;
-    Vector3D right;
-    Vector3D left;
-    Vector3D up;
-    Vector3D down;  
-    
-    Vector3D flatFront;
-    Vector3D flatBack;
-    Vector3D flatRight;
-    Vector3D flatLeft;
-    Vector3D flatUp;
-    Vector3D flatDown; 
-    
-    Matrix3D view;
-    
-    Plane3D frustumPlanes[6];
-};
-
-#endif
-

+ 35 - 39
client/math/Matrix3D.cpp → client/math/Matrix.cpp

@@ -1,14 +1,15 @@
-#include <cstring>
 #include <cmath>
+#include <iomanip>
+#include <cstring>
 
-#include "client/math/Matrix3D.h"
+#include "client/math/Matrix.h"
 
-Matrix3D::Matrix3D()
+Matrix::Matrix()
 {
     setToIdentity();
 }
 
-void Matrix3D::setToIdentity()
+void Matrix::setToIdentity()
 {
     data[0] = 1.0f;
     data[1] = 0.0f;
@@ -28,27 +29,12 @@ void Matrix3D::setToIdentity()
     data[15] = 1.0f;
 }
 
-void Matrix3D::set(const Matrix3D& m)
-{
-    memcpy(data, m.data, sizeof(float) * 16);
-}
-
-void Matrix3D::set(int row, int col, float value)
-{
-    data[row + (col << 2)] = value;
-}
-
-float Matrix3D::get(int row, int col) const
-{
-    return data[row + (col << 2)];
-}
-
-const float* Matrix3D::getValues() const
+const float* Matrix::getValues() const
 {
     return data;
 }
 
-void Matrix3D::mul(const Matrix3D& m)
+void Matrix::mul(const Matrix& m)
 {
     float mNew[16];
     mNew[0] = data[0] * m.data[0] + data[4] * m.data[1] + data[8] * m.data[2] + data[12] * m.data[3];
@@ -67,10 +53,10 @@ void Matrix3D::mul(const Matrix3D& m)
     mNew[13] = data[1] * m.data[12] + data[5] * m.data[13] + data[9] * m.data[14] + data[13] * m.data[15];
     mNew[14] = data[2] * m.data[12] + data[6] * m.data[13] + data[10] * m.data[14] + data[14] * m.data[15];
     mNew[15] = data[3] * m.data[12] + data[7] * m.data[13] + data[11] * m.data[14] + data[15] * m.data[15];
-    memcpy(data, mNew, sizeof(float) * 16);
+    std::memcpy(data, mNew, sizeof(float) * 16);
 }
 
-void Matrix3D::scale(float sx, float sy, float sz)
+void Matrix::scale(float sx, float sy, float sz)
 {
     data[0] *= sx;
     data[1] *= sx;
@@ -86,7 +72,7 @@ void Matrix3D::scale(float sx, float sy, float sz)
     data[11] *= sz;
 }
 
-void Matrix3D::translate(float tx, float ty, float tz) 
+void Matrix::translate(float tx, float ty, float tz) 
 {
     data[12] += data[0] * tx + data[4] * ty + data[8] * tz;
     data[13] += data[1] * tx + data[5] * ty + data[9] * tz;
@@ -94,7 +80,7 @@ void Matrix3D::translate(float tx, float ty, float tz)
     data[15] += data[3] * tx + data[7] * ty + data[11] * tz;
 }
 
-void Matrix3D::translateX(float tx) 
+void Matrix::translateX(float tx) 
 {
     data[12] += data[0] * tx;
     data[13] += data[1] * tx;
@@ -102,7 +88,7 @@ void Matrix3D::translateX(float tx)
     data[15] += data[3] * tx;
 }
 
-void Matrix3D::translateY(float ty) 
+void Matrix::translateY(float ty) 
 {
     data[12] += data[4] * ty;
     data[13] += data[5] * ty;
@@ -110,7 +96,7 @@ void Matrix3D::translateY(float ty)
     data[15] += data[7] * ty;
 }
 
-void Matrix3D::translateZ(float tz) 
+void Matrix::translateZ(float tz) 
 {
     data[12] += data[8] * tz;
     data[13] += data[9] * tz;
@@ -118,7 +104,7 @@ void Matrix3D::translateZ(float tz)
     data[15] += data[11] * tz;
 }
 
-void Matrix3D::translateTo(float tx, float ty, float tz) 
+void Matrix::translateTo(float tx, float ty, float tz) 
 {
     data[0] = 1.0f;
     data[1] = 0.0f;
@@ -138,7 +124,7 @@ void Matrix3D::translateTo(float tx, float ty, float tz)
     data[15] = 1.0f;
 }
 
-void Matrix3D::rotateX(float degrees) 
+void Matrix::rotateX(float degrees) 
 {
     degrees *= M_PI / 180.0f;
     float sin = sinf(degrees);
@@ -165,7 +151,7 @@ void Matrix3D::rotateX(float degrees)
     data[11] = a * -sin + b * cos;
 }
 
-void Matrix3D::rotateY(float degrees) 
+void Matrix::rotateY(float degrees) 
 {
     degrees *= M_PI / 180.0f;
     float sin = sinf(degrees);
@@ -192,7 +178,7 @@ void Matrix3D::rotateY(float degrees)
     data[11] = a * sin + b * cos;
 }
 
-void Matrix3D::rotateZ(float degrees) 
+void Matrix::rotateZ(float degrees) 
 {
     degrees *= M_PI / 180.0f;
     float sin = sinf(degrees);
@@ -219,13 +205,23 @@ void Matrix3D::rotateZ(float degrees)
     data[7] = a * -sin + b * cos;
 }
 
-std::ostream& operator<<(std::ostream& os, const Matrix3D& m)
-{
-    os << "Matrix3D\n(\n";
-    os << m.get(0, 0) << ", " << m.get(0, 1) << ", " << m.get(0, 2) << ", " << m.get(0, 3) << "\n";
-    os << m.get(1, 0) << ", " << m.get(1, 1) << ", " << m.get(1, 2) << ", " << m.get(1, 3) << "\n";
-    os << m.get(2, 0) << ", " << m.get(2, 1) << ", " << m.get(2, 2) << ", " << m.get(2, 3) << "\n";
-    os << m.get(3, 0) << ", " << m.get(3, 1) << ", " << m.get(3, 2) << ", " << m.get(3, 3) << "\n";
+std::ostream& operator<<(std::ostream& os, const Matrix& m)
+{
+    const float* data = m.getValues();
+    os << "Matrix\n(\n";
+    os << std::fixed << std::setprecision(5);
+    for(int i = 0; i < 4; i++)
+    {
+        os << std::setw(15);
+        os << data[i] << ", ";
+        os << std::setw(15);
+        os << data[i + 4] << ", ";
+        os << std::setw(15);
+        os << data[i + 8] << ", ";
+        os << std::setw(15);
+        os << data[i + 12] << "\n";
+    }
+    os << std::defaultfloat;
     os << ")";
     return os;
-}
+}

+ 8 - 12
client/math/Matrix3D.h → client/math/Matrix.h

@@ -1,22 +1,18 @@
-#ifndef MATRIX3D_H
-#define MATRIX3D_H
+#ifndef MATRIX_H
+#define MATRIX_H
 
 #include <iostream>
 
-class Matrix3D
+class Matrix final
 {
 public:
-    Matrix3D();
+    Matrix();
     
     void setToIdentity();
-    void set(const Matrix3D& m);
-    
-    void set(int row, int col, float value);
-    float get(int row, int col) const;
     
     const float* getValues() const;
     
-    void mul(const Matrix3D& m);
+    void mul(const Matrix& m);
     
     void scale(float sx, float sy, float sz);
     
@@ -29,11 +25,11 @@ public:
     void rotateX(float degrees);
     void rotateY(float degrees);
     void rotateZ(float degrees);
+    
 private:
     float data[16];
 };
 
-std::ostream& operator<<(std::ostream& os, const Matrix3D& m);
-
-#endif
+std::ostream& operator<<(std::ostream& os, const Matrix& m);
 
+#endif

+ 0 - 32
client/math/Matrix3DStack.cpp

@@ -1,32 +0,0 @@
-#include "client/math/Matrix3DStack.h"
-#include "client/math/StackOverflow.h"
-#include "client/math/StackUnderflow.h"
-
-Matrix3DStack::Matrix3DStack()
-{
-}
-
-void Matrix3DStack::pop()
-{
-    if(index <= 0)
-    {
-        throw StackUnderflow();
-    }
-    index--;
-}
-
-void Matrix3DStack::push()
-{
-    if(index >= STACK_SIZE - 1)
-    {
-        throw StackOverflow();
-    }
-    index++;
-    stack[index].set(stack[index - 1]);
-}
-
-Matrix3D& Matrix3DStack::get()
-{
-    return stack[index];
-}
-

+ 0 - 21
client/math/Matrix3DStack.h

@@ -1,21 +0,0 @@
-#ifndef MATRIX3DSTACK_H
-#define MATRIX3DSTACK_H
-
-#include "client/math/Matrix3D.h"
-
-class Matrix3DStack
-{
-public:
-    Matrix3DStack();
-    
-    void pop();
-    void push();
-    Matrix3D& get();
-private:
-    static const int STACK_SIZE = 10;
-    Matrix3D stack[STACK_SIZE];
-    int index = 0;
-};
-
-#endif
-

+ 27 - 0
client/math/MatrixStack.cpp

@@ -0,0 +1,27 @@
+#include <cassert>
+
+#include "client/math/MatrixStack.h"
+
+void MatrixStack::pop()
+{
+    assert(index > 0);
+    index--;
+}
+
+void MatrixStack::push()
+{
+    assert(index < stack.size() - 1);
+    index++;
+    stack[index] = stack[index - 1];
+}
+
+Matrix& MatrixStack::get()
+{
+    return stack[index];
+}
+
+void MatrixStack::clear()
+{
+    index = 0;
+    stack[0].setToIdentity();
+}

+ 21 - 0
client/math/MatrixStack.h

@@ -0,0 +1,21 @@
+#ifndef MATRIXSTACK_H
+#define MATRIXSTACK_H
+
+#include <array>
+
+#include "client/math/Matrix.h"
+
+class MatrixStack final
+{
+public:
+    void pop();
+    void push();
+    Matrix& get();
+    void clear();
+    
+private:
+    std::array<Matrix, 10> stack;
+    size_t index = 0;
+};
+
+#endif

+ 25 - 0
client/math/Plane.cpp

@@ -0,0 +1,25 @@
+#include "client/math/Plane.h"
+
+Plane::Plane() : a(0), b(0), c(0), d(0)
+{
+}
+
+void Plane::set(const Vector& va, const Vector& vb, const Vector& vc)
+{
+    Vector h1 = vb;
+    h1.sub(va);
+    Vector h2 = vc;
+    h2.sub(va);
+    h1.cross(h2);
+    h1.normalize();
+    
+    a = h1.getX();
+    b = h1.getY();
+    c = h1.getZ();
+    d = -h1.dot(va);
+}
+
+float Plane::getSignedDistance(float x, float y, float z) const
+{
+    return x * a + y * b + z * c + d;
+}

+ 21 - 0
client/math/Plane.h

@@ -0,0 +1,21 @@
+#ifndef PLANE3D_H
+#define PLANE3D_H
+
+#include "client/math/Vector.h"
+
+class Plane final
+{
+public:
+    Plane();
+    
+    void set(const Vector& va, const Vector& vb, const Vector& vc);
+    float getSignedDistance(float x, float y, float z) const;
+    
+private:
+    float a;
+    float b;
+    float c;
+    float d;
+};
+
+#endif

+ 0 - 29
client/math/Plane3D.cpp

@@ -1,29 +0,0 @@
-#include <iostream>
-
-#include "client/math/Plane3D.h"
-
-using namespace std;
-
-Plane3D::Plane3D()
-{
-}
-
-void Plane3D::set(const Vector3D& va, const Vector3D& vb, const Vector3D& vc)
-{
-    Vector3D h1 = vb;
-    h1.sub(va);
-    Vector3D h2 = vc;
-    h2.sub(va);
-    h1.cross(h2);
-    h1.normalize();
-    
-    a = h1.getX();
-    b = h1.getY();
-    c = h1.getZ();
-    d = -h1.dot(va);
-}
-
-float Plane3D::getSignedDistance(float x, float y, float z) const
-{
-    return x * a + y * b + z * c + d;
-}

+ 0 - 21
client/math/Plane3D.h

@@ -1,21 +0,0 @@
-#ifndef PLANE3D_H
-#define PLANE3D_H
-
-#include "client/math/Vector3D.h"
-
-class Plane3D
-{
-public:
-    Plane3D();
-
-    void set(const Vector3D& va, const Vector3D& vb, const Vector3D& vc);
-    float getSignedDistance(float x, float y, float z) const;
-    
-private:
-    float a = 1.0f;
-    float b = 1.0f;
-    float c = 1.0f;
-    float d = 1.0f;
-};
-
-#endif

+ 0 - 19
client/math/StackOverflow.cpp

@@ -1,19 +0,0 @@
-#include "client/math/StackOverflow.h"
-
-StackOverflow::StackOverflow()
-{
-}
-
-StackOverflow::StackOverflow(const StackOverflow& orig)
-{
-}
-
-StackOverflow::~StackOverflow()
-{
-}
-
-const char* StackOverflow::what() const throw()
-{
-    return "push used on full matrix stack";
-}
-

+ 0 - 19
client/math/StackOverflow.h

@@ -1,19 +0,0 @@
-#ifndef STACKOVERFLOW_H
-#define STACKOVERFLOW_H
-
-#include <exception>
-
-class StackOverflow : public std::exception
-{
-public:
-    StackOverflow();
-    StackOverflow(const StackOverflow& orig);
-    virtual ~StackOverflow();
-    
-    virtual const char* what() const throw();
-private:
-
-};
-
-#endif
-

+ 0 - 19
client/math/StackUnderflow.cpp

@@ -1,19 +0,0 @@
-#include "client/math/StackUnderflow.h"
-
-StackUnderflow::StackUnderflow()
-{
-}
-
-StackUnderflow::StackUnderflow(const StackUnderflow& orig)
-{
-}
-
-StackUnderflow::~StackUnderflow()
-{
-}
-
-const char* StackUnderflow::what() const throw()
-{
-    return "pop used on matrix stack of index 0";
-}
-

+ 0 - 19
client/math/StackUnderflow.h

@@ -1,19 +0,0 @@
-#ifndef STACKUNDERFLOW_H
-#define STACKUNDERFLOW_H
-
-#include <exception>
-
-class StackUnderflow : public std::exception
-{
-public:
-    StackUnderflow();
-    StackUnderflow(const StackUnderflow& orig);
-    virtual ~StackUnderflow();
-    
-    virtual const char* what() const throw();
-private:
-
-};
-
-#endif
-

+ 139 - 0
client/math/Vector.cpp

@@ -0,0 +1,139 @@
+#include <cmath>
+
+#include "client/math/Vector.h"
+
+Vector::Vector() : x(0), y(0), z(0)
+{
+}
+
+Vector::Vector(float ix, float iy, float iz) : x(ix), y(iy), z(iz)
+{
+}
+
+float Vector::getX() const
+{
+    return x;
+}
+
+float Vector::getY() const
+{
+    return y;
+}
+
+float Vector::getZ() const
+{
+    return z;
+}
+
+void Vector::setX(float ix)
+{
+    x = ix;
+}
+
+void Vector::setY(float iy)
+{
+    y = iy;
+}
+
+void Vector::setZ(float iz)
+{
+    z = iz;
+}
+
+void Vector::set(float ix, float iy, float iz)
+{
+    x = ix;
+    y = iy;
+    z = iz;
+}
+
+void Vector::setInverse(const Vector& v)
+{
+    x = -v.x;
+    y = -v.y;
+    z = -v.z;
+}
+
+void Vector::setMul(const Vector& v, float f)
+{
+    x = v.x * f;
+    y = v.y * f;
+    z = v.z * f;
+}
+
+void Vector::setAngles(float lengthAngle, float widthAngle)
+{
+    lengthAngle = lengthAngle * M_PI / 180.0f;
+    widthAngle = widthAngle * M_PI / 180.0f;
+    x = cosf(widthAngle) * sinf(lengthAngle);
+    y = sinf(widthAngle);
+    z = cosf(widthAngle) * cosf(lengthAngle); 
+}
+
+
+void Vector::add(const Vector& v)
+{
+    x += v.x;
+    y += v.y;
+    z += v.z;
+}
+
+void Vector::sub(const Vector& v)
+{
+    x -= v.x;
+    y -= v.y;
+    z -= v.z;
+}
+
+void Vector::mul(float f)
+{
+    x *= f;
+    y *= f;
+    z *= f;
+}
+
+void Vector::addMul(const Vector& v, float f)
+{
+    x += v.x * f;
+    y += v.y * f;
+    z += v.z * f;
+}
+
+
+void Vector::cross(float ix, float iy, float iz)
+{
+    set(y * iz - z * iy, z * ix - x * iz, x * iy - y * ix);
+}
+
+void Vector::cross(const Vector& v)
+{
+    set(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
+}
+
+void Vector::normalize()
+{
+    float f = 1.0f / sqrtf(squareLength());
+    x *= f;
+    y *= f;
+    z *= f;
+}
+
+float Vector::squareLength() const
+{
+    return x * x + y * y + z * z;
+}
+
+float Vector::dot(const Vector& v) const
+{
+    return x * v.x + y * v.y + z * v.z;
+}
+
+float Vector::dotInverse(const Vector& v) const
+{
+    return x * (-v.x) + y * (-v.y) + z * (-v.z);
+}
+
+std::ostream& operator<<(std::ostream& os, const Vector& v)
+{
+    return os << "Vector(x = " << v.getX() << ", y = " << v.getY() << ", z = " << v.getZ() << ")";
+}

+ 47 - 0
client/math/Vector.h

@@ -0,0 +1,47 @@
+#ifndef VECTOR_H
+#define VECTOR_H
+
+#include <iostream>
+
+class Vector final
+{
+public:
+    Vector();
+    Vector(float ix, float iy, float iz);
+    
+    float getX() const;
+    float getY() const;
+    float getZ() const;
+    
+    void setX(float ix);
+    void setY(float iy);
+    void setZ(float iz);
+    
+    void set(float ix, float iy, float iz);
+    void setInverse(const Vector& v);
+    void setMul(const Vector& v, float f);
+    void setAngles(float lengthAngle, float widthAngle);
+    
+    void add(const Vector& v);
+    void sub(const Vector& v);
+    void mul(float f);
+    void addMul(const Vector& v, float f);
+    
+    void cross(float ix, float iy, float iz);
+    void cross(const Vector& v);
+    
+    void normalize();
+    float squareLength() const;
+    
+    float dot(const Vector& v) const;
+    float dotInverse(const Vector& v) const;
+    
+private:
+    float x;
+    float y;
+    float z;
+};
+
+std::ostream& operator<<(std::ostream& os, const Vector& v);
+
+#endif

+ 0 - 157
client/math/Vector3D.cpp

@@ -1,157 +0,0 @@
-#include <cmath>
-
-#include "client/math/Vector3D.h"
-
-Vector3D::Vector3D() : x(0), y(0), z(0)
-{
-}
-
-Vector3D::Vector3D(float ix, float iy, float iz) : x(ix), y(iy), z(iz)
-{
-}
-
-Vector3D::Vector3D(const Vector3D& orig) : x(orig.x), y(orig.y), z(orig.z)
-{
-}
-
-Vector3D::~Vector3D()
-{
-}
-
-float Vector3D::getX() const
-{
-    return x;
-}
-
-float Vector3D::getY() const
-{
-    return y;
-}
-
-float Vector3D::getZ() const
-{
-    return z;
-}
-
-void Vector3D::setX(float ix)
-{
-    x = ix;
-}
-
-void Vector3D::setY(float iy)
-{
-    y = iy;
-}
-
-void Vector3D::setZ(float iz)
-{
-    z = iz;
-}
-
-void Vector3D::set(float ix, float iy, float iz)
-{
-    x = ix;
-    y = iy;
-    z = iz;
-}
-
-void Vector3D::set(const Vector3D& v)
-{
-    x = v.x;
-    y = v.y;
-    z = v.z;
-}
-
-void Vector3D::setInverse(const Vector3D& v)
-{
-    x = -v.x;
-    y = -v.y;
-    z = -v.z;
-}
-
-void Vector3D::setMul(const Vector3D& v, float f)
-{
-    x = v.x * f;
-    y = v.y * f;
-    z = v.z * f;
-}
-
-void Vector3D::setAngles(float lengthAngle, float widthAngle)
-{
-    lengthAngle = lengthAngle * M_PI / 180.0f;
-    widthAngle = widthAngle * M_PI / 180.0f;
-    x = cosf(widthAngle) * sinf(lengthAngle);
-    y = sinf(widthAngle);
-    z = cosf(widthAngle) * cosf(lengthAngle); 
-}
-
-
-void Vector3D::add(const Vector3D& v)
-{
-    x += v.x;
-    y += v.y;
-    z += v.z;
-}
-
-void Vector3D::sub(const Vector3D& v)
-{
-    x -= v.x;
-    y -= v.y;
-    z -= v.z;
-}
-
-void Vector3D::mul(float f)
-{
-    x *= f;
-    y *= f;
-    z *= f;
-}
-
-void Vector3D::addMul(const Vector3D& v, float f)
-{
-    x += v.x * f;
-    y += v.y * f;
-    z += v.z * f;
-}
-
-
-void Vector3D::cross(float ix, float iy, float iz)
-{
-    set(y * iz - z * iy, z * ix - x * iz, x * iy - y * ix);
-}
-
-void Vector3D::cross(const Vector3D& v)
-{
-    set(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
-}
-
-
-void Vector3D::normalize()
-{
-    float f = length();
-    x /= f;
-    y /= f;
-    z /= f;
-}
-
-float Vector3D::length() const
-{
-    return sqrtf(x * x + y * y + z * z);
-}
-
-float Vector3D::dot(const Vector3D& v) const
-{
-    return x * v.x + y * v.y + z * v.z;
-}
-
-float Vector3D::dotInverse(const Vector3D& v) const
-{
-    return x * (-v.x) + y * (-v.y) + z * (-v.z);
-}
-
-std::ostream& operator<<(std::ostream& os, const Vector3D& v)
-{
-    return os << "Vector3D(x = " << v.getX() << ", y = " << v.getY() << ", z = " << v.getZ() << ")";
-}
-
-

+ 0 - 50
client/math/Vector3D.h

@@ -1,50 +0,0 @@
-#ifndef VECTOR3D_H
-#define VECTOR3D_H
-
-#include <iostream>
-
-class Vector3D
-{
-public:
-    Vector3D();
-    Vector3D(float ix, float iy, float iz);
-    Vector3D(const Vector3D& orig);
-    virtual ~Vector3D();
-    
-    float getX() const;
-    float getY() const;
-    float getZ() const;
-    
-    void setX(float ix);
-    void setY(float iy);
-    void setZ(float iz);
-    
-    void set(float ix, float iy, float iz);
-    void set(const Vector3D& v);
-    void setInverse(const Vector3D& v);
-    void setMul(const Vector3D& v, float f);
-    void setAngles(float lengthAngle, float widthAngle);
-    
-    void add(const Vector3D& v);
-    void sub(const Vector3D& v);
-    void mul(float f);
-    void addMul(const Vector3D& v, float f);
-    
-    void cross(float ix, float iy, float iz);
-    void cross(const Vector3D& v);
-    
-    void normalize();
-    float length() const;
-    
-    float dot(const Vector3D& v) const;
-    float dotInverse(const Vector3D& v) const;
-private:
-    float x;
-    float y;
-    float z;
-};
-
-std::ostream& operator<<(std::ostream& os, const Vector3D& v);
-
-#endif
-

+ 0 - 101
client/rendering/ChunkRenderer.cpp

@@ -1,101 +0,0 @@
-#include "client/rendering/ChunkRenderer.h"
-#include "client/rendering/block/BlockRenderers.h"
-#include "client/rendering/block/BlockRenderer.h"
-
-ChunkRenderer::ChunkRenderer() : blockTexture("resources/textures.png")
-{
-    mesh = new NormalTextureMesh[chunkX * chunkZ * Chunk::HEIGHT_PARTIONS];
-}
-
-ChunkRenderer::~ChunkRenderer()
-{
-    delete[] mesh;
-}
-
-void ChunkRenderer::renderTick(Shader& shader, Camera3D camera, DirectRenderer& dr, float lag)
-{
-    blockTexture.bind();
-    
-    for(int x = 0; x < chunkX; x++)
-    {
-        for(int z = 0; z < chunkZ; z++)
-        {
-            int sx = x * Chunk::WIDTH;
-            int sz = z * Chunk::DEPTH;
-            int ex = sx + Chunk::WIDTH;
-            int ez = sz + Chunk::DEPTH;
-            
-            if(camera.isInFrustum(sx, 0, sz, ex, Chunk::HEIGHT, ez))
-            {
-                shader.translateTo(x * Chunk::WIDTH, 0, z * Chunk::DEPTH);
-                shader.updateModelMatrix();
-
-                for(int l = 0; l < Chunk::HEIGHT_PARTIONS; l++)
-                {
-                    if(camera.isInFrustum(sx, l * Chunk::PARTION_HEIGHT, sz, ex, (l + 1) * Chunk::PARTION_HEIGHT, ez))
-                    {
-                        mesh[l + z * Chunk::HEIGHT_PARTIONS + x * chunkZ * Chunk::HEIGHT_PARTIONS].draw();
-                    }
-                }
-            }
-        }
-    }
-}
-
-void ChunkRenderer::updateChunk(Chunk& c, Chunk* north, Chunk* east, Chunk* south, Chunk* west)
-{
-    int x = c.getChunkX();
-    int z = c.getChunkZ();
-    if(x < 0 || x >= chunkX || z < 0 || z >= chunkZ)
-    {
-        return;
-    }
-    cout << "UPDATE: " << x << " " << z << endl;
-    for(int l = 0; l < Chunk::HEIGHT_PARTIONS; l++)
-    {
-        if(c.isDirty(l))
-        {
-            buildChunk(l, c, north, east, south, west);
-        }
-    }
-}
-
-void ChunkRenderer::buildChunk(int partionY, Chunk& c, Chunk* north, Chunk* east, Chunk* south, Chunk* west)
-{    
-    Mesh& m = mesh[partionY + c.getChunkZ() * Chunk::HEIGHT_PARTIONS + c.getChunkX() * chunkZ * Chunk::HEIGHT_PARTIONS];
-    
-    int max = (partionY + 1) * Chunk::PARTION_HEIGHT;
-    for(int y = partionY * Chunk::PARTION_HEIGHT; y < max; y++)
-    {
-        for(int x = 0; x < Chunk::WIDTH; x++)
-        {
-            for(int z = 0; z < Chunk::DEPTH; z++)
-            {
-                const Block& block = c.getBlock(x, y, z);
-                if(!block.isEmpty())
-                {
-                    BlockRenderers::getBlockRenderer(block.getId()).addToMesh(m, x, y, z,
-                        Face::getCullData(
-                            // top
-                            y + 1 < Chunk::HEIGHT && c.getBlock(x, y + 1, z).isBlockingFace(Face::DOWN), 
-                            // bottom
-                            y > 0 && c.getBlock(x, y - 1, z).isBlockingFace(Face::UP), 
-                            // north
-                            (x + 1 >= Chunk::WIDTH || c.getBlock(x + 1, y, z).isBlockingFace(Face::SOUTH)) && 
-                            (x + 1 < Chunk::WIDTH || (north != nullptr && north->getBlock(x + 1 - Chunk::WIDTH, y, z).isBlockingFace(Face::SOUTH))), 
-                            // south
-                            (x - 1 < 0 || c.getBlock(x - 1, y, z).isBlockingFace(Face::NORTH)) && 
-                            (x - 1 >= 0 || (south != nullptr && south->getBlock(x - 1 + Chunk::WIDTH, y, z).isBlockingFace(Face::NORTH))), 
-                            // east
-                            (z + 1 >= Chunk::DEPTH || c.getBlock(x, y, z + 1).isBlockingFace(Face::WEST)) && 
-                            (z + 1 < Chunk::DEPTH || (east != nullptr && east->getBlock(x, y, z + 1 - Chunk::DEPTH).isBlockingFace(Face::WEST))), 
-                            // west
-                            (z - 1 < 0 || c.getBlock(x, y, z - 1).isBlockingFace(Face::EAST)) && 
-                            (z - 1 >= 0 || (west != nullptr && west->getBlock(x, y, z - 1 + Chunk::DEPTH).isBlockingFace(Face::EAST)))));
-                }
-            }
-        }
-    }
-    
-    m.build();
-}

+ 0 - 30
client/rendering/ChunkRenderer.h

@@ -1,30 +0,0 @@
-#ifndef CHUNKRENDERER_H
-#define CHUNKRENDERER_H
-
-#include "client/engine/Mesh.h"
-#include "client/engine/Shader.h"
-#include "client/engine/Texture.h"
-#include "client/engine/DirectRenderer.h"
-#include "common/world/IChunkListener.h"
-#include "client/math/Camera3D.h"
-
-class ChunkRenderer : public IChunkListener
-{
-public:
-    ChunkRenderer();
-    virtual ~ChunkRenderer();
-    
-    void renderTick(Shader& shader, Camera3D camera, DirectRenderer& dr, float lag);
-    void updateChunk(Chunk& c, Chunk* north, Chunk* east, Chunk* south, Chunk* west) override;
-private:
-    void buildChunk(int partionY, Chunk& c, Chunk* north, Chunk* east, Chunk* south, Chunk* west);
-    
-    const int chunkX = 32;
-    const int chunkZ = 32;
-    NormalTextureMesh* mesh;
-    
-    Texture blockTexture;
-};
-
-#endif
-

+ 0 - 50
client/rendering/ClientChunkProvider.cpp

@@ -1,50 +0,0 @@
-#include "client/rendering/ClientChunkProvider.h"
-
-ClientChunkProvider::ClientChunkProvider()
-{
-    chunks = new Chunk*[chunkX * chunkZ];
-    for(int x = 0; x < chunkX; x++)
-    {
-        for(int z = 0; z < chunkZ; z++)
-        {
-            chunks[x + z * chunkX] = new Chunk(x, z);
-        }
-    }
-}
-
-ClientChunkProvider::~ClientChunkProvider()
-{
-    for(int i = 0; i < chunkX * chunkZ; i++)
-    {
-        delete chunks[i];
-    }
-    delete[] chunks;
-}
-
-Chunk* ClientChunkProvider::getChunk(int x, int z)
-{
-    if(isChunkLoaded(x, z))
-    {
-        return chunks[x + z * chunkX];
-    }
-    return nullptr;
-}
-        
-bool ClientChunkProvider::isChunkLoaded(int x, int z) const
-{
-    return x >= 0 && x < chunkX && z >= 0 && z < chunkZ;
-}
-
-void ClientChunkProvider::forEachLoadedChunk(void* data, void (*fun) (Chunk&, void*)) const
-{
-    for(int x = 0; x < chunkX; x++)
-    {
-        for(int z = 0; z < chunkZ; z++)
-        {
-            fun(*chunks[x + z * chunkX], data);
-        }
-    }
-}
-
-        
-

+ 0 - 23
client/rendering/ClientChunkProvider.h

@@ -1,23 +0,0 @@
-#ifndef CLIENTCHUNKPROVIDER_H
-#define CLIENTCHUNKPROVIDER_H
-
-#include "common/world/IChunkProvider.h"
-
-class ClientChunkProvider : public IChunkProvider
-{
-public:
-    ClientChunkProvider();
-    virtual ~ClientChunkProvider();
-    
-    Chunk* getChunk(int x, int z) override;
-    bool isChunkLoaded(int x, int z) const override;
-    void forEachLoadedChunk(void* data, void (*fun) (Chunk&, void*)) const override;
-    
-private:
-    const int chunkX = 32;
-    const int chunkZ = 32;
-    Chunk** chunks;
-};
-
-#endif
-

+ 116 - 0
client/rendering/FontRenderer.cpp

@@ -0,0 +1,116 @@
+#include "client/rendering/FontRenderer.h"
+
+const size_t FontRenderer::BUFFER_LENGTH = 8 * 1024 * 1024;
+
+FontRenderer::FontRenderer() : tex("resources/font8x8.png"), offset(BUFFER_LENGTH), vba(0), vbo(0)
+{
+    glGenVertexArrays(1, &vba);
+    glBindVertexArray(vba);
+    
+    glGenBuffers(1, &vbo);
+    glBindBuffer(GL_ARRAY_BUFFER, vbo);
+    
+    glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(float) * 7, (GLvoid*) (sizeof(float) * 0));
+    glEnableVertexAttribArray(0);
+
+    glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 7, (GLvoid*) (sizeof(float) * 2));
+    glEnableVertexAttribArray(1);  
+    
+    glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof(float) * 7, (GLvoid*) (sizeof(float) * 4));
+    glEnableVertexAttribArray(2);
+}
+
+FontRenderer::~FontRenderer()
+{
+    glDeleteVertexArrays(1, &vba);
+    glDeleteBuffers(1, &vbo);
+}
+
+void FontRenderer::drawString(float x, float y, const char* text)
+{
+    glBindBuffer(GL_ARRAY_BUFFER, vbo);
+    
+    const size_t maxIndex = 256;
+    const size_t maxLength = maxIndex * 4 * sizeof(float) * 7;
+    
+    if(offset + maxLength >= BUFFER_LENGTH)
+    {
+        offset = 0;
+        glBufferData(GL_ARRAY_BUFFER, BUFFER_LENGTH, nullptr, GL_STREAM_DRAW);
+    }
+    
+    float* buffer = static_cast<float*>(glMapBufferRange(GL_ARRAY_BUFFER, offset, maxLength, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT));
+    if(buffer == nullptr)
+    {
+        return;
+    }
+    
+    size_t index = 0;
+    size_t i = 0;
+    float r = 1.0f;
+    float g = 1.0f;
+    float b = 1.0f;
+    
+    while(text[index] != '\0' && index < maxIndex)
+    {
+        char c = text[index];
+        if(c == '&')
+        {
+            if(text[index + 1] == '\0' || text[index + 2] == '\0' || text[index + 3] == '\0')
+            {
+                break;
+            }
+            r = (text[index + 1] - '0') * (1.0f / 9.0f);
+            g = (text[index + 2] - '0') * (1.0f / 9.0f);
+            b = (text[index + 3] - '0') * (1.0f / 9.0f);
+            index += 4;
+            continue;
+        }
+
+        float minX = (c & 0xF) * (1.0f / 16.0f);
+        float minY = (c >> 4) * (1.0f / 16.0f);
+        float maxX = minX + (1.0f / 16.0f);
+        float maxY = minY + (1.0f / 16.0f);
+        
+        buffer[i++] = x;
+        buffer[i++] = y;
+        buffer[i++] = minX;
+        buffer[i++] = minY;
+        buffer[i++] = r;
+        buffer[i++] = g;
+        buffer[i++] = b;
+        
+        buffer[i++] = x;
+        buffer[i++] = y + 8;
+        buffer[i++] = minX;
+        buffer[i++] = maxY;
+        buffer[i++] = r;
+        buffer[i++] = g;
+        buffer[i++] = b;
+        
+        buffer[i++] = x + 8;
+        buffer[i++] = y;
+        buffer[i++] = maxX;
+        buffer[i++] = minY;
+        buffer[i++] = r;
+        buffer[i++] = g;
+        buffer[i++] = b;
+        
+        buffer[i++] = x + 8;
+        buffer[i++] = y + 8;
+        buffer[i++] = maxX;
+        buffer[i++] = maxY;
+        buffer[i++] = r;
+        buffer[i++] = g;
+        buffer[i++] = b;
+        
+        x += 8;
+        index++;
+    }
+    
+    glUnmapBuffer(GL_ARRAY_BUFFER);
+    glBindVertexArray(vba);
+    tex.bind(0);
+    glDrawArrays(GL_TRIANGLE_STRIP, offset / (sizeof(float) * 7), i / 7);
+    offset += maxLength;
+}

+ 31 - 0
client/rendering/FontRenderer.h

@@ -0,0 +1,31 @@
+#ifndef FONTRENDERER_H
+#define FONTRENDERER_H
+
+#include <GL/glew.h>
+#include <array>
+
+#include "client/rendering/Texture.h"
+
+class FontRenderer final
+{
+public:
+    FontRenderer();
+    ~FontRenderer();
+    
+    FontRenderer(const FontRenderer& other) = delete;
+    FontRenderer(FontRenderer&& other) = delete;
+    FontRenderer& operator=(const FontRenderer& other) = delete;
+    FontRenderer& operator=(FontRenderer&& other) = delete;
+    
+    void drawString(float x, float y, const char* text);
+    
+private:
+    Texture tex;
+    static const size_t BUFFER_LENGTH;
+    size_t offset;
+    
+    GLuint vba;
+    GLuint vbo;
+};
+
+#endif

+ 169 - 0
client/rendering/Framebuffer.cpp

@@ -0,0 +1,169 @@
+#include <iostream>
+
+#include "Framebuffer.h"
+#include "client/Utils.h"
+
+Framebuffer::Framebuffer(u32 width, u32 height, u32 mode) : mode(mode), buffer(0), valid(false)
+{
+    glGenFramebuffers(1, &buffer);
+    glBindFramebuffer(GL_FRAMEBUFFER, buffer);
+    
+    GLuint attachments[4];
+    u32 counter = 0;
+    
+    if(mode & POSITION) // position texture
+    {
+        glGenTextures(1, &(textures[0]));
+        glBindTexture(GL_TEXTURE_2D, textures[0]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[0], 0); 
+        attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
+        counter++;
+    }
+      
+    if(mode & NORMAL) // normal texture
+    {
+        glGenTextures(1, &(textures[1]));
+        glBindTexture(GL_TEXTURE_2D, textures[1]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[1], 0);  
+        attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
+        counter++;
+    }
+    
+    if(mode & COLOR) // color texture
+    {
+        glGenTextures(1, &(textures[2]));
+        glBindTexture(GL_TEXTURE_2D, textures[2]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[2], 0);  
+        attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
+        counter++;
+    }
+    
+    if(mode & RED) // single color channel texture
+    {
+        glGenTextures(1, &textures[3]);
+        glBindTexture(GL_TEXTURE_2D, textures[3]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[3], 0);  
+        attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
+        counter++;
+    }
+    
+    if(mode & DEPTH24_STENCIL8) // depth texture
+    {
+        glGenTextures(1, &textures[4]);
+        glBindTexture(GL_TEXTURE_2D, textures[4]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textures[4], 0); 
+    }
+    
+    glDrawBuffers(counter, attachments);   
+    
+    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+    {
+	std::cout << "frame buffer is not complete\n";
+        return;
+    }
+    valid = true;
+}
+
+Framebuffer::~Framebuffer()
+{
+    glDeleteFramebuffers(1, &buffer);
+    for(GLuint& texture : textures)
+    {
+        glDeleteTextures(1, &texture);
+    }
+}
+
+bool Framebuffer::isValid() const
+{
+    return valid;
+}
+
+void Framebuffer::bind() const
+{
+    glBindFramebuffer(GL_FRAMEBUFFER, buffer);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+}
+
+void Framebuffer::resize(u32 width, u32 height) const
+{
+    if(mode & POSITION) // position texture
+    {
+        glBindTexture(GL_TEXTURE_2D, textures[0]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
+    }
+    if(mode & NORMAL) // normal texture
+    {
+        glBindTexture(GL_TEXTURE_2D, textures[1]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
+    }
+    if(mode & COLOR) // color texture
+    {
+        glBindTexture(GL_TEXTURE_2D, textures[2]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+    }
+    if(mode & RED) // single color channel texture
+    {
+        glBindTexture(GL_TEXTURE_2D, textures[3]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
+    }
+    if(mode & DEPTH24_STENCIL8) // depth texture
+    {
+        glBindTexture(GL_TEXTURE_2D, textures[4]);
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
+    }
+}
+
+void Framebuffer::bindPositionTexture(u32 textureUnit) const
+{
+    glActiveTexture(GL_TEXTURE0 + textureUnit);
+    glBindTexture(GL_TEXTURE_2D, textures[0]);
+}
+
+void Framebuffer::bindNormalTexture(u32 textureUnit) const
+{
+    glActiveTexture(GL_TEXTURE0 + textureUnit);
+    glBindTexture(GL_TEXTURE_2D, textures[1]);
+}
+
+void Framebuffer::bindColorTexture(u32 textureUnit) const
+{
+    glActiveTexture(GL_TEXTURE0 + textureUnit);
+    glBindTexture(GL_TEXTURE_2D, textures[2]);
+}
+
+void Framebuffer::bindRedTexture(u32 textureUnit) const
+{
+    glActiveTexture(GL_TEXTURE0 + textureUnit);
+    glBindTexture(GL_TEXTURE_2D, textures[3]);
+}
+
+void Framebuffer::bindDepthTexture(u32 textureUnit) const
+{
+    glActiveTexture(GL_TEXTURE0 + textureUnit);
+    glBindTexture(GL_TEXTURE_2D, textures[4]);
+}

+ 44 - 0
client/rendering/Framebuffer.h

@@ -0,0 +1,44 @@
+#ifndef FRAMEBUFFER_H
+#define FRAMEBUFFER_H
+
+#include <GL/glew.h>
+#include <array>
+
+#include "common/utils/Types.h"
+
+class Framebuffer final
+{
+public:
+    static const u32 POSITION = 1;
+    static const u32 NORMAL = 2;
+    static const u32 COLOR = 4;
+    static const u32 RED = 8;
+    static const u32 DEPTH24_STENCIL8 = 16;
+    
+    Framebuffer(u32 width, u32 height, u32 mode);
+    ~Framebuffer();
+    
+    bool isValid() const;
+    void bind() const;
+    
+    void resize(u32 width, u32 height) const;
+    
+    void bindPositionTexture(u32 textureUnit) const;
+    void bindNormalTexture(u32 textureUnit) const;
+    void bindColorTexture(u32 textureUnit) const;
+    void bindRedTexture(u32 textureUnit) const;
+    void bindDepthTexture(u32 textureUnit) const;
+    
+private:
+    Framebuffer(const Framebuffer& other) = delete;
+    Framebuffer(Framebuffer&& other) = delete;
+    Framebuffer& operator=(const Framebuffer& other) = delete;
+    Framebuffer& operator=(Framebuffer&& other) = delete;
+
+    u32 mode;
+    std::array<GLuint, 5> textures;
+    GLuint buffer;
+    bool valid;
+};
+
+#endif

+ 47 - 0
client/rendering/Mesh.cpp

@@ -0,0 +1,47 @@
+#include "client/rendering/Mesh.h"
+
+Mesh::Mesh() : vba(0), vbo(0)
+{
+    glGenVertexArrays(1, &vba);
+    glBindVertexArray(vba);
+    
+    glGenBuffers(1, &vbo);
+    glBindBuffer(GL_ARRAY_BUFFER, vbo);
+
+    glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(VertexData), (GLvoid*) (sizeof(float) * 0));
+    glEnableVertexAttribArray(0);
+
+    glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(VertexData), (GLvoid*) (sizeof(float) * 3));
+    glEnableVertexAttribArray(1);  
+    
+    glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof(VertexData), (GLvoid*) (sizeof(float) * 5));
+    glEnableVertexAttribArray(2);
+}
+
+Mesh::~Mesh()
+{
+    glDeleteVertexArrays(1, &vba);
+    glDeleteBuffers(1, &vbo);
+}
+
+void Mesh::add(const VertexData& data)
+{
+    buffer.push_back(data);
+}
+
+void Mesh::clear()
+{
+    buffer.clear();
+}
+
+void Mesh::build() const
+{
+    glBindBuffer(GL_ARRAY_BUFFER, vbo);
+    glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * buffer.size(), buffer.data(), GL_STATIC_DRAW);
+}
+
+void Mesh::draw() const
+{
+    glBindVertexArray(vba);
+    glDrawArrays(GL_TRIANGLES, 0, buffer.size());
+}

+ 42 - 0
client/rendering/Mesh.h

@@ -0,0 +1,42 @@
+#ifndef MESH_H
+#define MESH_H
+
+#include <GL/glew.h>
+#include <vector>
+
+class Mesh final
+{
+public:
+    struct VertexData final
+    {
+        float x;
+        float y;
+        float z;
+        float tx;
+        float ty;
+        float nx;
+        float ny;
+        float nz;
+    };
+    
+    Mesh();
+    ~Mesh();
+    
+    void add(const VertexData& data);
+    
+    void clear();
+    void build() const;
+    void draw() const;
+    
+private:
+    Mesh(const Mesh& other) = delete;
+    Mesh(Mesh&& other) = delete;
+    Mesh& operator=(const Mesh& other) = delete;
+    Mesh& operator=(Mesh&& other) = delete;
+    
+    GLuint vba;
+    GLuint vbo;
+    std::vector<VertexData> buffer;
+};
+
+#endif

+ 113 - 0
client/rendering/Shader.cpp

@@ -0,0 +1,113 @@
+#include <fstream>
+#include <cstring>
+
+#include "client/rendering/Shader.h"
+#include "client/Utils.h"
+
+Shader::Shader(const GLchar* vPath, const GLchar* fPath) : valid(false), 
+        vShader(0), fShader(0), program(0)
+{
+    std::vector<GLchar> vCode;
+    std::vector<GLchar> fCode;
+    bool vCheck = readFile(vCode, vPath);
+    bool fCheck = readFile(fCode, fPath);
+    if(vCheck || fCheck)
+    {
+        return;
+    }
+    
+    vCheck = compileShader(vShader, vCode.data(), GL_VERTEX_SHADER);
+    fCheck = compileShader(fShader, fCode.data(), GL_FRAGMENT_SHADER);
+    if(vCheck || fCheck)
+    {
+        return;
+    }
+    
+    program = glCreateProgram();
+    glAttachShader(program, vShader);
+    glAttachShader(program, fShader);
+    glLinkProgram(program);
+    
+    if(checkAndPrintError("shader linking error"))
+    {
+        return;
+    }
+
+    GLint linked;
+    glGetProgramiv(program, GL_LINK_STATUS, &linked);
+    if(linked == GL_FALSE)
+    {
+        GLchar buffer[512];
+        glGetProgramInfoLog(program, 512, nullptr, buffer);
+        std::cout << "programm linking info log: " << buffer << "\n";
+        return;
+    }
+    valid = true;
+}
+
+Shader::~Shader()
+{
+    glDeleteProgram(program);
+    glDeleteShader(vShader);
+    glDeleteShader(fShader);
+}
+
+bool Shader::isValid() const
+{
+    return valid;
+}
+
+bool Shader::readFile(std::vector<GLchar>& buffer, const GLchar* path) const
+{
+    std::ifstream in;
+    in.open(path);
+    if(in.fail())
+    {
+        std::cout << "cannot read shader file: '" << path << "'\n"; 
+        return true;
+    }
+    while(true)
+    {
+        GLchar c = in.get();
+        if(in.eof())
+        {
+            break;
+        }
+        buffer.push_back(c);
+    }
+    buffer.push_back('\0');
+    return false;
+}
+
+bool Shader::compileShader(GLuint& shader, const GLchar* code, GLenum shaderType) const
+{
+    shader = glCreateShader(shaderType);
+    glShaderSource(shader, 1, &code, nullptr);
+    glCompileShader(shader);
+
+    if(checkAndPrintError("shader error"))
+    {
+        return true;
+    }
+    
+    GLint compiled;
+    glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
+    if(compiled == GL_FALSE)
+    {
+        GLchar buffer[512];
+        glGetShaderInfoLog(shader, 512, nullptr, buffer);
+        std::cout << "shader info log: " << buffer << "\n";
+        return true;
+    }
+    return false;
+}
+
+void Shader::use() const
+{
+    glUseProgram(program);
+}
+
+void Shader::setMatrix(const GLchar* name, const float* data) const
+{
+    glUniformMatrix4fv(glGetUniformLocation(program, name), 1, GL_FALSE, data);
+}

+ 35 - 0
client/rendering/Shader.h

@@ -0,0 +1,35 @@
+#ifndef SHADER_H
+#define SHADER_H
+
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+#include <iostream>
+#include <vector>
+
+class Shader final
+{
+public:
+    Shader(const GLchar* vPath, const GLchar* fPath);
+    ~Shader();
+
+    bool isValid() const;
+    void use() const;
+    void setMatrix(const GLchar* name, const float* data) const;
+    
+private:
+    Shader(const Shader& other) = delete;
+    Shader(Shader&& other) = delete;
+    Shader& operator=(const Shader& other) = delete;
+    Shader& operator=(Shader&& other) = delete;
+    
+    bool readFile(std::vector<GLchar>& buffer, const GLchar* path) const;
+    bool compileShader(GLuint& shader, const GLchar* code, GLenum shaderType) const;
+    
+    bool valid;
+    GLuint vShader;
+    GLuint fShader;
+    GLuint program;
+};
+
+#endif
+

+ 23 - 51
client/engine/Texture.cpp → client/rendering/Texture.cpp

@@ -1,14 +1,10 @@
 #include <png.h>
 
-#include "client/engine/Texture.h"
+#include "client/rendering/Texture.h"
 
 Texture::Texture(const char* path)
 {
-    if(!load(path))
-    {
-        loaded = true;
-        cout << "cannot load texture " << path << endl;
-    }
+    load(path);
 }
 
 Texture::~Texture()
@@ -23,13 +19,13 @@ Texture::~Texture()
     }
 }
 
-bool Texture::load(const char* path)
+void Texture::load(const char* path)
 {
     FILE* file = fopen(path, "r");
-    if(file == NULL)
+    if(file == nullptr)
     {
-        cerr << "image '" << path << "' does not exist" << endl;
-        return false;
+        std::cout << "texture '" << path << "' does not exist\n";
+        return;
     }
     bool b = load(path, file);
     fclose(file);
@@ -37,7 +33,6 @@ bool Texture::load(const char* path)
     {
         initGL();
     }
-    return b;
 }
 
 bool Texture::load(const char* path, FILE* file)
@@ -46,42 +41,42 @@ bool Texture::load(const char* path, FILE* file)
     unsigned char buffer[8];
     if(fread(buffer, sizeof(char), 8, file) != 8)
     {
-        cerr << "cannot read signature of image '" << path << "'" << endl;
+        std::cout << "cannot read signature of texture '" << path << "'\n";
         return false;
     }
     
     if(png_sig_cmp(buffer, 0, 8))        
     {
-        cerr << "file '" << path << "' is not an image" << endl;
+        std::cout << "file '" << path << "' is not a texture\n";
         return false;
     }
     
     // create structures for data
-    png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-    if(png == NULL)
+    png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
+    if(png == nullptr)
     {
-        cerr << "cannot create image data structure" << endl;
+        std::cout << "cannot create texture data structure\n";
         return false;
     }
     
     png_infop info = png_create_info_struct(png);
-    if(info == NULL)
+    if(info == nullptr)
     {
-       cerr << "cannot create image info structure" << endl;
+       std::cout << "cannot create image info structure\n";
        return false;
     }
 
-    unsigned int** rowPointers = NULL;
+    u32** rowPointers = nullptr;
     
     // set callback for errors
     if(setjmp(png_jmpbuf(png)))
     {
-        if(rowPointers != NULL)
+        if(rowPointers != nullptr)
         {
             png_free(png, rowPointers);
         }
-        png_destroy_read_struct(&png, &info, NULL);
-        cerr << "image '" << path << "' has used error callback" << endl;
+        png_destroy_read_struct(&png, &info, nullptr);
+        std::cout << "texture '" << path << "' has used error callback\n";
         return false;
     }
 
@@ -96,10 +91,10 @@ bool Texture::load(const char* path, FILE* file)
     height = png_get_image_height(png, info);
     
     // read image data
-    data = new unsigned int[width * height];
+    data = new u32[width * height];
     
     // allocate and set row pointer to correct places in block
-    rowPointers = (unsigned int**) png_malloc(png, height * (sizeof(unsigned int*)));
+    rowPointers = (u32**) png_malloc(png, height * (sizeof(u32*)));
     for(unsigned int i = 0; i < height; i++)
     {
         rowPointers[i] = (data + i * width);
@@ -115,7 +110,6 @@ bool Texture::load(const char* path, FILE* file)
 
 void Texture::initGL()
 {
-    glActiveTexture(GL_TEXTURE0);
     glGenTextures(1, &texture);
     glBindTexture(GL_TEXTURE_2D, texture);
     
@@ -123,36 +117,14 @@ void Texture::initGL()
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-    
-    /*for(int i = 0; i < width * height; i++)
-    {
-        if(data[i] != 0)
-        {
-            cout << "X";
-        }
-        else
-        {
-            cout << " ";
-        }
-        
-        if(i != 0 && i % width == 0)
-        {
-            cout << endl;
-        }
-    }*/
-    
+
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
     delete[] data;
     data = nullptr;
 }
 
-void Texture::bind()
+void Texture::bind(unsigned int index) const
 {
+    glActiveTexture(GL_TEXTURE0 + index);
     glBindTexture(GL_TEXTURE_2D, texture);
-}
-
-bool Texture::isLoaded()
-{
-    return loaded;
-}
-
+}

+ 37 - 0
client/rendering/Texture.h

@@ -0,0 +1,37 @@
+#ifndef TEXTURE_H
+#define TEXTURE_H
+
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+#include <iostream>
+
+#include "common/utils/Types.h"
+
+class Texture final
+{
+public:
+    Texture(const char* path);
+    ~Texture();
+    
+    Texture(const Texture& other) = delete;
+    Texture(Texture&& other) = delete;
+    Texture& operator=(const Texture& other) = delete;
+    Texture& operator=(Texture&& other) = delete;
+    
+    void bind(unsigned int index) const;
+    
+private:
+    void load(const char* path);
+    bool load(const char* path, FILE* file);
+    void initGL();
+    
+    u32 width;
+    u32 height;
+    u32* data;
+    
+    GLuint texture = 0;
+};
+
+#endif
+
+

+ 0 - 171
client/rendering/block/BlockRenderer.cpp

@@ -1,171 +0,0 @@
-#include "client/rendering/block/BlockRenderer.h"
-#include "common/utils/Face.h"
-
-BlockRenderer::BlockRenderer()
-{
-}
-
-void BlockRenderer::addTriangle(float p1x, float p1y, float p1z, float p1nx, float p1ny, float p1nz, float p1texX, float p1texY, 
-                                float p2x, float p2y, float p2z, float p2nx, float p2ny, float p2nz, float p2texX, float p2texY, 
-                                float p3x, float p3y, float p3z, float p3nx, float p3ny, float p3nz, float p3texX, float p3texY, 
-                                int cullData)
-{
-    // move texture coords a small amount to the middle of the triagngle
-    // to prevent calculation errors getting out of the range of the texture
-    float f = 1.0f / 256.0f;
-    
-    float mid1x = (((p2texX + p3texX) * 0.5) - p1texX) * f;
-    float mid1y = (((p2texY + p3texY) * 0.5) - p1texY) * f;
-    float mid2x = (((p1texX + p3texX) * 0.5) - p2texX) * f;
-    float mid2y = (((p1texY + p3texY) * 0.5) - p2texY) * f;
-    float mid3x = (((p2texX + p1texX) * 0.5) - p3texX) * f;
-    float mid3y = (((p2texY + p1texY) * 0.5) - p3texY) * f;
-    
-    p1texX += mid1x;
-    p1texY += mid1y;
-    p2texX += mid2x;
-    p2texY += mid2y;
-    p3texX += mid3x;
-    p3texY += mid3y;
-    
-    data.push_back(Triangle());
-    Triangle& tri = data[data.size() - 1];
-    
-    tri.p1x = p1x;
-    tri.p1y = p1y;
-    tri.p1z = p1z;
-    
-    tri.p1nx = p1nx;
-    tri.p1ny = p1ny;
-    tri.p1nz = p1nz;
-    
-    tri.p1texX = p1texX;
-    tri.p1texY = p1texY;
-    
-    tri.p2x = p2x;
-    tri.p2y = p2y;
-    tri.p2z = p2z;
-    
-    tri.p2nx = p2nx;
-    tri.p2ny = p2ny;
-    tri.p2nz = p2nz;
-    
-    tri.p2texX = p2texX;
-    tri.p2texY = p2texY;
-    
-    tri.p3x = p3x;
-    tri.p3y = p3y;
-    tri.p3z = p3z;
-    
-    tri.p3nx = p3nx;
-    tri.p3ny = p3ny;
-    tri.p3nz = p3nz;
-    
-    tri.p3texX = p3texX;
-    tri.p3texY = p3texY;
-    
-    tri.cullData = cullData;
-}
-    
-void BlockRenderer::addCuboid(float sx, float sy, float sz, float ex, float ey, float ez,
-               float topTexStartX, float topTexStartY, float topTexEndX, float topTexEndY, 
-               float bottomTexStartX, float bottomTexStartY, float bottomTexEndX, float bottomTexEndY, 
-               float northTexStartX, float northTexStartY, float northTexEndX, float northTexEndY, 
-               float southTexStartX, float southTexStartY, float southTexEndX, float southTexEndY, 
-               float eastTexStartX, float eastTexStartY, float eastTexEndX, float eastTexEndY, 
-               float westTexStartX, float westTexStartY, float westTexEndX, float westTexEndY)
-{
-    // bottom side
-    addTriangle(
-            sx, sy, sz, 0.0f, -1.0f, 0.0f, bottomTexStartX, bottomTexStartY,
-            ex, sy, sz, 0.0f, -1.0f, 0.0f, bottomTexEndX, bottomTexStartY,
-            sx, sy, ez, 0.0f, -1.0f, 0.0f, bottomTexStartX, bottomTexEndY,
-            Face::DOWN.getCullData());
-    addTriangle(
-            ex, sy, sz, 0.0f, -1.0f, 0.0f, bottomTexEndX, bottomTexStartY,
-            ex, sy, ez, 0.0f, -1.0f, 0.0f, bottomTexEndX, bottomTexEndY,
-            sx, sy, ez, 0.0f, -1.0f, 0.0f, bottomTexStartX, bottomTexEndY,
-            Face::DOWN.getCullData());
-    
-    // top side
-    addTriangle(
-            sx, ey, sz, 0.0f, 1.0f, 0.0f, topTexStartX, topTexStartY,
-            sx, ey, ez, 0.0f, 1.0f, 0.0f, topTexStartX, topTexEndY,
-            ex, ey, sz, 0.0f, 1.0f, 0.0f, topTexEndX, topTexStartY,
-            Face::UP.getCullData());
-    addTriangle(
-            ex, ey, sz, 0.0f, 1.0f, 0.0f, topTexEndX, topTexStartY,
-            sx, ey, ez, 0.0f, 1.0f, 0.0f, topTexStartX, topTexEndY,
-            ex, ey, ez, 0.0f, 1.0f, 0.0f, topTexEndX, topTexEndY,
-            Face::UP.getCullData());
-    
-    // north side
-    addTriangle(
-            ex, sy, sz, 1.0f, 0.0f, 0.0f, northTexStartX, northTexEndY,
-            ex, ey, ez, 1.0f, 0.0f, 0.0f, northTexEndX, northTexStartY,
-            ex, sy, ez, 1.0f, 0.0f, 0.0f, northTexEndX, northTexEndY,
-            Face::NORTH.getCullData());
-    addTriangle(
-            ex, sy, sz, 1.0f, 0.0f, 0.0f, northTexStartX, northTexEndY,
-            ex, ey, sz, 1.0f, 0.0f, 0.0f, northTexStartX, northTexStartY,
-            ex, ey, ez, 1.0f, 0.0f, 0.0f, northTexEndX, northTexStartY,
-            Face::NORTH.getCullData());
-    
-    // south side
-    addTriangle(
-            sx, sy, sz, -1.0f, 0.0f, 0.0f, southTexStartX, southTexEndY,
-            sx, sy, ez, -1.0f, 0.0f, 0.0f, southTexEndX, southTexEndY,
-            sx, ey, ez, -1.0f, 0.0f, 0.0f, southTexEndX, southTexStartY,
-            Face::SOUTH.getCullData());
-    addTriangle(
-            sx, sy, sz, -1.0f, 0.0f, 0.0f, southTexStartX, southTexEndY,
-            sx, ey, ez, -1.0f, 0.0f, 0.0f, southTexEndX, southTexStartY,
-            sx, ey, sz, -1.0f, 0.0f, 0.0f, southTexStartX, southTexStartY,
-            Face::SOUTH.getCullData());
-    
-    // east side
-    addTriangle(
-            sx, sy, ez, 0.0f, 0.0f, 1.0f, eastTexStartX, eastTexEndY,
-            ex, sy, ez, 0.0f, 0.0f, 1.0f, eastTexEndX, eastTexEndY,
-            ex, ey, ez, 0.0f, 0.0f, 1.0f, eastTexEndX, eastTexStartY,
-            Face::EAST.getCullData());
-    addTriangle(
-            sx, sy, ez, 0.0f, 0.0f, 1.0f, eastTexStartX, eastTexEndY,
-            ex, ey, ez, 0.0f, 0.0f, 1.0f, eastTexEndX, eastTexStartY,
-            sx, ey, ez, 0.0f, 0.0f, 1.0f, eastTexStartX, eastTexStartY,
-            Face::EAST.getCullData());
-    
-    // west side
-    addTriangle(
-            sx, sy, sz, 0.0f, 0.0f, -1.0f, westTexStartX, westTexEndY,
-            ex, ey, sz, 0.0f, 0.0f, -1.0f, westTexEndX, westTexStartY,
-            ex, sy, sz, 0.0f, 0.0f, -1.0f, westTexEndX, westTexEndY,
-            Face::WEST.getCullData());
-    addTriangle(
-            sx, sy, sz, 0.0f, 0.0f, -1.0f, westTexStartX, westTexEndY,
-            sx, ey, sz, 0.0f, 0.0f, -1.0f, westTexStartX, westTexStartY,
-            ex, ey, sz, 0.0f, 0.0f, -1.0f, westTexEndX, westTexStartY,
-            Face::WEST.getCullData());
-}
-
-void BlockRenderer::addToMesh(Mesh& m, int offsetX, int offsetY, int offsetZ, int cullData) const
-{
-    for(const Triangle& tri : data)
-    {
-        // if any cull bits of a block are the same as of a triangle => do not render
-        if((cullData & tri.cullData) == 0)
-        {
-            m.addPosition(offsetX + tri.p1x, offsetY + tri.p1y, offsetZ + tri.p1z);
-            m.addPosition(offsetX + tri.p2x, offsetY + tri.p2y, offsetZ + tri.p2z);
-            m.addPosition(offsetX + tri.p3x, offsetY + tri.p3y, offsetZ + tri.p3z);
-            
-            m.addNormal(tri.p1nx, tri.p1ny, tri.p1nz);
-            m.addNormal(tri.p2nx, tri.p2ny, tri.p2nz);
-            m.addNormal(tri.p3nx, tri.p3ny, tri.p3nz);
-            
-            m.addTexture(tri.p1texX, tri.p1texY);
-            m.addTexture(tri.p2texX, tri.p2texY);
-            m.addTexture(tri.p3texX, tri.p3texY);
-        }
-    }
-}

+ 0 - 73
client/rendering/block/BlockRenderer.h

@@ -1,73 +0,0 @@
-#ifndef BLOCKRENDERER_H
-#define BLOCKRENDERER_H
-
-#include <vector>
-
-#include "client/engine/Mesh.h"
-
-using namespace std;
-
-class BlockRenderer
-{
-public:
-    BlockRenderer();
-    
-    void addTriangle(float p1x, float p1y, float p1z, float p1nx, float p1ny, float p1nz, float p1texX, float p1texY, 
-                     float p2x, float p2y, float p2z, float p2nx, float p2ny, float p2nz, float p2texX, float p2texY, 
-                     float p3x, float p3y, float p3z, float p3nx, float p3ny, float p3nz, float p3texX, float p3texY, 
-                     int cullData);
-    
-    void addCuboid(float sx, float sy, float sz, float ex, float ey, float ez,
-                   float topTexStartX, float topTexStartY, float topTexEndX, float topTexEndY, 
-                   float bottomTexStartX, float bottomTexStartY, float bottomTexEndX, float bottomTexEndY, 
-                   float northTexStartX, float northTexStartY, float northTexEndX, float northTexEndY, 
-                   float southTexStartX, float southTexStartY, float southTexEndX, float southTexEndY, 
-                   float eastTexStartX, float eastTexStartY, float eastTexEndX, float eastTexEndY, 
-                   float westTexStartX, float westTexStartY, float westTexEndX, float westTexEndY);
-    
-    void addToMesh(Mesh& m, int offsetX, int offsetY, int offsetZ, int cullData) const;
-    
-private:
-    struct Triangle
-    {
-        float p1x;
-        float p1y;
-        float p1z;
-        
-        float p1nx;
-        float p1ny;
-        float p1nz;
-        
-        float p1texX;
-        float p1texY;
-        
-        float p2x;
-        float p2y;
-        float p2z;
-        
-        float p2nx;
-        float p2ny;
-        float p2nz;
-        
-        float p2texX;
-        float p2texY;
-        
-        float p3x;
-        float p3y;
-        float p3z;
-        
-        float p3nx;
-        float p3ny;
-        float p3nz;
-        
-        float p3texX;
-        float p3texY;
-        
-        int cullData;
-    };
-    
-    vector<Triangle> data;
-};
-
-#endif
-

+ 0 - 41
client/rendering/block/BlockRenderers.cpp

@@ -1,41 +0,0 @@
-#include "client/rendering/block/BlockRenderers.h"
-
-const int BlockRenderers::RENDERER_AMOUNT = 4;
-BlockRenderer BlockRenderers::RENDERER[RENDERER_AMOUNT];
-
-BlockRenderers::BlockRenderers()
-{
-}
-
-const BlockRenderer& BlockRenderers::getBlockRenderer(BlockId id)
-{
-    return RENDERER[id * (id >= 0 && id < RENDERER_AMOUNT)];
-}
-
-void BlockRenderers::init()
-{
-    RENDERER[1].addCuboid(-1, -1, -1, 0, 0, 0, 
-            0.25f, 0.0f, 0.3125f, 0.0625f, 
-            0.125f, 0.0f, 0.1875f, 0.0625f, 
-            0.1875f, 0.0f, 0.25f, 0.0625f, 
-            0.1875f, 0.0f, 0.25f, 0.0625f,
-            0.1875f, 0.0f, 0.25f, 0.0625f, 
-            0.1875f, 0.0f, 0.25f, 0.0625f);
-    
-    RENDERER[2].addCuboid(-1, -1, -1, 0, 0, 0, 
-            0.125f, 0.0f, 0.1875f, 0.0625f,
-            0.125f, 0.0f, 0.1875f, 0.0625f, 
-            0.125f, 0.0f, 0.1875f, 0.0625f, 
-            0.125f, 0.0f, 0.1875f, 0.0625f,
-            0.125f, 0.0f, 0.1875f, 0.0625f, 
-            0.125f, 0.0f, 0.1875f, 0.0625f);
-    
-    RENDERER[3].addCuboid(-1, -1, -1, 0, 0, 0, 
-            0.0625f, 0.0f, 0.125f, 0.0625f,
-            0.0625f, 0.0f, 0.125f, 0.0625f, 
-            0.0625f, 0.0f, 0.125f, 0.0625f, 
-            0.0625f, 0.0f, 0.125f, 0.0625f,
-            0.0625f, 0.0f, 0.125f, 0.0625f, 
-            0.0625f, 0.0f, 0.125f, 0.0625f);
-}
-

+ 0 - 21
client/rendering/block/BlockRenderers.h

@@ -1,21 +0,0 @@
-#ifndef BLOCKRENDERERS_H
-#define BLOCKRENDERERS_H
-
-#include "common/block/Block.h"
-#include "client/rendering/block/BlockRenderer.h"
-
-class BlockRenderers
-{
-public:
-    static const BlockRenderer& getBlockRenderer(BlockId id);
-    static void init();
-
-private:
-    BlockRenderers();
-    
-    static const int RENDERER_AMOUNT;
-    static BlockRenderer RENDERER[];
-};
-
-#endif
-

+ 0 - 133
client/rendering/entity/EntityRenderer.cpp

@@ -1,133 +0,0 @@
-#include "client/rendering/entity/EntityRenderer.h"
-#include "client/engine/Utils.h"
-
-EntityRenderer::EntityRenderer() : texture("resources/skin.png")
-{
-    // head
-    mesh.addCuboid(0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f, 
-            0.125f, 0.0f, 0.25f, 0.125f,
-            0.25f, 0.0f, 0.375f, 0.125f,
-            0.25f, 0.125f, 0.375f, 0.25f,
-            0.0f, 0.125f, 0.125f, 0.25f,
-            0.125f, 0.125f, 0.25f, 0.25f,
-            0.375f, 0.125f, 0.5f, 0.25f);
-    // right arm
-    mesh.addCuboid(0.0f, 0.0f, 0.0f, 0.25f, 0.75f, 0.25f, 
-            0.6875f, 0.25f, 0.75f, 0.3125f,
-            0.75f, 0.25f, 0.8125f, 0.3125f,
-            0.75f, 0.3125f, 0.8125f, 0.5f,
-            0.625f, 0.3125f, 0.6875f, 0.5f,
-            0.6875f, 0.3125f, 0.75f, 0.5f,
-            0.8125f, 0.3125f, 0.875f, 0.5f);
-    // left arm
-    mesh.addCuboid(0.0f, 0.0f, 0.0f, 0.25f, 0.75f, 0.25f, 
-            0.5625f, 0.75f, 0.625f, 0.8125f,
-            0.625f, 0.75f, 0.6875f, 0.8125f,
-            0.625f, 0.8125f, 0.6875f, 1.0f,
-            0.5f, 0.8125f, 0.5625f, 1.0f,
-            0.5625f, 0.8125f, 0.625f, 1.0f,
-            0.6875f, 0.8125f, 0.75f, 1.0f);
-    // body
-    mesh.addCuboid(0.0f, 0.0f, 0.0f, 0.5f, 0.75f, 0.25f, 
-            0.3125f, 0.25f, 0.4375f, 0.3125f,
-            0.4375f, 0.25f, 0.5625f, 0.3125f,
-            0.4375f, 0.3125f, 0.5f, 0.5f,
-            0.25f, 0.3125f, 0.3125f, 0.5f,
-            0.3125f, 0.3125f, 0.4375f, 0.5f,
-            0.5f, 0.3125f, 0.625f, 0.5f);
-    // right leg
-    mesh.addCuboid(0.0f, 0.0f, 0.0f, 0.25f, 0.75f, 0.25f, 
-            0.0625f, 0.25f, 0.125f, 0.3125f,
-            0.125f, 0.25f, 0.1875f, 0.3125f,
-            0.125f, 0.3125f, 0.1875f, 0.5f,
-            0.0f, 0.3125f, 0.0625f, 0.5f,
-            0.0625f, 0.3125f, 0.125f, 0.5f,
-            0.1875f, 0.3125f, 0.25f, 0.5f);
-    // left leg
-    mesh.addCuboid(0.0f, 0.0f, 0.0f, 0.25f, 0.75f, 0.25f, 
-            0.3125f, 0.75f, 0.375f, 0.8125f,
-            0.375f, 0.75f, 0.4375f, 0.8125f,
-            0.375f, 0.8125f, 0.4375f, 1.0f,
-            0.25f, 0.8125f, 0.3125f, 1.0f,
-            0.3125f, 0.8125f, 0.375f, 1.0f,
-            0.4375f, 0.8125f, 0.5f, 1.0f);
-    mesh.build();
-}
-
-EntityRenderer::~EntityRenderer()
-{
-}
-
-void EntityRenderer::tick()
-{
-    lifetime += 15;
-}
-
-void EntityRenderer::renderTick(Shader& shader, Camera3D camera, DirectRenderer& dr, float lag)
-{
-    const int d = 360;
-    
-    float f1 = lifetime % d;
-    if(f1 >= d / 2)
-    {
-        f1 = d - f1;
-    }
-    
-    float f2 = (lifetime + 15) % d;
-    if(f2 >= d / 2)
-    {
-        f2 = d - f2;
-    }
-    
-    float inter = interpolate(lag, f1, f2);
-    
-    texture.bind();
-    
-    shader.setToIdentity();
-    shader.translateTo(5.0f + 0.5f, 42.0f, 15.0f + 0.25f);
-    //shader.scale(3, 6, 3);
-    shader.rotateY(90);
-    shader.translate(-0.5f, 0.0f, -0.25f);
-    
-    shader.push();
-    shader.translate(0.25f + 0.25f, 1.5f, 0.0f + 0.25f);
-    shader.rotateY(inter * 0.25f - 22.5f);
-    shader.translate(-0.25f, 0.0f, -0.25f);
-    shader.updateModelMatrix(); 
-    mesh.draw(0, 36);
-    shader.pop();
-    
-    shader.push();
-    shader.translate(0.0f, 1.375f, 0.25f);
-    shader.rotateX(inter / 6 - 15);
-    shader.translate(0.0f, -0.625f, -0.125f);
-    shader.updateModelMatrix();  
-    mesh.draw(36, 36);
-    shader.pop();
-    
-    shader.push();
-    shader.translate(0.75f, 1.375f, 0.25f);
-    shader.rotateX(- inter / 6 + 15);
-    shader.translate(0.0f, -0.625f, -0.125f);
-    shader.updateModelMatrix(); 
-    mesh.draw(72, 36);
-    shader.pop();
-    
-    shader.push();
-    shader.translate(0.25f, 0.75f, 0.125f);
-    shader.updateModelMatrix(); 
-    mesh.draw(108, 36);
-    shader.pop();
-    
-    shader.push();
-    shader.translate(0.25f, 0.0f, 0.125f);
-    shader.updateModelMatrix(); 
-    mesh.draw(144, 36);
-    shader.pop();
-    
-    shader.push();
-    shader.translate(0.5f, 0.0f, 0.125f);
-    shader.updateModelMatrix(); 
-    mesh.draw(180, 36);
-    shader.pop();
-}

+ 0 - 26
client/rendering/entity/EntityRenderer.h

@@ -1,26 +0,0 @@
-#ifndef ENTITYRENDERER_H
-#define ENTITYRENDERER_H
-
-#include "client/engine/Shader.h"
-#include "client/math/Camera3D.h"
-#include "client/engine/DirectRenderer.h"
-#include "client/engine/Mesh.h"
-#include "client/engine/Texture.h"
-
-class EntityRenderer
-{
-public:
-    EntityRenderer();
-    virtual ~EntityRenderer();
-    
-    void tick();
-    void renderTick(Shader& shader, Camera3D camera, DirectRenderer& dr, float lag);
-    
-private:
-    Texture texture;
-    NormalTextureMesh mesh;
-    unsigned int lifetime = 0;
-};
-
-#endif
-

+ 0 - 20
client/rendering/gui/GUI.cpp

@@ -1,20 +0,0 @@
-#include "client/rendering/gui/GUI.h"
-
-GUI::GUI()
-{
-}
-
-GUI::~GUI()
-{
-}
-
-GUI* GUI::tick(KeyManager& keyManager, MouseManager& mouseManager)
-{
-    return this;
-}
-
-void GUI::render2DTick(Shader& shader, DirectRenderer& dr, float lag)
-{
-    
-}
-

+ 0 - 26
client/rendering/gui/GUI.h

@@ -1,26 +0,0 @@
-#ifndef GUI_H
-#define GUI_H
-
-// these two are not needed here but prevent further errors
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-#include "client/engine/KeyManager.h"
-#include "client/engine/MouseManager.h"
-#include "client/engine/Shader.h"
-#include "client/engine/DirectRenderer.h"
-
-class GUI
-{
-public:
-    GUI();
-    virtual ~GUI();
-    
-    virtual GUI* tick(KeyManager& keyManager, MouseManager& mouseManager);
-    virtual void render2DTick(Shader& shader, DirectRenderer& dr, float lag);
-private:
-
-};
-
-#endif
-

+ 0 - 10
client/rendering/gui/GUIs.h

@@ -1,10 +0,0 @@
-#ifndef GUIS_H
-#define GUIS_H
-
-enum GUIs 
-{ 
-    START_MENU
-};
-
-#endif
-

+ 0 - 38
client/rendering/gui/StartMenu.cpp

@@ -1,38 +0,0 @@
-#include "client/rendering/gui/StartMenu.h"
-
-StartMenu::StartMenu()
-{
-}
-
-StartMenu::~StartMenu()
-{
-}
-
-void StartMenu::render2DTick(Shader& shader, DirectRenderer& dr, float lag)
-{
-    shader.setToIdentity();
-    shader.updateModelMatrix();
-    
-    float w = Engine::getScaledWidth();
-    float h = Engine::getScaledHeight();
-    
-    Engine::setColorMode();
-    dr.drawRectangle(0, 0, w, h, 0xFF004B96);
-    
-    float halfW = w * 0.5;
-    float halfH = h * 0.5;
-    
-    float startHalfW = w * 0.25;
-    float startHalfH = h * 0.25;
-    
-    dr.drawRectangle(startHalfW, startHalfH, startHalfW + halfW, startHalfH + halfH, 0x30000000);
-    
-    float textWidth;
-    float textHeight;
-    
-    string title = "Cubes Plus Plus";
-    dr.getStringSize(textWidth, textHeight, title);
-    Engine::setMixMode();
-    dr.drawString(startHalfW + (halfW - textWidth) * 0.5, startHalfH + 10, true, title);
-}
-

+ 0 - 18
client/rendering/gui/StartMenu.h

@@ -1,18 +0,0 @@
-#ifndef STARTMENU_H
-#define STARTMENU_H
-
-#include "client/rendering/gui/GUI.h"
-
-class StartMenu : public GUI
-{
-public:
-    StartMenu();
-    virtual ~StartMenu();
-    
-    void render2DTick(Shader& shader, DirectRenderer& dr, float lag) override;
-private:
-
-};
-
-#endif
-

+ 1 - 1
meson.build

@@ -4,7 +4,7 @@ sourcesCommon = ['common/block/BlockRegistry.cpp', 'common/block/Block.cpp', 'co
 
 sourcesServer = ['server/GameServer.cpp', 'server/commands/CommandUtils.cpp', 'server/commands/ServerCommands.cpp', 'server/commands/CommandManager.cpp', 'server/network/Server.cpp', 'server/Main.cpp']
 
-sourcesClient = ['client/Main.cpp', 'client/GameClient.cpp', 'client/Keys.cpp']
+sourcesClient = ['client/Main.cpp', 'client/GameClient.cpp', 'client/input/Keys.cpp', 'client/rendering/Shader.cpp', 'client/Utils.cpp', 'client/rendering/Mesh.cpp', 'client/math/Matrix.cpp', 'client/math/MatrixStack.cpp', 'client/math/Vector.cpp', 'client/math/Camera.cpp', 'client/math/Plane.cpp', 'client/Game.cpp', 'client/input/MouseButtons.cpp', 'client/rendering/Texture.cpp', 'client/rendering/FontRenderer.cpp', 'client/rendering/Framebuffer.cpp']
 
 sourcesTest = ['tests/Main.cpp', 'server/commands/CommandUtils.cpp']
 

+ 13 - 0
resources/shader/test2Fragment.fs

@@ -0,0 +1,13 @@
+#version 430
+
+layout (binding = 1) uniform sampler2D samp;
+
+in vec2 varTex;
+
+out vec4 color;
+
+void main()
+{
+    color = texture(samp, varTex);
+    //color = vec4(1, 0, 1, 1);
+}  

+ 13 - 0
resources/shader/test2Vertex.vs

@@ -0,0 +1,13 @@
+#version 430
+
+layout (location = 0) in vec3 position;
+layout (location = 1) in vec2 tex;
+layout (location = 2) in vec3 normals;
+
+out vec2 varTex;
+
+void main(void)
+{ 
+    varTex = tex;
+    gl_Position = vec4(position, 1.0);
+}

+ 11 - 0
resources/shader/testFragment.fs

@@ -0,0 +1,11 @@
+#version 430
+
+layout (binding = 0) uniform sampler2D samp;
+
+in vec2 varTex;
+out vec4 color;
+
+void main(void)
+{
+    color = texture(samp, varTex);
+}

+ 16 - 0
resources/shader/testVertex.vs

@@ -0,0 +1,16 @@
+#version 430
+
+layout (location = 0) in vec3 position;
+layout (location = 1) in vec2 tex;
+layout (location = 2) in vec3 normals;
+
+uniform mat4 proj;
+uniform mat4 view;
+
+out vec2 varTex;
+
+void main(void)
+{
+    gl_Position = proj * view * vec4(position, 1.0);
+    varTex = tex;
+}

+ 13 - 0
resources/shader/textFragment.fs

@@ -0,0 +1,13 @@
+#version 430
+
+layout (binding = 0) uniform sampler2D samp;
+
+in vec2 varTex;
+in vec3 varColor;
+
+out vec4 color;
+
+void main()
+{
+    color = vec4(varColor, texture(samp, varTex).r);
+}  

+ 19 - 0
resources/shader/textVertex.vs

@@ -0,0 +1,19 @@
+#version 430
+
+layout (location = 0) in vec2 position;
+layout (location = 1) in vec2 tex;
+layout (location = 2) in vec3 color;
+
+uniform mat4 proj;
+uniform mat4 view;
+uniform mat4 model;
+
+out vec2 varTex;
+out vec3 varColor;
+
+void main(void)
+{ 
+    varTex = tex;
+    varColor = color;
+    gl_Position = proj * view * model * vec4(position, 0.0, 1.0);
+}