From 340b21f099ef211c63ab5fc3d0ae1d7bf393f8fa Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Mon, 6 Dec 2021 22:44:47 -0500 Subject: [PATCH] Create a simple camera --- .../resources/shaders/vertex_core.glsl | 15 ++- examples/dev_testing/src/main.cpp | 93 ++++++++++++++++--- include/simpleengine/camera.h | 41 ++++++++ include/simpleengine/game.h | 3 + include/simpleengine/gfx/shader.h | 16 ++++ include/simpleengine/shader_program.h | 6 +- src/camera.cpp | 50 ++++++++++ src/game.cpp | 10 ++ src/gfx/shader.cpp | 58 +++++++----- src/shapes/2d/square.cpp | 4 +- src/shapes/2d/triangle.cpp | 2 +- 11 files changed, 253 insertions(+), 45 deletions(-) create mode 100644 include/simpleengine/camera.h create mode 100644 src/camera.cpp diff --git a/examples/dev_testing/resources/shaders/vertex_core.glsl b/examples/dev_testing/resources/shaders/vertex_core.glsl index 8babb47..222c2cc 100644 --- a/examples/dev_testing/resources/shaders/vertex_core.glsl +++ b/examples/dev_testing/resources/shaders/vertex_core.glsl @@ -9,13 +9,22 @@ out vec3 vs_color; out vec2 vs_texcoord; out mat4 vs_transform; -uniform mat4 transform; +uniform mat4 transform_matrix; +uniform mat4 view_matrix; +uniform mat4 projection_matrix; void main() { vs_position = vertex_position; - vs_transform = transform; + vs_transform = transform_matrix; vs_color = vertex_color; vs_texcoord = vertex_texcoord; - gl_Position = transform * vec4(vertex_position, 1.0f); + gl_Position = projection_matrix * view_matrix * transform_matrix * vec4(vertex_position, 1.0f); + + /* vs_position = vec4(transform_matrix * vec4(vertex_position, 1.f)).xyz; + vs_transform = transform_matrix; + vs_color = vertex_color; + vs_texcoord = vertex_texcoord; + + gl_Position = projection_matrix * view_matrix * transform_matrix * vec4(vertex_position, 1.0f); */ } \ No newline at end of file diff --git a/examples/dev_testing/src/main.cpp b/examples/dev_testing/src/main.cpp index 83f6881..8bab303 100644 --- a/examples/dev_testing/src/main.cpp +++ b/examples/dev_testing/src/main.cpp @@ -1,6 +1,8 @@ +#include "simpleengine/camera.h" #include "simpleengine/gfx/texture.h" #include "simpleengine/shapes/2d/square.h" #include "simpleengine/vector.h" +#include #include #include #include @@ -19,6 +21,37 @@ CMRC_DECLARE(resource_shaders); #include +/* class Triangle3D : public simpleengine::shapes_2d::Triangle { +public: + glm::mat4 projection_matrix; + //glm::mat4 view_matrix; + + const float fov = 70; + const float near_plane = 0.1f; + const float far_plane = 1000.f; + + Triangle3D(simpleengine::gfx::Shader shader, std::vector vertices) : + simpleengine::shapes_2d::Triangle(shader, vertices) { + + projection_matrix = glm::perspective(glm::radians(fov), 640.f / 480.f, near_plane, far_plane); + + shader.use(); + shader.set_uniform_matrix_4f("projection_matrix", projection_matrix, false); + //shader.set_uniform_matrix_4f("view_matrix", view_matrix, false); + shader.unuse(); + } + + Triangle3D(std::shared_ptr shader_program, std::vector vertices) : + simpleengine::shapes_2d::Triangle(shader_program, vertices) { + + + } + + virtual void render(GLFWwindow* target) override { + + } +}; */ + std::string read_resource_shader(const std::string& path) { auto fs = cmrc::resource_shaders::get_filesystem(); cmrc::file vertex_file = fs.open(path); @@ -40,13 +73,13 @@ int main(int argc, char *argv[]) { shader_prog.link(); std::shared_ptr base_shader_program = shader_prog.program; - simpleengine::gfx::Texture wall_texture("resources/wall.jpg"); - simpleengine::gfx::Texture crate_texture("resources/container.jpg", true, true); + /* simpleengine::gfx::Texture wall_texture("resources/wall.jpg"); + simpleengine::gfx::Texture crate_texture("resources/container.jpg", true, true); */ std::vector vertices = { - { simpleengine::Vectorf(-0.5f, -0.5f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // bottom left - { simpleengine::Vectorf(0.5f, -0.5f, 0.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right - { simpleengine::Vectorf(0.f, 0.5f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // top + { simpleengine::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // bottom left + { simpleengine::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right + { simpleengine::Vectorf(0.f, 0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // top }; auto tri = std::make_shared(base_shader_program, vertices); @@ -54,20 +87,58 @@ int main(int argc, char *argv[]) { game.add_event(tri); /* std::vector vertices = { - { glm::vec3(0.5f, 0.5f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, - { glm::vec3(0.5f, -0.5f, 0.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, - { glm::vec3(-0.5f, -0.5f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, - { glm::vec3(-0.5f, 0.5f, 0.f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, + { simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, + { simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, + { simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, + { simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, + + { simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, + { simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, + { simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, + { simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, + + { simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, + { simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, + { simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, + { simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, + + { simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, + { simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, + { simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, + { simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, + + { simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, + { simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, + { simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, + { simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, + + { simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) }, + { simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, + { simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) }, + { simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) }, }; std::vector indicies = { - 0, 1, 3, - 1, 2, 3 + 0,1,3, + 3,1,2, + 4,5,7, + 7,5,6, + 8,9,11, + 11,9,10, + 12,13,15, + 15,13,14, + 16,17,19, + 19,17,18, + 20,21,23, + 23,21,22 }; auto square = std::make_shared(base_shader_program, vertices, indicies); //square->set_texture(crate_texture); game.add_event(square); */ + auto camera = std::make_shared(game.get_window(), base_shader_program); + game.add_event(camera); + return game.run(); } \ No newline at end of file diff --git a/include/simpleengine/camera.h b/include/simpleengine/camera.h new file mode 100644 index 0000000..4118fd7 --- /dev/null +++ b/include/simpleengine/camera.h @@ -0,0 +1,41 @@ +#pragma once + +#include "simpleengine/gfx/shader.h" +#include "event/event.h" + +#include + +#include +#include +#include + +namespace simpleengine { + class Camera : public simpleengine::Event { + private: + + public: + glm::vec3 position; + glm::vec3 rotation; + gfx::Shader shader; + + glm::mat4 projection_matrix; + glm::mat4 view_matrix; + glm::vec3 world_up = glm::vec3(0.f, 1.f, 0.f); + glm::vec3 cam_front = glm::vec3(0.f, 0.f, -1.f); + + float fov; + float near_plane ; + float far_plane; + + Camera(GLFWwindow* window, gfx::Shader shader, float fov = 70, glm::vec3 position = glm::vec3(0.f), glm::vec3 rotation = glm::vec3(0.f), + float near_plane = 0.1f, float far_plane = 1000.f, glm::vec3 world_up = glm::vec3(0.f, 1.f, 0.f), + glm::vec3 cam_front = glm::vec3(0.f, 0.f, -1.f)); + + Camera(GLFWwindow* window, std::shared_ptr shader_prog, float fov = 70, glm::vec3 position = glm::vec3(0.f), + glm::vec3 rotation = glm::vec3(0.f), float near_plane = 0.1f, float far_plane = 1000.f, glm::vec3 world_up = glm::vec3(0.f, 1.f, 0.f), + glm::vec3 cam_front = glm::vec3(0.f, 0.f, -1.f)); + + virtual void update(const float& delta_time) override; + virtual void render(GLFWwindow* target) override; + }; +} \ No newline at end of file diff --git a/include/simpleengine/game.h b/include/simpleengine/game.h index b09b105..90dfa12 100644 --- a/include/simpleengine/game.h +++ b/include/simpleengine/game.h @@ -30,6 +30,9 @@ namespace simpleengine { const int& minor_version = 4, const bool& resizeable = false, const int& forward_compat = GL_TRUE); virtual ~Game(); + void enable_default_gl_options() const; + void enable_gl_option(GLenum option) const; + void add_event(std::shared_ptr event); void update(); diff --git a/include/simpleengine/gfx/shader.h b/include/simpleengine/gfx/shader.h index 135c6b1..e542dee 100644 --- a/include/simpleengine/gfx/shader.h +++ b/include/simpleengine/gfx/shader.h @@ -105,6 +105,22 @@ namespace simpleengine::gfx { */ void attach(std::shared_ptr program); + /** + * @brief Get the location of the uniform variable in the shader. + * + * @param uniform_name The name of the uniform variable. + * @return int The location of the uniform in the shader. + */ + int get_uniform_location(const std::string& uniform_name) const; + + /** + * @brief Get the location of the uniform variable in the shader. + * + * @param uniform_name The name of the uniform variable. + * @return int The location of the uniform in the shader. + */ + int get_uniform_location(const char* uniform_name) const; + /** * @brief Get a Uniform Float from the shader using a `location`. * diff --git a/include/simpleengine/shader_program.h b/include/simpleengine/shader_program.h index 8253cd9..8739786 100644 --- a/include/simpleengine/shader_program.h +++ b/include/simpleengine/shader_program.h @@ -26,6 +26,9 @@ namespace simpleengine { private: using super = simpleengine::Event; public: + std::shared_ptr program; + std::vector shaders; + ShaderProgram() : program(std::make_shared(glCreateProgram())) { } @@ -112,8 +115,5 @@ namespace simpleengine { virtual void render(GLFWwindow* target) { glUseProgram(*program); } - - std::shared_ptr program; - std::vector shaders; }; } \ No newline at end of file diff --git a/src/camera.cpp b/src/camera.cpp new file mode 100644 index 0000000..454e13d --- /dev/null +++ b/src/camera.cpp @@ -0,0 +1,50 @@ +#include "camera.h" + +namespace simpleengine { + Camera::Camera(GLFWwindow* window, gfx::Shader shader, float fov, glm::vec3 position, glm::vec3 rotation, + float near_plane, float far_plane, glm::vec3 world_up, glm::vec3 cam_front) : simpleengine::Event(window), shader(shader), + projection_matrix(1.f), view_matrix(1.f), fov(fov), position(position), rotation(rotation), near_plane(near_plane), far_plane(far_plane), + world_up(world_up), cam_front(cam_front) { + + // TODO: Update width and height on window resize. + int width, height; + glfwGetFramebufferSize(window, &width, &height); + + projection_matrix = glm::perspective(glm::radians(fov), ((float) width) / height, near_plane, far_plane); + } + + Camera::Camera(GLFWwindow* window, std::shared_ptr shader_prog, float fov, glm::vec3 position, glm::vec3 rotation, + float near_plane, float far_plane, glm::vec3 world_up, glm::vec3 cam_front) : Camera(window, gfx::Shader(shader_prog), fov, position, + rotation, near_plane, far_plane, world_up, cam_front) { + + } + + void Camera::update(const float& delta_time) { + /* if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { + position.z -= 0.02f; + } + + if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { + position.z += 0.02f; + } + + if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { + position.x += 0.02f; + } + + if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { + position.x -= 0.02f; + } */ + + view_matrix = glm::lookAt(position, position + cam_front, world_up); + + shader.use(); + shader.set_uniform_matrix_4f("view_matrix", view_matrix, false); + shader.set_uniform_matrix_4f("projection_matrix", projection_matrix, false); + shader.unuse(); + } + + void Camera::render(GLFWwindow* target) { + + } +} \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp index 7eae309..3088e23 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -38,6 +38,16 @@ simpleengine::Game::Game(int w, int h, const std::string& window_name, const int std::cout << "Failed to initialize glew!" << std::endl; glfwTerminate(); } + + enable_default_gl_options(); +} + +void simpleengine::Game::enable_default_gl_options() const { + glEnable(GL_DEPTH_TEST); +} + +void simpleengine::Game::enable_gl_option(GLenum option) const { + glEnable(option); } void simpleengine::Game::initialize(const int& gl_profile, const int& major_version, const int& minor_version, diff --git a/src/gfx/shader.cpp b/src/gfx/shader.cpp index 0f99024..701cfc0 100644 --- a/src/gfx/shader.cpp +++ b/src/gfx/shader.cpp @@ -110,6 +110,14 @@ namespace simpleengine::gfx { glAttachShader(*program, shader); } + int Shader::get_uniform_location(const std::string& uniform_name) const { + return this->get_uniform_location(uniform_name.c_str()); + } + + int Shader::get_uniform_location(const char* uniform_name) const { + return glGetUniformLocation(*program, uniform_name); + } + GLfloat Shader::get_uniform_float(GLint location) const { use(); @@ -120,7 +128,7 @@ namespace simpleengine::gfx { } GLfloat Shader::get_uniform_float(const char* uniform_name) const { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); return get_uniform_float(location); } @@ -134,7 +142,7 @@ namespace simpleengine::gfx { } GLint Shader::get_uniform_int(const char* uniform_name) const { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); return get_uniform_int(location); } @@ -148,7 +156,7 @@ namespace simpleengine::gfx { } GLuint Shader::get_uniform_uint(const char* uniform_name) const { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); return get_uniform_uint(location); } @@ -162,7 +170,7 @@ namespace simpleengine::gfx { } GLdouble Shader::get_uniform_double(const char* uniform_name) const { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); return get_uniform_double(location); } @@ -177,7 +185,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_float(const char* uniform_name, GLfloat fl, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_float(location, fl, bind_shader); } @@ -192,7 +200,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_float_vec2(const char* uniform_name, glm::vec2 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_float_vec2(location, vec, bind_shader); } @@ -207,7 +215,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_float_vec3(const char* uniform_name, glm::vec3 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_float_vec3(location, vec, bind_shader); } @@ -222,7 +230,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_float_vec4(const char* uniform_name, glm::vec4 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_float_vec4(location, vec, bind_shader); } @@ -237,7 +245,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_int(const char* uniform_name, GLint i, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_int(location, i, bind_shader); } @@ -252,7 +260,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_int_vec2(const char* uniform_name, glm::ivec2 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_int_vec2(location, vec, bind_shader); } @@ -267,7 +275,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_int_vec3(const char* uniform_name, glm::ivec3 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_int_vec3(location, vec, bind_shader); } @@ -282,7 +290,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_int_vec4(const char* uniform_name, glm::ivec4 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_int_vec4(location, vec, bind_shader); } @@ -297,7 +305,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_uint(const char* uniform_name, GLuint ui, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_uint(location, ui, bind_shader); } @@ -312,7 +320,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_uint_vec2(const char* uniform_name, glm::uvec2 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_uint_vec2(location, vec, bind_shader); } @@ -327,7 +335,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_uint_vec3(const char* uniform_name, glm::uvec3 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_uint_vec3(location, vec, bind_shader); } @@ -342,7 +350,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_uint_vec4(const char* uniform_name, glm::uvec4 vec, bool bind_shader) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_uint_vec4(location, vec, bind_shader); } @@ -357,7 +365,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_2f(const char* uniform_name, glm::mat2 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_2f(location, mat, bind_shader, transpose); } @@ -372,7 +380,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_3f(const char* uniform_name, glm::mat3 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_3f(location, mat, bind_shader, transpose); } @@ -387,7 +395,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_4f(const char* uniform_name, glm::mat4 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_4f(location, mat, bind_shader, transpose); } @@ -402,7 +410,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_2x3f(const char* uniform_name, glm::mat2x3 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_2x3f(location, mat, bind_shader, transpose); } @@ -417,7 +425,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_3x2f(const char* uniform_name, glm::mat3x2 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_3x2f(location, mat, bind_shader, transpose); } @@ -432,7 +440,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_2x4f(const char* uniform_name, glm::mat2x4 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_2x4f(location, mat, bind_shader, transpose); } @@ -447,7 +455,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_4x2f(const char* uniform_name, glm::mat4x2 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_4x2f(location, mat, bind_shader, transpose); } @@ -462,7 +470,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_3x4f(const char* uniform_name, glm::mat3x4 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_3x4f(location, mat, bind_shader, transpose); } @@ -477,7 +485,7 @@ namespace simpleengine::gfx { } void Shader::set_uniform_matrix_4x3f(const char* uniform_name, glm::mat4x3 mat, bool bind_shader, bool transpose) { - int location = glGetUniformLocation(*program, uniform_name); + int location = get_uniform_location(uniform_name); set_uniform_matrix_4x3f(location, mat, bind_shader, transpose); } } \ No newline at end of file diff --git a/src/shapes/2d/square.cpp b/src/shapes/2d/square.cpp index 71345e6..e12b887 100644 --- a/src/shapes/2d/square.cpp +++ b/src/shapes/2d/square.cpp @@ -33,13 +33,13 @@ namespace simpleengine::shapes_2d { } void Square::update(const float& delta_time) { - + this->rotate_y(1.f); } void Square::render(GLFWwindow* target) { shader.use(); - shader.set_uniform_matrix_4f("transform", transform_matrix, false); + shader.set_uniform_matrix_4f("transform_matrix", transform_matrix, false); // When binding to the texture, also tell the shader if the texture is set or not. if (texture.has_value()) { diff --git a/src/shapes/2d/triangle.cpp b/src/shapes/2d/triangle.cpp index 76593e9..29da70b 100644 --- a/src/shapes/2d/triangle.cpp +++ b/src/shapes/2d/triangle.cpp @@ -40,7 +40,7 @@ namespace simpleengine::shapes_2d { void Triangle::render(GLFWwindow* target) { shader.use(); - shader.set_uniform_matrix_4f("transform", transform_matrix, false); + shader.set_uniform_matrix_4f("transform_matrix", transform_matrix, false); // When binding to the texture, also tell the shader if the texture is set or not. if (texture.has_value()) {