123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #ifndef GAMEENGINE_H
- #define GAMEENGINE_H
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cstring>
- #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
|