diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj b/CharcoalBuiltin/CharcoalBuiltin.vcxproj
index 72111cb..b590d4b 100644
--- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj
+++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj
@@ -156,6 +156,10 @@ copy "$(ProjectDir)*.h" "$(SolutionDir)include\charcoal-builtin\"
+
+
+
+
diff --git a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters
index c6659f7..cc6a60e 100644
--- a/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters
+++ b/CharcoalBuiltin/CharcoalBuiltin.vcxproj.filters
@@ -28,6 +28,9 @@
{a0a4d461-a490-40ce-bc57-22c47460f60e}
+
+ {bc6d5912-669e-4e73-8e9e-67e1d4af38be}
+
@@ -107,5 +110,17 @@
Header Files\Pipelines\Textured
+
+ Header Files\Pipelines\Lit
+
+
+ Header Files\Pipelines\Lit
+
+
+ Header Files\Pipelines\Lit
+
+
+ Header Files\Pipelines\Lit
+
\ No newline at end of file
diff --git a/CharcoalBuiltin/LitBatch.h b/CharcoalBuiltin/LitBatch.h
new file mode 100644
index 0000000..80efe95
--- /dev/null
+++ b/CharcoalBuiltin/LitBatch.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "LitTypes.h"
+#include "PoseableBatch.h"
+
+namespace charcoal
+{
+ namespace builtin
+ {
+ namespace lit
+ {
+ class Batch : public PoseableBatch
+ {
+ public:
+ using PoseableBatch::PoseableBatch;
+ protected:
+ void setup_vao_vertex() override
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
+
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+ glEnableVertexAttribArray(2);
+
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal));
+ glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, material));
+
+ glVertexAttribDivisor(0, 0);
+ glVertexAttribDivisor(1, 0);
+ glVertexAttribDivisor(2, 0);
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/CharcoalBuiltin/LitPipeline.h b/CharcoalBuiltin/LitPipeline.h
new file mode 100644
index 0000000..8e3635e
--- /dev/null
+++ b/CharcoalBuiltin/LitPipeline.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "GLUtil.h"
+#include "BuiltinPipeline.h"
+#include "WithCamera.h"
+#include "LitShaderProgram.h"
+#include "LitBatch.h"
+
+namespace charcoal
+{
+ namespace builtin
+ {
+ namespace lit
+ {
+ // TODO: May want to abstract this into a base pipeline class since this is the same as basic::Pipeline
+ class Pipeline : public builtin::Pipeline, public WithCamera
+ {
+ public:
+ void prepare_opengl() override
+ {
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LESS);
+ }
+
+ void prepare_uniforms() override
+ {
+ glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix());
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/CharcoalBuiltin/LitShaderProgram.h b/CharcoalBuiltin/LitShaderProgram.h
new file mode 100644
index 0000000..021dd59
--- /dev/null
+++ b/CharcoalBuiltin/LitShaderProgram.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include
+
+namespace charcoal
+{
+ namespace builtin
+ {
+ namespace lit
+ {
+ class ShaderProgram : public VertexFragmentShaderProgram
+ {
+ public:
+ ShaderProgram() : VertexFragmentShaderProgram(SHADER_PATH "LitVS.glsl", SHADER_PATH "LitFS.glsl") {}
+ };
+ }
+ }
+}
diff --git a/CharcoalBuiltin/LitTypes.h b/CharcoalBuiltin/LitTypes.h
new file mode 100644
index 0000000..188f0f9
--- /dev/null
+++ b/CharcoalBuiltin/LitTypes.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "BuiltinTypes.h"
+
+
+namespace charcoal
+{
+ namespace builtin
+ {
+ namespace lit
+ {
+ typedef PNMVertex Vertex;
+ typedef Index Index;
+ typedef RenderableT Renderable;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Example/Example.vcxproj b/Example/Example.vcxproj
index 306d8ef..19573f5 100644
--- a/Example/Example.vcxproj
+++ b/Example/Example.vcxproj
@@ -24,6 +24,7 @@
+
@@ -36,6 +37,7 @@
+
diff --git a/Example/Example.vcxproj.filters b/Example/Example.vcxproj.filters
index 769100f..2fadeda 100644
--- a/Example/Example.vcxproj.filters
+++ b/Example/Example.vcxproj.filters
@@ -42,6 +42,9 @@
Source Files
+
+ Source Files
+
@@ -74,5 +77,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/Example/MyApplication.cpp b/Example/MyApplication.cpp
index 6521907..f51a001 100644
--- a/Example/MyApplication.cpp
+++ b/Example/MyApplication.cpp
@@ -7,7 +7,8 @@ MyApplication::MyApplication(int width, int height)
m_simple_3d_scene(*this),
m_simple_cube_scene(*this),
m_builtin_basic_cube_scene(*this),
- m_builtin_textured_scene(*this)
+ m_builtin_textured_scene(*this),
+ m_builtin_lit_scene(*this)
{}
void MyApplication::init()
@@ -18,6 +19,7 @@ void MyApplication::init()
m_simple_cube_scene.init();
m_builtin_basic_cube_scene.init();
m_builtin_textured_scene.init();
+ m_builtin_lit_scene.init();
m_p_current_scene = &m_basic_scene;
m_p_current_scene->use();
@@ -49,6 +51,10 @@ void MyApplication::update(float delta_time, clock_t clock)
{
swap_scene(&m_builtin_textured_scene);
}
+ else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_7))
+ {
+ swap_scene(&m_builtin_lit_scene);
+ }
m_p_current_scene->update(delta_time, clock);
}
diff --git a/Example/MyApplication.h b/Example/MyApplication.h
index 5b8d32a..044e9b6 100644
--- a/Example/MyApplication.h
+++ b/Example/MyApplication.h
@@ -9,6 +9,7 @@
#include "MySimpleCubeScene.h"
#include "MyBuiltinCubeScene.h"
#include "MyBuiltinTexturedScene.h"
+#include "MyBuiltinLitScene.h"
using namespace charcoal;
@@ -38,5 +39,6 @@ private:
MySimpleCubeScene m_simple_cube_scene;
MyBuiltinCubeScene m_builtin_basic_cube_scene;
MyBuiltinTexturedScene m_builtin_textured_scene;
+ MyBuiltinLitScene m_builtin_lit_scene;
};
diff --git a/Example/MyBuiltinLitScene.cpp b/Example/MyBuiltinLitScene.cpp
new file mode 100644
index 0000000..d2df1d1
--- /dev/null
+++ b/Example/MyBuiltinLitScene.cpp
@@ -0,0 +1,81 @@
+#include "MyBuiltinLitScene.h"
+
+#include
+
+#include
+
+#include
+
+// TODO: Consider just making a template class for testing out stuff like this...
+// Especially considering that update and render are probably going to be relatively similar almost every time.
+
+MyBuiltinLitScene::MyBuiltinLitScene(Application& application)
+ : Scene(application),
+ m_shape(meshgenerator::gen_cube_p(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f), DrawMode::DRAW_TRIANGLES),
+ 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)),
+ m_batch(&m_shape, 2)
+{
+ m_pipeline.add_batch(&m_batch);
+ m_pipeline.set_camera(&m_camera);
+}
+
+void MyBuiltinLitScene::init()
+{
+ m_batch.init();
+}
+
+void MyBuiltinLitScene::update(float delta_time, clock_t clock)
+{
+ float brightness;
+ float radians;
+
+ clock_t c;
+ const clock_t intervals = 512 * CLOCKS_PER_SEC / 100;
+ const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100;
+ c = clock % intervals;
+ if (c < half_interval)
+ brightness = (float)c / half_interval;
+ else
+ brightness = (float)(intervals - c) / half_interval;
+
+ radians = (float)TAU * c / intervals;
+
+ m_pose_a.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time);
+ m_pose_a.update_position(vec3(3 * (float)cos(radians), 1.0f, 0.0f));
+
+ m_pose_b.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_2 * delta_time);
+ m_pose_b.update_position(vec3(-3 * (float)cos(radians), -1.0f, 0.0f));
+
+ vec3 camera_translation(0.0f, 0.0f, 0.0f);
+
+ if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1;
+ if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1;
+ if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1;
+ if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1;
+ if (m_input_manager.is_key_down(GLFW_KEY_Q)) camera_translation.z -= 1;
+ if (m_input_manager.is_key_down(GLFW_KEY_E)) camera_translation.z += 1;
+
+ float camera_rotation = 0.0f;
+ if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1;
+ 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)TAU_1_8 * delta_time);
+
+ m_batch.reset_rendered();
+ m_batch.add_rendered(m_pose_a);
+ m_batch.add_rendered(m_pose_b);
+}
+
+void MyBuiltinLitScene::prerender()
+{
+ m_camera.prerender();
+ m_batch.prerender();
+}
+
+void MyBuiltinLitScene::render()
+{
+ glutil::clear_screen();
+ m_pipeline.render();
+}
+
diff --git a/Example/MyBuiltinLitScene.h b/Example/MyBuiltinLitScene.h
new file mode 100644
index 0000000..308154f
--- /dev/null
+++ b/Example/MyBuiltinLitScene.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+using namespace charcoal;
+using namespace charcoal::builtin;
+
+class MyBuiltinLitScene : public Scene
+{
+public:
+ // TODO: Add the lights!
+ // This should be done in the pipeline!
+ MyBuiltinLitScene(Application& application);
+
+ void init() override;
+
+ void use() override {}
+
+ void unuse() override {}
+
+ void update(float delta_time, clock_t clock) override;
+
+ void prerender() override;
+
+ void render() override;
+
+private:
+ lit::Renderable m_shape;
+ builtin::Camera3D m_camera;
+ lit::Batch m_batch;
+
+ lit::Pipeline m_pipeline;
+
+ Poseable m_pose_a;
+ Poseable m_pose_b;
+};
\ No newline at end of file