From 6164aa82b23f4c7557edd9097c365e6376ac03d0 Mon Sep 17 00:00:00 2001 From: elipzer Date: Tue, 11 Sep 2018 01:18:17 -0400 Subject: [PATCH] Cleaned up File Names --- OpenGLEngine/MyApplication.cpp | 16 +- OpenGLEngine/MyApplication.h | 12 +- .../{MyFragmentShader.glsl => MyBasicFS.glsl} | 0 .../{MySimpleScene.cpp => MyBasicScene.cpp} | 16 +- .../{MySimpleScene.h => MyBasicScene.h} | 12 +- OpenGLEngine/MyBasicShaderProgram.cpp | 13 ++ ...ShaderProgram.h => MyBasicShaderProgram.h} | 17 +-- .../{MyVertexShader.glsl => MyBasicVS.glsl} | 0 OpenGLEngine/MyBatch.cpp | 6 +- OpenGLEngine/MyBatch.h | 12 +- OpenGLEngine/MyBatchTestShaderProgram.cpp | 13 -- OpenGLEngine/MyBatchTestVertexShader.glsl | 14 -- OpenGLEngine/MyObjectOrientedScene.cpp | 138 ------------------ OpenGLEngine/MyShaderProgram.cpp | 13 -- OpenGLEngine/MySimple2DScene.cpp | 102 +++++++++++++ ...bjectOrientedScene.h => MySimple2DScene.h} | 13 +- .../{My3DScene.cpp => MySimple3DScene.cpp} | 51 ++----- .../{My3DScene.h => MySimple3DScene.h} | 13 +- ...estFragmentShader.glsl => MySimpleFS.glsl} | 0 OpenGLEngine/MySimpleShaderProgram.cpp | 13 ++ ...haderProgram.h => MySimpleShaderProgram.h} | 12 +- OpenGLEngine/MySimpleVS.glsl | 13 ++ OpenGLEngine/OpenGLEngine.vcxproj | 28 ++-- OpenGLEngine/OpenGLEngine.vcxproj.filters | 56 +++---- 24 files changed, 259 insertions(+), 324 deletions(-) rename OpenGLEngine/{MyFragmentShader.glsl => MyBasicFS.glsl} (100%) rename OpenGLEngine/{MySimpleScene.cpp => MyBasicScene.cpp} (70%) rename OpenGLEngine/{MySimpleScene.h => MyBasicScene.h} (57%) create mode 100644 OpenGLEngine/MyBasicShaderProgram.cpp rename OpenGLEngine/{MyShaderProgram.h => MyBasicShaderProgram.h} (67%) rename OpenGLEngine/{MyVertexShader.glsl => MyBasicVS.glsl} (100%) delete mode 100644 OpenGLEngine/MyBatchTestShaderProgram.cpp delete mode 100644 OpenGLEngine/MyBatchTestVertexShader.glsl delete mode 100644 OpenGLEngine/MyObjectOrientedScene.cpp delete mode 100644 OpenGLEngine/MyShaderProgram.cpp create mode 100644 OpenGLEngine/MySimple2DScene.cpp rename OpenGLEngine/{MyObjectOrientedScene.h => MySimple2DScene.h} (53%) rename OpenGLEngine/{My3DScene.cpp => MySimple3DScene.cpp} (57%) rename OpenGLEngine/{My3DScene.h => MySimple3DScene.h} (57%) rename OpenGLEngine/{MyBatchTestFragmentShader.glsl => MySimpleFS.glsl} (100%) create mode 100644 OpenGLEngine/MySimpleShaderProgram.cpp rename OpenGLEngine/{MyBatchTestShaderProgram.h => MySimpleShaderProgram.h} (67%) create mode 100644 OpenGLEngine/MySimpleVS.glsl diff --git a/OpenGLEngine/MyApplication.cpp b/OpenGLEngine/MyApplication.cpp index 960da39..caf7536 100644 --- a/OpenGLEngine/MyApplication.cpp +++ b/OpenGLEngine/MyApplication.cpp @@ -1,17 +1,17 @@ #include "MyApplication.h" MyApplication::MyApplication(int width, int height) - : Application(width, height), m_simple_scene(*this), m_object_oriented_scene(*this), m_3d_scene(*this) + : Application(width, height), m_basic_scene(*this), m_simple_2d_scene(*this), m_simple_3d_scene(*this) { } void MyApplication::init() { - m_simple_scene.init(); - m_object_oriented_scene.init(); - m_3d_scene.init(); + m_basic_scene.init(); + m_simple_2d_scene.init(); + m_simple_3d_scene.init(); - m_p_current_scene = &m_simple_scene; + m_p_current_scene = &m_basic_scene; m_p_current_scene->use(); } @@ -19,15 +19,15 @@ void MyApplication::update(float delta_time, clock_t clock) { if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_1)) { - swap_scene(&m_simple_scene); + swap_scene(&m_basic_scene); } else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_2)) { - swap_scene(&m_object_oriented_scene); + swap_scene(&m_simple_2d_scene); } else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_3)) { - swap_scene(&m_3d_scene); + swap_scene(&m_simple_3d_scene); } m_p_current_scene->update(delta_time, clock); } diff --git a/OpenGLEngine/MyApplication.h b/OpenGLEngine/MyApplication.h index 543cec9..6bd3934 100644 --- a/OpenGLEngine/MyApplication.h +++ b/OpenGLEngine/MyApplication.h @@ -1,9 +1,9 @@ #pragma once #include "Application.h" -#include "MySimpleScene.h" -#include "MyObjectOrientedScene.h" -#include "My3DScene.h" +#include "MyBasicScene.h" +#include "MySimple2DScene.h" +#include "MySimple3DScene.h" class MyApplication : public Application @@ -24,8 +24,8 @@ private: void swap_scene(Scene* scene); Scene* m_p_current_scene = nullptr; - MySimpleScene m_simple_scene; - MyObjectOrientedScene m_object_oriented_scene; - My3DScene m_3d_scene; + MyBasicScene m_basic_scene; + MySimple2DScene m_simple_2d_scene; + MySimple3DScene m_simple_3d_scene; }; diff --git a/OpenGLEngine/MyFragmentShader.glsl b/OpenGLEngine/MyBasicFS.glsl similarity index 100% rename from OpenGLEngine/MyFragmentShader.glsl rename to OpenGLEngine/MyBasicFS.glsl diff --git a/OpenGLEngine/MySimpleScene.cpp b/OpenGLEngine/MyBasicScene.cpp similarity index 70% rename from OpenGLEngine/MySimpleScene.cpp rename to OpenGLEngine/MyBasicScene.cpp index d64aefe..b2ba12c 100644 --- a/OpenGLEngine/MySimpleScene.cpp +++ b/OpenGLEngine/MyBasicScene.cpp @@ -1,16 +1,16 @@ -#include "MySimpleScene.h" +#include "MyBasicScene.h" -MySimpleScene::MySimpleScene(Application& application) +MyBasicScene::MyBasicScene(Application& application) : Scene(application) { } -MySimpleScene::~MySimpleScene() +MyBasicScene::~MyBasicScene() { } -void MySimpleScene::init() +void MyBasicScene::init() { float points[] = { 0.0f, 0.5f, 0.0f, @@ -29,21 +29,21 @@ void MySimpleScene::init() glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); } -void MySimpleScene::use() +void MyBasicScene::use() { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); } -void MySimpleScene::unuse() +void MyBasicScene::unuse() { } -void MySimpleScene::update(float delta_time, clock_t clock) +void MyBasicScene::update(float delta_time, clock_t clock) { } -void MySimpleScene::render() +void MyBasicScene::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shader_program.use(); diff --git a/OpenGLEngine/MySimpleScene.h b/OpenGLEngine/MyBasicScene.h similarity index 57% rename from OpenGLEngine/MySimpleScene.h rename to OpenGLEngine/MyBasicScene.h index e613d2d..4a88abb 100644 --- a/OpenGLEngine/MySimpleScene.h +++ b/OpenGLEngine/MyBasicScene.h @@ -2,15 +2,13 @@ #include "Scene.h" -#include "MyBatch.h" -#include "MyShaderProgram.h" +#include "MyBasicShaderProgram.h" -class MySimpleScene : - public Scene +class MyBasicScene : public Scene { public: - MySimpleScene(Application& application); - ~MySimpleScene(); + MyBasicScene(Application& application); + ~MyBasicScene(); void init() override; @@ -23,7 +21,7 @@ public: void render() override; private: - MyShaderProgram m_shader_program; + MyBasicShaderProgram m_shader_program; GLuint m_vbo; GLuint m_vao; diff --git a/OpenGLEngine/MyBasicShaderProgram.cpp b/OpenGLEngine/MyBasicShaderProgram.cpp new file mode 100644 index 0000000..1454dcd --- /dev/null +++ b/OpenGLEngine/MyBasicShaderProgram.cpp @@ -0,0 +1,13 @@ +#include "MyBasicShaderProgram.h" + +#include "Util.h" + +MyBasicShaderProgram::MyBasicShaderProgram() + // TEMP Hardcode in the path. (Should Use Relative Path to General Shader Dir) + : m_vertex_shader(Util::load_file("D:/Development/C++/OpenGLEngine/OpenGLEngine/MyBasicVS.glsl"), VERTEX_SHADER), + m_fragment_shader(Util::load_file("D:/Development/C++/OpenGLEngine/OpenGLEngine/MyBasicFS.glsl"), FRAGMENT_SHADER) +{ + attach_shader(m_vertex_shader); + attach_shader(m_fragment_shader); + link(); +} \ No newline at end of file diff --git a/OpenGLEngine/MyShaderProgram.h b/OpenGLEngine/MyBasicShaderProgram.h similarity index 67% rename from OpenGLEngine/MyShaderProgram.h rename to OpenGLEngine/MyBasicShaderProgram.h index 54b4a7e..5a3096b 100644 --- a/OpenGLEngine/MyShaderProgram.h +++ b/OpenGLEngine/MyBasicShaderProgram.h @@ -5,7 +5,7 @@ #include "Mesh.h" #include "Renderable.h" -class MyShaderProgram : public ShaderProgram +class MyBasicShaderProgram : public ShaderProgram { public: struct Vertex @@ -13,24 +13,23 @@ public: Vertex() {} Vertex(float x, float y, float z) : x(x), y(y), z(z) - { - } + {} float x; float y; float z; }; - struct Color // Try changing to normalized unsigned chars (0-255) for the example + struct Color { - float r; - float g; - float b; - float a; + float r = 0.0f; + float g = 0.0f; + float b = 0.0f; + float a = 1.0f; }; typedef unsigned int Index; typedef Renderable Renderable; typedef Mesh Mesh; - MyShaderProgram(); + MyBasicShaderProgram(); private: Shader m_vertex_shader; diff --git a/OpenGLEngine/MyVertexShader.glsl b/OpenGLEngine/MyBasicVS.glsl similarity index 100% rename from OpenGLEngine/MyVertexShader.glsl rename to OpenGLEngine/MyBasicVS.glsl diff --git a/OpenGLEngine/MyBatch.cpp b/OpenGLEngine/MyBatch.cpp index 240db73..83c335b 100644 --- a/OpenGLEngine/MyBatch.cpp +++ b/OpenGLEngine/MyBatch.cpp @@ -3,7 +3,7 @@ void MyBatch::setup_element_buffers() { glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]); - glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MyBatchTestShaderProgram::Color), NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MySimpleShaderProgram::Color), NULL, GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[POSEABLE_VBO_INDEX]); glBufferData(GL_ARRAY_BUFFER, m_poseable_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); @@ -39,8 +39,8 @@ void MyBatch::update_element_buffers() { // TODO: There are probably better ways to do this. Should check with the old engine to see what I did there. glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]); - glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MyBatchTestShaderProgram::Color), NULL, GL_STREAM_DRAW); - glBufferSubData(GL_ARRAY_BUFFER, 0, m_color_elements.size() * sizeof(MyBatchTestShaderProgram::Color), m_color_elements.data()); + glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MySimpleShaderProgram::Color), NULL, GL_STREAM_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, m_color_elements.size() * sizeof(MySimpleShaderProgram::Color), m_color_elements.data()); glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[POSEABLE_VBO_INDEX]); glBufferData(GL_ARRAY_BUFFER, m_poseable_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW); diff --git a/OpenGLEngine/MyBatch.h b/OpenGLEngine/MyBatch.h index 67a0111..41a4e4d 100644 --- a/OpenGLEngine/MyBatch.h +++ b/OpenGLEngine/MyBatch.h @@ -4,23 +4,23 @@ #include "Poseable.h" -#include "MyBatchTestShaderProgram.h" +#include "MySimpleShaderProgram.h" -class MyBatch : public Batch +class MyBatch : public Batch { public: MyBatch( - const MyBatchTestShaderProgram::Renderable* renderable, + const MySimpleShaderProgram::Renderable* renderable, const SizeType& element_count ) : MyBatch(renderable, element_count, element_count) {} MyBatch( - const MyBatchTestShaderProgram::Renderable* renderable, + const MySimpleShaderProgram::Renderable* renderable, const SizeType& element_count, const SizeType& element_render_count ) : Batch(renderable, element_render_count), m_color_elements(element_count), m_poseable_elements(element_count) {} - MyBatchTestShaderProgram::Color& get_color(const SizeType& index) { return m_color_elements[index]; } + MySimpleShaderProgram::Color& get_color(const SizeType& index) { return m_color_elements[index]; } Poseable& get_pose(const SizeType& index) { return m_poseable_elements[index]; } @@ -35,6 +35,6 @@ private: const int COLOR_VBO_INDEX = 0; const int POSEABLE_VBO_INDEX = 1; - std::vector m_color_elements; + std::vector m_color_elements; std::vector m_poseable_elements; }; \ No newline at end of file diff --git a/OpenGLEngine/MyBatchTestShaderProgram.cpp b/OpenGLEngine/MyBatchTestShaderProgram.cpp deleted file mode 100644 index fc57350..0000000 --- a/OpenGLEngine/MyBatchTestShaderProgram.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "MyBatchTestShaderProgram.h" - -#include "Util.h" - -MyBatchTestShaderProgram::MyBatchTestShaderProgram() - // TEMP Hardcode in the path. (Should Use Relative Path to General Shader Dir) - : m_vertex_shader(Util::load_file("D:\\Development\\C++\\OpenGLEngine\\OpenGLEngine\\MyBatchTestVertexShader.glsl"), VERTEX_SHADER), - m_fragment_shader(Util::load_file("D:\\Development\\C++\\OpenGLEngine\\OpenGLEngine\\MyBatchTestFragmentShader.glsl"), FRAGMENT_SHADER) -{ - attach_shader(m_vertex_shader); - attach_shader(m_fragment_shader); - link(); -} diff --git a/OpenGLEngine/MyBatchTestVertexShader.glsl b/OpenGLEngine/MyBatchTestVertexShader.glsl deleted file mode 100644 index f49b865..0000000 --- a/OpenGLEngine/MyBatchTestVertexShader.glsl +++ /dev/null @@ -1,14 +0,0 @@ -#version 430 -layout(location = 0) in vec3 vertex_position; -layout(location = 1) in vec4 vertex_color; -layout(location = 2) in mat4 m; - -// TODO: Try this with location 0 -layout(location = 6) uniform mat4 pv; - -out vec4 fragment_color; -void main() -{ - fragment_color = vertex_color; - gl_Position = pv * m * vec4(vertex_position, 1.0); -} \ No newline at end of file diff --git a/OpenGLEngine/MyObjectOrientedScene.cpp b/OpenGLEngine/MyObjectOrientedScene.cpp deleted file mode 100644 index bb99211..0000000 --- a/OpenGLEngine/MyObjectOrientedScene.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "MyObjectOrientedScene.h" - -#include -#include - -#include "constants.h" - -#include "Util.h" - -#include "DrawMode.h" -#include "MeshFactory.h" - -#define FIRST_VERT -50.0f, 50.0f, 0.0f -#define SECOND_VERT 50.0f, 150.0f, 0.0f -#define THIRD_VERT -100.0f, -50.0f, 0.0f -#define FOURTH_VERT 100.0f, -50.0f, 0.0f - -MyObjectOrientedScene::MyObjectOrientedScene(Application& application) - : Scene(application), - m_shape(MeshFactory::gen( - DrawMode::DRAW_TRIANGLES, - MyBatchTestShaderProgram::Vertex(FIRST_VERT), - MyBatchTestShaderProgram::Vertex(SECOND_VERT), - MyBatchTestShaderProgram::Vertex(THIRD_VERT), - MyBatchTestShaderProgram::Vertex(FOURTH_VERT) - ), DrawMode::DRAW_TRIANGLES), - m_batch(&m_shape, 2), - m_camera(vec3(m_screen_size, 2.0f))// TODO: change this back to just m_screen_size -{ -} - -MyObjectOrientedScene::~MyObjectOrientedScene() -{ -} - -void MyObjectOrientedScene::init() -{ - m_batch.init(); -} - -void MyObjectOrientedScene::use() -{ - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); -} - -void MyObjectOrientedScene::unuse() -{ - -} - -void MyObjectOrientedScene::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)egm::TAU * c / intervals; - - { - MyBatchTestShaderProgram::Color& color = m_batch.get_color(0); - color.r = brightness; - color.g = brightness; - color.b = brightness; - color.a = 1.0f; - - Poseable& pose = m_batch.get_pose(0); - pose.update_position(vec3(cos(radians) * 50, 2.0f, 0.0f)); - } - - { - MyBatchTestShaderProgram::Color& color = m_batch.get_color(1); - color.r = 1.0f - brightness; - color.g = 1.0f - brightness; - color.b = 1.0f - brightness; - color.a = 1.0f; - - Poseable& pose = m_batch.get_pose(1); - pose.update_position(vec3(-3.0f, -2.0f, 0.0f)); - } - - vec2 camera_translation(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; - - m_camera.translate(camera_translation * delta_time * 100.0f); - - const mat4& projection = m_camera.get_projection_matrix(); - const mat4& camera_orientation = m_camera.get_orientation_matrix(); - const mat4& world_to_view = m_camera.get_world_to_view_matrix(); - const mat4& orientation = m_batch.get_pose(0).get_orientation_matrix(); - - const mat4 mvp = world_to_view * orientation; - - vec4 first_vert(FIRST_VERT, 1.0f); - vec4 second_vert(SECOND_VERT, 1.0f); - vec4 third_vert(THIRD_VERT, 1.0f); - vec4 fourth_vert(FOURTH_VERT, 1.0f); - - Util::set_console_position(0, 0); - std::cout << "Projection" << std::endl; - Util::print_matrix(projection); - std::cout << "World to View" << std::endl; - Util::print_matrix(world_to_view); - std::cout << "Pose 0 Orientation" << std::endl; - Util::print_matrix(orientation); - std::cout << "Full Projection Matrix" << std::endl; - Util::print_matrix(world_to_view * orientation); - std::cout << " First Second Third Fourth " << std::endl; - Util::print_matrix(mat4(mvp * first_vert, mvp * second_vert, mvp * third_vert, mvp * fourth_vert)); - - // TODO: Make a prerender function or move this to render - m_batch.prerender(); -} - -void MyObjectOrientedScene::render() -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_shader_program.use(); - glUniformMatrix4fv(6, 1, GL_FALSE, &m_camera.get_world_to_view_matrix()[0][0]); - m_batch.render(); -} - -#undef FIRST_VERT -#undef SECOND_VERT -#undef THIRD_VERT -#undef FOURTH_VERT \ No newline at end of file diff --git a/OpenGLEngine/MyShaderProgram.cpp b/OpenGLEngine/MyShaderProgram.cpp deleted file mode 100644 index 4743ebe..0000000 --- a/OpenGLEngine/MyShaderProgram.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "MyShaderProgram.h" - -#include "Util.h" - -MyShaderProgram::MyShaderProgram() - // TEMP Hardcode in the path. (Should Use Relative Path to General Shader Dir) - : m_vertex_shader(Util::load_file("D:\\Development\\C++\\OpenGLEngine\\OpenGLEngine\\MyVertexShader.glsl"), VERTEX_SHADER), - m_fragment_shader(Util::load_file("D:\\Development\\C++\\OpenGLEngine\\OpenGLEngine\\MyFragmentShader.glsl"), FRAGMENT_SHADER) -{ - attach_shader(m_vertex_shader); - attach_shader(m_fragment_shader); - link(); -} \ No newline at end of file diff --git a/OpenGLEngine/MySimple2DScene.cpp b/OpenGLEngine/MySimple2DScene.cpp new file mode 100644 index 0000000..6ba7c63 --- /dev/null +++ b/OpenGLEngine/MySimple2DScene.cpp @@ -0,0 +1,102 @@ +#include "MySimple2DScene.h" + +#include "stdafx.h" + +#include +#include + +#include "constants.h" + +#include "DrawMode.h" +#include "MeshFactory.h" + +MySimple2DScene::MySimple2DScene(Application& application) + : Scene(application), + m_shape(MeshFactory::gen( + DrawMode::DRAW_TRIANGLES, + MySimpleShaderProgram::Vertex(-50.0f, 50.0f, 0.0f), + MySimpleShaderProgram::Vertex(50.0f, 150.0f, 0.0f), + MySimpleShaderProgram::Vertex(-100.0f, -50.0f, 0.0f), + MySimpleShaderProgram::Vertex(100.0f, -50.0f, 0.0f) + ), DrawMode::DRAW_TRIANGLES), + m_batch(&m_shape, 2), + m_camera(m_screen_size) +{} + +MySimple2DScene::~MySimple2DScene() +{} + +void MySimple2DScene::init() +{ + m_batch.init(); +} + +void MySimple2DScene::use() +{ + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); +} + +void MySimple2DScene::unuse() +{ + +} + +void MySimple2DScene::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)egm::TAU * c / intervals; + + { + MySimpleShaderProgram::Color& color = m_batch.get_color(0); + color.r = brightness; + color.g = brightness; + color.b = brightness; + color.a = 1.0f; + + Poseable& pose = m_batch.get_pose(0); + pose.update_position(vec3(cos(radians) * 50, 0.0f, 0.0f)); + } + + { + MySimpleShaderProgram::Color& color = m_batch.get_color(1); + color.r = 1.0f - brightness; + color.g = 1.0f - brightness; + color.b = 1.0f - brightness; + color.a = 1.0f; + + Poseable& pose = m_batch.get_pose(1); + pose.update_position(vec3(0.0f, sin(radians) * 50, 0.0f)); + } + + vec2 camera_translation(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; + + m_camera.translate(camera_translation * delta_time * 100.0f); + + // TODO: Make a prerender function or move this to render + m_batch.prerender(); +} + +void MySimple2DScene::render() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + m_shader_program.use(); + glUniformMatrix4fv(0, 1, GL_FALSE, &m_camera.get_world_to_view_matrix()[0][0]); + m_batch.render(); +} diff --git a/OpenGLEngine/MyObjectOrientedScene.h b/OpenGLEngine/MySimple2DScene.h similarity index 53% rename from OpenGLEngine/MyObjectOrientedScene.h rename to OpenGLEngine/MySimple2DScene.h index b3d7359..beffb46 100644 --- a/OpenGLEngine/MyObjectOrientedScene.h +++ b/OpenGLEngine/MySimple2DScene.h @@ -5,13 +5,13 @@ #include "Camera2D.h" #include "MyBatch.h" -#include "MyBatchTestShaderProgram.h" +#include "MySimpleShaderProgram.h" -class MyObjectOrientedScene : public Scene +class MySimple2DScene : public Scene { public: - MyObjectOrientedScene(Application& application); - ~MyObjectOrientedScene(); + MySimple2DScene(Application& application); + ~MySimple2DScene(); void init() override; @@ -22,9 +22,10 @@ public: void update(float delta_time, clock_t clock) override; void render() override; + private: MyBatch m_batch; - MyBatchTestShaderProgram::Renderable m_shape; - MyBatchTestShaderProgram m_shader_program; + MySimpleShaderProgram::Renderable m_shape; + MySimpleShaderProgram m_shader_program; Camera2D m_camera; }; \ No newline at end of file diff --git a/OpenGLEngine/My3DScene.cpp b/OpenGLEngine/MySimple3DScene.cpp similarity index 57% rename from OpenGLEngine/My3DScene.cpp rename to OpenGLEngine/MySimple3DScene.cpp index 22d4bff..792fa8e 100644 --- a/OpenGLEngine/My3DScene.cpp +++ b/OpenGLEngine/MySimple3DScene.cpp @@ -1,4 +1,4 @@ -#include "My3DScene.h" +#include "MySimple3DScene.h" #include "stdafx.h" @@ -9,43 +9,40 @@ #include "DrawMode.h" #include "MeshFactory.h" -#include "Util.h" -#define FIRST_VERT -1.0f, 1.0f, 0.0f - -My3DScene::My3DScene(Application& application) +MySimple3DScene::MySimple3DScene(Application& application) : Scene(application), - m_shape(MeshFactory::gen( + m_shape(MeshFactory::gen( DrawMode::DRAW_TRIANGLES, - MyBatchTestShaderProgram::Vertex(FIRST_VERT), - MyBatchTestShaderProgram::Vertex(1.0f, 1.0f, 0.0f), - MyBatchTestShaderProgram::Vertex(-2.0f, -1.0f, 0.0f), - MyBatchTestShaderProgram::Vertex(2.0f, -1.0f, 0.0f) + MySimpleShaderProgram::Vertex(-1.0f, 1.0f, 0.0f), + MySimpleShaderProgram::Vertex(1.0f, 1.0f, 0.0f), + MySimpleShaderProgram::Vertex(-2.0f, -1.0f, 0.0f), + 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)) {} -My3DScene::~My3DScene() +MySimple3DScene::~MySimple3DScene() {} -void My3DScene::init() +void MySimple3DScene::init() { m_batch.init(); } -void My3DScene::use() +void MySimple3DScene::use() { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); } -void My3DScene::unuse() +void MySimple3DScene::unuse() { } -void My3DScene::update(float delta_time, clock_t clock) +void MySimple3DScene::update(float delta_time, clock_t clock) { float brightness; float radians; @@ -62,7 +59,7 @@ void My3DScene::update(float delta_time, clock_t clock) radians = (float)egm::TAU * c / intervals; { - MyBatchTestShaderProgram::Color& color = m_batch.get_color(0); + MySimpleShaderProgram::Color& color = m_batch.get_color(0); color.r = brightness; color.g = brightness; color.b = brightness; @@ -73,7 +70,7 @@ void My3DScene::update(float delta_time, clock_t clock) } { - MyBatchTestShaderProgram::Color& color = m_batch.get_color(1); + MySimpleShaderProgram::Color& color = m_batch.get_color(1); color.r = 1.0f - brightness; color.g = 1.0f - brightness; color.b = 1.0f - brightness; @@ -94,30 +91,14 @@ void My3DScene::update(float delta_time, clock_t clock) m_camera.translate(camera_translation * delta_time); - const mat4& world_to_view = m_camera.get_world_to_view_matrix(); - const mat4& orientation = m_batch.get_pose(0).get_orientation_matrix(); - const vec4 first_vert(FIRST_VERT, 1.0f); - - Util::set_console_position(0, 0); - std::cout << "World to View" << std::endl; - Util::print_matrix(m_camera.get_world_to_view_matrix()); - std::cout << "Pose 0 Orientation" << std::endl; - Util::print_matrix(m_batch.get_pose(0).get_orientation_matrix()); - std::cout << "First Vert" << std::endl; - Util::print_vec(first_vert); - std::cout << "Projected Position" << std::endl; - Util::print_vec(world_to_view * orientation * first_vert); - // TODO: Make a prerender function or move this to render m_batch.prerender(); } -void My3DScene::render() +void MySimple3DScene::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_shader_program.use(); - glUniformMatrix4fv(6, 1, GL_FALSE, &m_camera.get_world_to_view_matrix()[0][0]); + glUniformMatrix4fv(0, 1, GL_FALSE, &m_camera.get_world_to_view_matrix()[0][0]); m_batch.render(); } - -#undef FIRST_VERT \ No newline at end of file diff --git a/OpenGLEngine/My3DScene.h b/OpenGLEngine/MySimple3DScene.h similarity index 57% rename from OpenGLEngine/My3DScene.h rename to OpenGLEngine/MySimple3DScene.h index 249b8f3..b8c0797 100644 --- a/OpenGLEngine/My3DScene.h +++ b/OpenGLEngine/MySimple3DScene.h @@ -5,14 +5,13 @@ #include "Camera3D.h" #include "MyBatch.h" -#include "MyShaderProgram.h" +#include "MySimpleShaderProgram.h" -class My3DScene : - public Scene +class MySimple3DScene : public Scene { public: - My3DScene(Application& application); - ~My3DScene(); + MySimple3DScene(Application& application); + ~MySimple3DScene(); void init() override; @@ -26,8 +25,8 @@ public: private: MyBatch m_batch; - MyBatchTestShaderProgram::Renderable m_shape; - MyBatchTestShaderProgram m_shader_program; + MySimpleShaderProgram::Renderable m_shape; + MySimpleShaderProgram m_shader_program; Camera3D m_camera; }; diff --git a/OpenGLEngine/MyBatchTestFragmentShader.glsl b/OpenGLEngine/MySimpleFS.glsl similarity index 100% rename from OpenGLEngine/MyBatchTestFragmentShader.glsl rename to OpenGLEngine/MySimpleFS.glsl diff --git a/OpenGLEngine/MySimpleShaderProgram.cpp b/OpenGLEngine/MySimpleShaderProgram.cpp new file mode 100644 index 0000000..db7f976 --- /dev/null +++ b/OpenGLEngine/MySimpleShaderProgram.cpp @@ -0,0 +1,13 @@ +#include "MySimpleShaderProgram.h" + +#include "Util.h" + +MySimpleShaderProgram::MySimpleShaderProgram() + // TEMP Hardcode in the path. (Should Use Relative Path to General Shader Dir) + : m_vertex_shader(Util::load_file("D:/Development/C++/OpenGLEngine/OpenGLEngine/MySimpleVS.glsl"), VERTEX_SHADER), + m_fragment_shader(Util::load_file("D:/Development/C++/OpenGLEngine/OpenGLEngine/MySimpleFS.glsl"), FRAGMENT_SHADER) +{ + attach_shader(m_vertex_shader); + attach_shader(m_fragment_shader); + link(); +} diff --git a/OpenGLEngine/MyBatchTestShaderProgram.h b/OpenGLEngine/MySimpleShaderProgram.h similarity index 67% rename from OpenGLEngine/MyBatchTestShaderProgram.h rename to OpenGLEngine/MySimpleShaderProgram.h index d9b6bd3..3481be5 100644 --- a/OpenGLEngine/MyBatchTestShaderProgram.h +++ b/OpenGLEngine/MySimpleShaderProgram.h @@ -5,7 +5,7 @@ #include "Mesh.h" #include "Renderable.h" -class MyBatchTestShaderProgram : public ShaderProgram +class MySimpleShaderProgram : public ShaderProgram { public: struct Vertex @@ -18,24 +18,18 @@ public: float y; float z; }; - struct Color // Try changing to normalized unsigned chars (0-255) for the example + struct Color { float r = 0.0f; float g = 0.0f; float b = 0.0f; float a = 1.0f; }; - struct Offset - { - float x = 0.0f; - float y = 0.0f; - float z = 0.0f; - }; typedef unsigned int Index; typedef Renderable Renderable; typedef Mesh Mesh; - MyBatchTestShaderProgram(); + MySimpleShaderProgram(); private: Shader m_vertex_shader; diff --git a/OpenGLEngine/MySimpleVS.glsl b/OpenGLEngine/MySimpleVS.glsl new file mode 100644 index 0000000..a67426e --- /dev/null +++ b/OpenGLEngine/MySimpleVS.glsl @@ -0,0 +1,13 @@ +#version 430 +layout(location = 0) in vec3 vertex_position; +layout(location = 1) in vec4 vertex_color; +layout(location = 2) in mat4 model_to_world; + +layout(location = 0) uniform mat4 world_to_projection; + +out vec4 fragment_color; +void main() +{ + fragment_color = vertex_color; + gl_Position = world_to_projection * model_to_world * vec4(vertex_position, 1.0); +} \ No newline at end of file diff --git a/OpenGLEngine/OpenGLEngine.vcxproj b/OpenGLEngine/OpenGLEngine.vcxproj index d952189..d07bbd5 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj +++ b/OpenGLEngine/OpenGLEngine.vcxproj @@ -156,13 +156,13 @@ - + - - - - + + + + @@ -186,13 +186,13 @@ - + - - - - + + + + @@ -202,10 +202,10 @@ - - - - + + + + diff --git a/OpenGLEngine/OpenGLEngine.vcxproj.filters b/OpenGLEngine/OpenGLEngine.vcxproj.filters index d51b4c8..094b08c 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj.filters +++ b/OpenGLEngine/OpenGLEngine.vcxproj.filters @@ -84,12 +84,6 @@ Source Files\Example\Rendering - - Source Files\Example\Rendering - - - Source Files\Example\Rendering - Source Files\Example\Application @@ -102,15 +96,21 @@ Source Files\Engine - + Source Files\Example\Application - + Source Files\Example\Application - + Source Files\Example\Application + + Source Files\Example\Rendering + + + Source Files\Example\Rendering + @@ -164,12 +164,6 @@ Header Files\Example\Rendering - - Header Files\Example\Rendering - - - Header Files\Example\Rendering - Header Files\Example\Application @@ -182,30 +176,36 @@ Header Files\Engine - - Header Files\Example\Application - - - Header Files\Example\Application - - - Header Files\Example\Application - Header Files\Engine + + Header Files\Example\Application + + + Header Files\Example\Application + + + Header Files\Example\Application + + + Header Files\Example\Rendering + + + Header Files\Example\Rendering + - + Source Files\Example\Rendering\Shader Code - + Source Files\Example\Rendering\Shader Code - + Source Files\Example\Rendering\Shader Code - + Source Files\Example\Rendering\Shader Code