Added Namespace: charcoal

This commit is contained in:
elipzer 2018-09-12 17:03:46 -04:00
parent 3205680062
commit 77e8b0de5e
41 changed files with 1322 additions and 1227 deletions

View File

@ -4,6 +4,8 @@
#include "Util.h"
namespace charcoal
{
Application::Application(int width, int height)
: m_screen_size(width, height)
{
@ -78,3 +80,4 @@ void Application::base_close()
{
close();
}
}

View File

@ -9,6 +9,8 @@
// TODO: Close without rendering next frame.
namespace charcoal
{
using namespace glm;
class Application
@ -48,4 +50,4 @@ protected:
private:
void base_close();
};
}

View File

@ -7,11 +7,8 @@
#include "Exception.h"
namespace
namespace charcoal
{
struct EmptyElement {};
}
template <typename VertexType, typename IndexType, int element_buffer_count = 0, typename Renderable = Renderable<VertexType, IndexType> >
class Batch
{
@ -121,3 +118,4 @@ private:
GLuint m_index_vbo;
GLenum m_gl_index_type;
};
}

View File

@ -4,6 +4,8 @@
#include "Poseable.h"
namespace charcoal
{
using namespace glm;
class Camera
@ -21,3 +23,4 @@ protected:
mat4 m_view_matrix;
mat4 m_projection_matrix;
};
}

View File

@ -2,8 +2,11 @@
#include "Exception.h"
namespace charcoal
{
Camera2D::Camera2D(const vec2& size, const vec2& position)
: Camera2D(vec3(size.x, size.y, 2.0f), vec3(position.x, position.y, 0.0f)) {}
: Camera2D(vec3(size.x, size.y, 2.0f), vec3(position.x, position.y, 0.0f))
{}
Camera2D::Camera2D(const vec3& size, const vec3& position)
{
@ -45,3 +48,4 @@ void Camera2D::update_scale()
m_projection_matrix[1][1] = 2.0f / m_size.y;
m_projection_matrix[2][2] = -2.0f / m_size.z;
}
}

View File

@ -4,6 +4,8 @@
#include <glm/glm.hpp>
namespace charcoal
{
using namespace glm;
class Camera2D : public Camera
@ -29,3 +31,4 @@ private:
vec3 m_size;
vec3 m_position;
};
}

View File

@ -2,6 +2,8 @@
#include <glm/gtc/matrix_transform.hpp>
namespace charcoal
{
Camera3D::Camera3D(
float fov_y,
float aspect_ratio,
@ -78,3 +80,4 @@ void Camera3D::prerender()
);
}
}

View File

@ -4,6 +4,8 @@
#include <glm/glm.hpp>
namespace charcoal
{
using namespace glm;
class Camera3D : public Camera
@ -45,3 +47,4 @@ private:
vec4 m_up;
vec4 m_right;
};
}

View File

@ -2,6 +2,8 @@
#include "stdafx.h"
namespace charcoal
{
enum DrawMode : GLenum
{
DRAW_POINTS = GL_POINTS,
@ -17,3 +19,4 @@ enum DrawMode : GLenum
DRAW_TRIANGLES_ADJACENCY = GL_TRIANGLES_ADJACENCY,
DRAW_PATCHES = GL_PATCHES,
};
}

View File

@ -5,6 +5,8 @@
// TODO: This MUST be changed to something less generic
#define EXCEPTION(message) Exception(message, __FILE__, __LINE__)
namespace charcoal
{
class Exception
{
public:
@ -21,3 +23,4 @@ private:
std::string m_file_name;
int m_line;
};
}

View File

@ -1,5 +1,7 @@
#include "FPS.h"
namespace charcoal
{
FPS::FPS(unsigned short frames /* = 2 */) :
m_iter(frames), m_frames(frames)
{
@ -46,3 +48,4 @@ float FPS::mark()
clock_t diff = (m_clocks[m_iter] - m_clocks[(m_iter > 0 ? m_iter - 1 : m_frames - 1)]);
return ((float)diff) / CLOCKS_PER_SEC;
}
}

View File

@ -2,6 +2,8 @@
#include <ctime>
namespace charcoal
{
//A class to handle the FPS of the game
//Calculations are done per the number of frames specified
//Frames must be a value from 2 - 255
@ -42,3 +44,4 @@ private:
clock_t* m_clocks = nullptr;
};
}

View File

@ -2,6 +2,8 @@
#include "Exception.h"
namespace charcoal
{
std::map<GLFWwindow*, GLFWInputManager*> GLFWInputManager::s_glfw_windows;
GLFWInputManager::~GLFWInputManager()
@ -32,3 +34,4 @@ void GLFWInputManager::key_callback(GLFWwindow* p_window, int key, int scancode,
throw EXCEPTION("Invalid GLFW Key Action: " + std::to_string(action) + " (" + std::to_string(scancode) + ")");
}
}

View File

@ -6,6 +6,8 @@
#include <map>
namespace charcoal
{
class GLFWInputManager : public InputManager
{
public:
@ -19,3 +21,4 @@ private:
static std::map<GLFWwindow*, GLFWInputManager*> s_glfw_windows;
};
}

View File

@ -1,8 +1,9 @@
#include "InputManager.h"
namespace charcoal
{
InputManager::InputManager() {}
InputManager::~InputManager() {}
void InputManager::mark()
@ -79,3 +80,4 @@ const int& InputManager::get_scroll_distance() const
{
return m_scroll_distance;
}
}

View File

@ -44,6 +44,8 @@
#define K_Y 0x59
#define K_Z 0x5A
namespace charcoal
{
using namespace glm;
class InputManager
@ -91,3 +93,4 @@ private:
//TODO: Controller Movement
};
}

View File

@ -1,5 +1,7 @@
#pragma once
namespace charcoal
{
template <typename VertexType, typename IndexType>
struct Mesh
{
@ -11,3 +13,4 @@ struct Mesh
IndexType* indices = nullptr;
unsigned int index_count = 0;
};
}

View File

@ -8,6 +8,8 @@
#include "Mesh.h"
namespace charcoal
{
template <typename VertexType, typename IndexType>
class MeshFactory
{
@ -376,3 +378,4 @@ private:
template <typename VertexType, typename IndexType>
std::vector<Mesh<VertexType, IndexType>*> MeshFactory<VertexType, IndexType>::m_meshes = std::vector<Mesh<VertexType, IndexType>*>();
}

View File

@ -6,6 +6,8 @@
#include "MySimple3DScene.h"
#include "MySimpleCubeScene.h"
using namespace charcoal;
class MyApplication :
public Application
{

View File

@ -4,6 +4,8 @@
#include "MyBasicShaderProgram.h"
using namespace charcoal;
class MyBasicScene : public Scene
{
public:

View File

@ -5,6 +5,8 @@
#include "Mesh.h"
#include "Renderable.h"
using namespace charcoal;
class MyBasicShaderProgram : public ShaderProgram
{
public:

View File

@ -6,6 +6,8 @@
#include "MySimpleShaderProgram.h"
using namespace charcoal;
class MyBatch : public Batch<MySimpleShaderProgram::Vertex, MySimpleShaderProgram::Index, 2>
{
public:

View File

@ -56,7 +56,7 @@ void MySimple2DScene::update(float delta_time, clock_t clock)
else
brightness = (float)(intervals - c) / half_interval;
radians = (float)egm::TAU * c / intervals;
radians = (float)TAU * c / intervals;
{
MySimpleShaderProgram::Color& color = m_batch.get_color(0);

View File

@ -7,6 +7,8 @@
#include "MyBatch.h"
#include "MySimpleShaderProgram.h"
using namespace charcoal;
class MySimple2DScene : public Scene
{
public:

View File

@ -20,7 +20,7 @@ MySimple3DScene::MySimple3DScene(Application& application)
MySimpleShaderProgram::Vertex(2.0f, -1.0f, 0.0f)
), DrawMode::DRAW_TRIANGLES),
m_batch(&m_shape, 2),
m_camera((float)egm::TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f))
m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f))
{}
MySimple3DScene::~MySimple3DScene()
@ -56,7 +56,7 @@ void MySimple3DScene::update(float delta_time, clock_t clock)
else
brightness = (float)(intervals - c) / half_interval;
radians = (float)egm::TAU * c / intervals;
radians = (float)TAU * c / intervals;
{
MySimpleShaderProgram::Color& color = m_batch.get_color(0);

View File

@ -7,6 +7,8 @@
#include "MyBatch.h"
#include "MySimpleShaderProgram.h"
using namespace charcoal;
class MySimple3DScene : public Scene
{
public:

View File

@ -19,7 +19,7 @@ MySimpleCubeScene::MySimpleCubeScene(Application& application)
MySimpleShaderProgram::Vertex( 1.0f, -1.0f, 1.0f)
), DrawMode::DRAW_TRIANGLES),
m_batch(&m_shape, 1),
m_camera((float)egm::TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f))
m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f))
{}
MySimpleCubeScene::~MySimpleCubeScene()
@ -55,7 +55,7 @@ void MySimpleCubeScene::update(float delta_time, clock_t clock)
else
brightness = (float)(intervals - c) / half_interval;
radians = (float)egm::TAU * c / intervals;
radians = (float)TAU * c / intervals;
{
MySimpleShaderProgram::Color& color = m_batch.get_color(0);
@ -65,7 +65,7 @@ void MySimpleCubeScene::update(float delta_time, clock_t clock)
color.a = 1.0f;
Poseable& pose = m_batch.get_pose(0);
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)egm::TAU_1_2 * delta_time);
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time);
pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f));
}
@ -83,7 +83,7 @@ void MySimpleCubeScene::update(float delta_time, clock_t clock)
if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1;
m_camera.translate(camera_translation * delta_time);
m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)egm::TAU_1_8 * delta_time);
m_camera.rotate(vec3(0.0f, 1.0f, 0.0f), camera_rotation * (float)TAU_1_8 * delta_time);
}
void MySimpleCubeScene::prerender()

View File

@ -7,6 +7,8 @@
#include "MyBatch.h"
#include "MySimpleShaderProgram.h"
using namespace charcoal;
class MySimpleCubeScene : public Scene
{
public:

View File

@ -5,6 +5,8 @@
#include "Mesh.h"
#include "Renderable.h"
using namespace charcoal;
class MySimpleShaderProgram : public ShaderProgram
{
public:

View File

@ -146,24 +146,15 @@
<ClInclude Include="ShaderProgram.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="DrawMode.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="Shader.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="Mesh.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="Camera.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="Batch.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="Renderable.h">
<Filter>Header Files\Engine\Rendering</Filter>
</ClInclude>
<ClInclude Include="MyBatch.h">
<Filter>Header Files\Example\Rendering</Filter>
</ClInclude>
@ -200,6 +191,15 @@
<ClInclude Include="MySimpleCubeScene.h">
<Filter>Header Files\Example\Application</Filter>
</ClInclude>
<ClInclude Include="DrawMode.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
<ClInclude Include="Renderable.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
<ClInclude Include="Mesh.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="MySimpleVS.glsl">

View File

@ -2,6 +2,8 @@
#include <glm/gtc/matrix_transform.hpp>
namespace charcoal
{
Poseable::Poseable(
const vec3& position,
const vec3& forward,
@ -13,7 +15,8 @@ Poseable::Poseable(
vec4(up, 0.0f),
vec4(forward, 0.0f),
vec4(position, 1.0f)
) {}
)
{}
void Poseable::update_position(const vec3& position)
{
@ -51,3 +54,4 @@ void Poseable::rotate(const vec3& axis, float angle)
m_orientation_matrix[1] = rotation_matrix * m_orientation_matrix[1];
m_orientation_matrix[2] = rotation_matrix * m_orientation_matrix[2];
}
}

View File

@ -2,6 +2,8 @@
#include <glm/glm.hpp>
namespace charcoal
{
using namespace glm;
class Poseable
@ -27,3 +29,4 @@ public:
protected:
mat4 m_orientation_matrix;
};
}

View File

@ -8,6 +8,8 @@
#include "DrawMode.h"
#include "Batch.h"
namespace charcoal
{
template <typename VertexType, typename IndexType>
class Renderable final
{
@ -17,7 +19,8 @@ public:
typedef Mesh<VertexType, IndexType> MeshType;
Renderable(const MeshType* mesh, const DrawMode& draw_mode)
: m_p_mesh(mesh), m_draw_mode(draw_mode) {}
: m_p_mesh(mesh), m_draw_mode(draw_mode)
{}
const MeshType* get_mesh() const { return m_p_mesh; }
@ -27,3 +30,4 @@ private:
const MeshType* m_p_mesh = nullptr;
DrawMode m_draw_mode;
};
}

View File

@ -6,13 +6,16 @@
#include "Application.h"
namespace charcoal
{
class Scene
{
public:
Scene(Application& application)
: m_screen_size(application.get_screen_size()),
m_input_manager(application.get_input_manager()),
m_fps(application.get_fps()) {};
m_fps(application.get_fps())
{};
virtual ~Scene() {};
// Called when the scene is ready to be initialized
@ -40,4 +43,4 @@ protected:
const GLFWInputManager& m_input_manager;
const FPS& m_fps;
};
}

View File

@ -2,6 +2,8 @@
#include "Exception.h"
namespace charcoal
{
Shader::Shader(const std::string& source, ShaderType type)
{
GLenum gl_shader_type;
@ -49,3 +51,4 @@ GLuint Shader::get_shader() const
{
return m_shader;
}
}

View File

@ -4,6 +4,8 @@
#include <string>
namespace charcoal
{
enum ShaderType
{
VERTEX_SHADER,
@ -21,4 +23,4 @@ public:
private:
GLuint m_shader;
};
}

View File

@ -1,5 +1,7 @@
#include "ShaderProgram.h"
namespace charcoal
{
ShaderProgram::ShaderProgram()
: m_program(glCreateProgram())
{}
@ -29,3 +31,4 @@ GLuint ShaderProgram::get_program() const
{
return m_program;
}
}

View File

@ -6,6 +6,8 @@
#include "Shader.h"
namespace charcoal
{
class ShaderProgram
{
public:
@ -23,3 +25,4 @@ protected:
private:
GLuint m_program = 0;
};
}

View File

@ -9,6 +9,8 @@
#include "Exception.h"
namespace charcoal
{
std::string Util::load_file(const std::string& path)
{
std::ifstream input_stream;
@ -81,3 +83,4 @@ void Util::_check_gl_err(const char* file_name, int line)
if (gl_err != GL_NO_ERROR)
throw Exception(("Caught OpenGL Error: " + std::string((const char*)gluErrorString(gl_err)) + " (" + std::to_string(gl_err) + ")").c_str(), file_name, line);
}
}

View File

@ -5,12 +5,14 @@
#include <glm/glm.hpp>
using namespace glm;
#define DISPLAY_DIGITS 5
#define CHECK_GL_ERR() Util::_check_gl_err(__FILE__, __LINE__)
namespace charcoal
{
using namespace glm;
class Util
{
public:
@ -24,3 +26,4 @@ public:
// Use the CHECK_GL_ERR macro unless you know what you are doing with this function
static void _check_gl_err(const char* file_name, int line);
};
}

View File

@ -3,7 +3,7 @@
#define DEG_TO_RAD(x) x * egm::TAU_1_360;
#define RAD_TO_DEG(x)
namespace egm
namespace charcoal
{
// 2PI = TAU: 6.2831853071795864769252867665590