#ifndef GAMEENGINE_H #define GAMEENGINE_H #include #include #include #include #include #include #include "../math/Matrix3D.h" #include "Camera.h" #include "Texture.h" #include "DirectRenderer.h" #include "Clock.h" using namespace std; static const uint64_t NANOS_PER_TICK = 50000000; static const int MAX_TICKS_PER_FRAME = 5; typedef void (*InitFunction) (); typedef void (*TickFunction) (); typedef void (*RenderTickFunction) (float); class DirectRenderer; class GameEngine { public: static void start(int width, int height, const char* name, InitFunction init, TickFunction tick, RenderTickFunction renderTick); static Camera& getCamera(); static DirectRenderer& getDirectRenderer(); static void setTextureEnabled(bool use); static void setColorEnabled(bool use); static void setMixColorEnabled(bool use); static void setMixColor(float r, float g, float b, float a); static void setUseBlending(bool use); static void printError(); static void stop(); static double getTicksPerSecond(); static double getFramesPerSecond(); friend Camera; friend Texture; friend DirectRenderer; private: GameEngine(); 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 GLchar* readFile(const char* name); static bool checkShaderErrors(const char* name, GLuint shader); static GLuint compileProgram(const GLchar* vertex, const GLchar* fragment); static GLuint createProgram(); static void updateProjection(); static void updateView(Matrix3D& m); static void onInit(); static void onTick(); static void onTerm(); static void updateScale(); static Clock tps; static Clock fps; static InitFunction init; static TickFunction tick; static RenderTickFunction renderTick; static GLuint vShader; static GLuint fShader; static GLFWwindow* window; static GLuint program; static int scale; static int width; static int height; static float fovY; static float nearClip; static float farClip; static Matrix3D proj; static Camera camera; static DirectRenderer directRenderer; // uniforms static GLint unifProjMatrix; static GLint unifViewMatrix; static GLint unifUseTexture; static GLint unifUseColor; static GLint unifUseMixColor; static GLint unifMixColorLoc; }; #endif