diff --git a/src/camera.cpp b/src/camera.cpp index 032df4d..b229248 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -13,7 +13,7 @@ Camera::Camera() void Camera::prepare() { // Set projection matrix - State::projection_matrix_ = projection_; + state::projection_matrix = projection_; // Calculate view matrix // For a camera, we need the inverse transformation: @@ -29,7 +29,7 @@ void Camera::prepare() // Inverse translation (translate in opposite direction) view = glm::translate(view, -position_); - State::view_matrix_ = view; + state::view_matrix = view; // Set viewport glViewport(viewport_.x, viewport_.y, viewport_.z, viewport_.w); diff --git a/src/engine.cpp b/src/engine.cpp index 93593b0..3a2a9d0 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -75,11 +75,11 @@ void Engine::initialize() } // Initialize default shader - State::default_shader_ = + state::default_shader = std::make_shared("data/vertex.glsl", "data/fragment.glsl"); - if (std::strlen(State::default_shader_->error()) > 0) { + if (std::strlen(state::default_shader->error()) > 0) { std::cerr << "Failed to initialize shaders: " - << State::default_shader_->error() << "\n"; + << state::default_shader->error() << "\n"; } } diff --git a/src/engine.h b/src/engine.h index 59f07a7..80de442 100644 --- a/src/engine.h +++ b/src/engine.h @@ -4,6 +4,7 @@ #include #include +#include "../lib/glew/GL/glew.h" #include "../lib/glfw/glfw3.h" class World; diff --git a/src/mesh.cpp b/src/mesh.cpp index b5f6be5..24aa05e 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -13,15 +13,15 @@ void Mesh::add_buffer(const std::shared_ptr& buffer, void Mesh::draw() { // Calculate MVP matrix - glm::mat4 mvp = State::projection_matrix_ * State::view_matrix_ - * State::model_matrix_; + glm::mat4 mvp = state::projection_matrix * state::view_matrix + * state::model_matrix; // Draw each buffer with its shader for (size_t i = 0; i < buffers_.size(); ++i) { // Use buffer's shader if available, otherwise use default // shader std::shared_ptr shader = - shaders_[i] ? shaders_[i] : State::default_shader_; + shaders_[i] ? shaders_[i] : state::default_shader; if (shader) { shader->use(); diff --git a/src/model.cpp b/src/model.cpp index e5c631d..73afc0e 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -27,8 +27,8 @@ void Model::draw() // Scale model = glm::scale(model, scale_); - // Set the model matrix in State - State::model_matrix_ = model; + // Set the model matrix in state + state::model_matrix = model; // Draw the mesh mesh_->draw(); diff --git a/src/state.cpp b/src/state.cpp deleted file mode 100644 index 744f11a..0000000 --- a/src/state.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "state.h" - -std::shared_ptr State::default_shader_ = nullptr; -glm::mat4 State::projection_matrix_ = glm::mat4(1.0f); -glm::mat4 State::view_matrix_ = glm::mat4(1.0f); -glm::mat4 State::model_matrix_ = glm::mat4(1.0f); diff --git a/src/state.h b/src/state.h index bd24ae7..c611ba6 100644 --- a/src/state.h +++ b/src/state.h @@ -6,12 +6,13 @@ class Shader; -class State { -public: - static std::shared_ptr default_shader_; - static glm::mat4 projection_matrix_; - static glm::mat4 view_matrix_; - static glm::mat4 model_matrix_; -}; +namespace state { + +inline std::shared_ptr default_shader = nullptr; +inline glm::mat4 projection_matrix = glm::mat4(1.0f); +inline glm::mat4 view_matrix = glm::mat4(1.0f); +inline glm::mat4 model_matrix = glm::mat4(1.0f); + +} // namespace state #endif // STATE_H_ diff --git a/ugine3d.vcxproj b/ugine3d.vcxproj index 6021d72..702a68d 100644 --- a/ugine3d.vcxproj +++ b/ugine3d.vcxproj @@ -180,7 +180,6 @@ - diff --git a/ugine3d.vcxproj.filters b/ugine3d.vcxproj.filters index 290bd8b..39837d9 100644 --- a/ugine3d.vcxproj.filters +++ b/ugine3d.vcxproj.filters @@ -80,9 +80,6 @@ Source Files - - Source Files - Source Files