Create a simple camera
This commit is contained in:
parent
211d8957a3
commit
340b21f099
|
@ -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); */
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#include "simpleengine/camera.h"
|
||||
#include "simpleengine/gfx/texture.h"
|
||||
#include "simpleengine/shapes/2d/square.h"
|
||||
#include "simpleengine/vector.h"
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <simpleengine/gfx/shader.h>
|
||||
#include <simpleengine/renderable.h>
|
||||
#include <simpleengine/event/event.h>
|
||||
|
@ -19,6 +21,37 @@ CMRC_DECLARE(resource_shaders);
|
|||
|
||||
#include <SOIL2/SOIL2.h>
|
||||
|
||||
/* 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<simpleengine::Vertex> 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<GLuint> shader_program, std::vector<simpleengine::Vertex> 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<GLuint> 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<simpleengine::Vertex> 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<simpleengine::shapes_2d::Triangle>(base_shader_program, vertices);
|
||||
|
@ -54,20 +87,58 @@ int main(int argc, char *argv[]) {
|
|||
game.add_event(tri);
|
||||
|
||||
/* std::vector<simpleengine::Vertex> 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<GLuint> 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<simpleengine::shapes_2d::Square>(base_shader_program, vertices, indicies);
|
||||
//square->set_texture(crate_texture);
|
||||
game.add_event(square); */
|
||||
|
||||
auto camera = std::make_shared<simpleengine::Camera>(game.get_window(), base_shader_program);
|
||||
game.add_event(camera);
|
||||
|
||||
return game.run();
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
#include "simpleengine/gfx/shader.h"
|
||||
#include "event/event.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
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<GLuint> 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;
|
||||
};
|
||||
}
|
|
@ -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<simpleengine::Event> event);
|
||||
|
||||
void update();
|
||||
|
|
|
@ -105,6 +105,22 @@ namespace simpleengine::gfx {
|
|||
*/
|
||||
void attach(std::shared_ptr<GLuint> 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`.
|
||||
*
|
||||
|
|
|
@ -26,6 +26,9 @@ namespace simpleengine {
|
|||
private:
|
||||
using super = simpleengine::Event;
|
||||
public:
|
||||
std::shared_ptr<GLuint> program;
|
||||
std::vector<gfx::Shader> shaders;
|
||||
|
||||
ShaderProgram() : program(std::make_shared<GLuint>(glCreateProgram())) {
|
||||
|
||||
}
|
||||
|
@ -112,8 +115,5 @@ namespace simpleengine {
|
|||
virtual void render(GLFWwindow* target) {
|
||||
glUseProgram(*program);
|
||||
}
|
||||
|
||||
std::shared_ptr<GLuint> program;
|
||||
std::vector<gfx::Shader> shaders;
|
||||
};
|
||||
}
|
|
@ -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<GLuint> 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) {
|
||||
|
||||
}
|
||||
}
|
10
src/game.cpp
10
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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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()) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue