#ifndef WRAPPER_H #define WRAPPER_H #include #include #include "ShaderProgram.h" #include using namespace std; class IClient { public: virtual void tick() = 0; virtual void renderTick(float lag) = 0; virtual void onKeyEvent(int key, int scancode, int action, int mods) = 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 renderTick(float lag) override { cout << "Dummy renderTick" << endl; }; void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << 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 GLint getUniformLocation(const GLchar* name); static void setMatrix(GLint location, const GLfloat* m); static void setInt(GLint location, GLint i); static void setFloat(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4); static void setLineMode(bool mode); static float testX; static float testY; static float testZ; private: static const uint64_t NANOS_PER_TICK = 50000000; static const int MAX_TICKS_PER_FRAME = 5; static bool onProgramInit(); static void onInit(); static void onRenderTick(float lag); static void onTerm(); static GLchar* readFile(const char* name); static bool checkShaderErrors(const char* name, GLuint shader); static GLuint compileProgram(GLuint& vShader, GLuint& fShader, const GLchar* v, const GLchar* f); static GLuint createProgram(const char* v, const char* f, GLuint& vShader, GLuint& fShader); static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods); static void onMouseClick(GLFWwindow* w, int button, int action, int mods); static void onWindowResize(GLFWwindow* w, int width, int height); static void updateScale(); static IClient* client; static GLFWwindow* window; // active program static GLuint activeProgram; // world data static ShaderProgram worldShader; static GLuint worldFrameBuffer; static GLuint worldPositionTexture; static GLuint worldNormalTexture; static GLuint worldColorTexture; static GLuint worldDepthRenderBuffer; // post shader static GLuint postVba; static GLuint postVbo; static ShaderProgram postShader; static int scale; static int width; static int height; static bool lineMode; }; #endif