Initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#define SPEED 2.5f
|
||||
#define SENSITIVITY 0.25f
|
||||
#define NEAR_PlANE 0.1f
|
||||
#define FAR_PlANE 100.0f
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class Camera : public Object {
|
||||
public:
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
float fov();
|
||||
void setFov(float fov);
|
||||
glm::mat4 projection();
|
||||
|
||||
private:
|
||||
float m_fov;
|
||||
float m_pitch;
|
||||
float m_yaw;
|
||||
glm::vec3 m_up;
|
||||
glm::mat4 m_projection;
|
||||
};
|
||||
|
||||
#endif // CAMERA_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef CUBE_H
|
||||
#define CUBE_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class Shader;
|
||||
|
||||
class Cube : public Object {
|
||||
public:
|
||||
Cube();
|
||||
Cube(float r, float g, float b);
|
||||
~Cube();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void setColor(float r, float g, float b);
|
||||
|
||||
private:
|
||||
unsigned int m_vao;
|
||||
unsigned int m_vbo;
|
||||
unsigned int m_vSize;
|
||||
unsigned int m_texture;
|
||||
glm::vec3 m_color;
|
||||
Shader *m_shader;
|
||||
};
|
||||
|
||||
#endif // CUBE_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef CUBE_COLOR_H
|
||||
#define CUBE_COLOR_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class Shader;
|
||||
|
||||
class CubeColor : public Object {
|
||||
public:
|
||||
CubeColor();
|
||||
CubeColor(float r, float g, float b, bool lineMode = false);
|
||||
~CubeColor();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void setLineMode(bool lineMode);
|
||||
void setColor(float r, float g, float b);
|
||||
|
||||
private:
|
||||
bool m_lineMode;
|
||||
unsigned int m_vao;
|
||||
unsigned int m_vbo;
|
||||
unsigned int m_vSize;
|
||||
glm::vec3 m_color;
|
||||
Shader *m_shader;
|
||||
};
|
||||
|
||||
#endif // CUBE_COLOR_H
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity();
|
||||
virtual ~Entity();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
virtual void initialize() = 0;
|
||||
virtual void update() = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void destroy() = 0;
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
bool active() const;
|
||||
void setActive(bool active);
|
||||
|
||||
private:
|
||||
bool m_active;
|
||||
};
|
||||
|
||||
#endif // ENTITY_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#include <map> // map
|
||||
#include <string> // string
|
||||
#include <unordered_map> // unordered_map
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct Character {
|
||||
unsigned int texture; // ID
|
||||
glm::ivec2 size; // Width / height
|
||||
glm::ivec2 bearing; // Offset from baseline to left/top of glyph
|
||||
unsigned int advance; // Offset to advance to next glyph
|
||||
};
|
||||
|
||||
class FontManager {
|
||||
public:
|
||||
FT_Face loadFont(const std::string &path);
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
Character character(const char character) const;
|
||||
const std::map<const char, Character> &characterList() const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, FT_Face> m_fontList;
|
||||
|
||||
std::map<const char, Character> m_characterList;
|
||||
};
|
||||
|
||||
extern FontManager *g_fontManager;
|
||||
|
||||
#endif // FONT_H
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
#include <chrono> // time
|
||||
#include <thread> // sleep_for
|
||||
|
||||
#include "entity.h"
|
||||
#include "window.h"
|
||||
|
||||
class GameState : public Entity {
|
||||
public:
|
||||
static void sleep(int amount) {
|
||||
// Sleep for amount ms
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(amount));
|
||||
}
|
||||
};
|
||||
|
||||
class GameStateManager {
|
||||
public:
|
||||
GameStateManager() : m_state(nullptr) {
|
||||
}
|
||||
|
||||
~GameStateManager() {
|
||||
if(m_state != nullptr) {
|
||||
m_state->destroy();
|
||||
delete m_state;
|
||||
}
|
||||
}
|
||||
|
||||
void setState(GameState* state) {
|
||||
if(m_state != nullptr) {
|
||||
m_state->destroy();
|
||||
delete m_state;
|
||||
}
|
||||
|
||||
m_state = state;
|
||||
if(m_state != nullptr) {
|
||||
m_state->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(m_state != nullptr) {
|
||||
m_state->update();
|
||||
}
|
||||
}
|
||||
|
||||
void render() {
|
||||
if(m_state != nullptr) {
|
||||
m_state->render();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
GameState *m_state;
|
||||
};
|
||||
|
||||
extern GameStateManager *g_gameStateManager;
|
||||
|
||||
#endif // GAMESTATE_H
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
class InputManager : public Entity {
|
||||
public:
|
||||
InputManager();
|
||||
~InputManager();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
enum keyStates {
|
||||
UP = 0,
|
||||
PRESSED,
|
||||
DOWN,
|
||||
RELEASED,
|
||||
};
|
||||
|
||||
char keyState(int key);
|
||||
void setKeyState(int key, int scancode, int action, int mode);
|
||||
float xOffset();
|
||||
float yOffset();
|
||||
void setMouse(double xpos, double ypos);
|
||||
|
||||
private:
|
||||
char m_previousKeyStates[GLFW_KEY_LAST];
|
||||
char m_currentKeyStates[GLFW_KEY_LAST];
|
||||
bool m_firstMouse;
|
||||
float m_xLast;
|
||||
float m_yLast;
|
||||
float m_xOffset;
|
||||
float m_yOffset;
|
||||
};
|
||||
|
||||
extern InputManager *g_inputManager;
|
||||
|
||||
#endif // INPUT_H
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_H
|
||||
#define OBJECT_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
class Object : public Entity {
|
||||
public:
|
||||
Object();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
virtual void initialize();
|
||||
virtual void update();
|
||||
virtual void render();
|
||||
virtual void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
glm::vec3 position() const;
|
||||
void setPosition(glm::vec3 position);
|
||||
void setPosition(float x, float y, float z);
|
||||
glm::vec3 rotation() const;
|
||||
void setRotation(glm::vec3 rotation);
|
||||
void setRotation(float x, float y, float z);
|
||||
glm::vec3 scale() const;
|
||||
void setScale(glm::vec3 scale);
|
||||
void setScale(float x, float y, float z);
|
||||
glm::mat4 model() const;
|
||||
void setModel(glm::mat4 transform);
|
||||
|
||||
private:
|
||||
glm::vec3 m_position;
|
||||
glm::vec3 m_rotation;
|
||||
glm::vec3 m_scale;
|
||||
glm::mat4 m_model;
|
||||
};
|
||||
|
||||
#endif // OBJECT_H
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#define INFO_LOG_SIZE 512
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
Shader(const std::string &vertexSource, const std::string &fragmentSource);
|
||||
~Shader();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Setup shader program
|
||||
std::string readFile(const std::string &path) const;
|
||||
unsigned int compileShader(unsigned int type, const char *shaderSource) const;
|
||||
unsigned int linkShader(unsigned int vertex, unsigned int fragment) const;
|
||||
int checkStatus(unsigned int check, bool isProgram = false) const;
|
||||
|
||||
// Use shader program
|
||||
void use() const;
|
||||
void setFloat(const std::string &name, float f1, float f2, float f3, float f4) const;
|
||||
void setFloat(const std::string &name, glm::vec3 v) const;
|
||||
void setFloat(const std::string &name, glm::vec4 v) const;
|
||||
void setFloat(const std::string &name, glm::mat4 m) const;
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
unsigned int program() const;
|
||||
|
||||
private:
|
||||
unsigned int m_program;
|
||||
};
|
||||
|
||||
#endif // SHADER_H
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef MAINGAME_H
|
||||
#define MAINGAME_H
|
||||
|
||||
#define CUBE 6
|
||||
#define CUBE_SIZE 15
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "gamestate.h"
|
||||
|
||||
class Object;
|
||||
class Text;
|
||||
|
||||
class MainGame : public GameState
|
||||
{
|
||||
public:
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
std::array<Object *, CUBE_SIZE> m_object;
|
||||
Text *m_text;
|
||||
};
|
||||
|
||||
#endif // MAINGAME_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class Shader;
|
||||
|
||||
class Text : public Object {
|
||||
public:
|
||||
Text();
|
||||
~Text();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void setText(std::string text);
|
||||
|
||||
private:
|
||||
unsigned int m_vao;
|
||||
unsigned int m_vbo;
|
||||
glm::vec3 m_color;
|
||||
Shader *m_shader;
|
||||
std::string m_text;
|
||||
};
|
||||
|
||||
#endif // TEXT_H
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class TextureManager {
|
||||
public:
|
||||
unsigned int loadTexture(const std::string &path);
|
||||
void deleteTexture(const unsigned int texture);
|
||||
|
||||
unsigned int createTexture(
|
||||
int format, unsigned int width, unsigned int height, const void *image,
|
||||
int wrap, int filterMin, int filterMag, bool genMipmap = false);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, unsigned int> m_textureList;
|
||||
};
|
||||
|
||||
extern TextureManager *g_textureManager;
|
||||
|
||||
#endif // TEXTURE_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Rick van Vonderen
|
||||
* 0945444
|
||||
* TI2B
|
||||
*/
|
||||
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
class Camera;
|
||||
class GLFWwindow;
|
||||
class Shader;
|
||||
|
||||
class Window : public Entity {
|
||||
public:
|
||||
// Window();
|
||||
Window(int width, int height);
|
||||
~Window();
|
||||
|
||||
bool shouldClose();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void initialize();
|
||||
void update();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
int width();
|
||||
int height();
|
||||
float aspect();
|
||||
float currentTime();
|
||||
float deltaTime();
|
||||
|
||||
GLFWwindow *window();
|
||||
Shader *shader();
|
||||
Shader *shaderColor();
|
||||
Shader *shaderFont();
|
||||
Camera *camera();
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
static void errorCallback(int error, const char *description);
|
||||
static void keyCallback(GLFWwindow *window, int key, int scancode,
|
||||
int action, int mode);
|
||||
static void mouseCallback(GLFWwindow* window, double xpos, double ypos);
|
||||
|
||||
private:
|
||||
int m_width;
|
||||
int m_height;
|
||||
float m_aspect;
|
||||
float m_currentTime;
|
||||
float m_lastFrameTime;
|
||||
float m_deltaTime;
|
||||
|
||||
GLFWwindow *m_window;
|
||||
Shader *m_shader;
|
||||
Shader *m_shaderColor;
|
||||
Shader *m_shaderFont;
|
||||
Camera *m_camera;
|
||||
};
|
||||
|
||||
extern Window *g_window;
|
||||
|
||||
#endif // WINDOW_H
|
||||
Reference in New Issue
Block a user