diff --git a/CMakeLists.txt b/CMakeLists.txt index 5012c18..a5c2fe7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ file(GLOB_RECURSE source_files "vendor/src/*.c" ) +message(STATUS ${source_files}) + add_library(openglu SHARED ${include_files} ${source_files} diff --git a/examples/movement/CMakeLists.txt b/examples/movement/CMakeLists.txt index e5ec362..6cfb7fc 100644 --- a/examples/movement/CMakeLists.txt +++ b/examples/movement/CMakeLists.txt @@ -32,8 +32,8 @@ add_custom_command(TARGET movement POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $/assets ) -# if(WIN32) -# add_custom_command(TARGET movement POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy $ $ $ -# ) -# endif() \ No newline at end of file +if(WIN32) + add_custom_command(TARGET movement POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif() \ No newline at end of file diff --git a/examples/movement/main.cpp b/examples/movement/main.cpp index e8155fb..f903d77 100644 --- a/examples/movement/main.cpp +++ b/examples/movement/main.cpp @@ -201,6 +201,9 @@ int main(int argc, char** argv) oglu::Texture crate = oglu::MakeTexture("assets/crate.jpg"); oglu::Texture opengl = oglu::MakeTexture("assets/opengl.png"); + oglu::AmbientLight ambient; + ambient.intensity = 0.1f; + camera.Move(0.0f, 0.0f, 5.0f); // Window loop @@ -209,7 +212,7 @@ int main(int argc, char** argv) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); - oglu::Color bgColor(0.29f, 0.13f, 0.23f); + oglu::Color bgColor = oglu::Color::Black; while (!glfwWindowShouldClose(window)) { processInput(window); @@ -222,6 +225,8 @@ int main(int argc, char** argv) shader->Use(); shader->SetUniformTexture("texture1", crate, 0); shader->SetUniformTexture("texture2", opengl, 1); + shader->SetUniform("ambientStrength", ambient.intensity); + shader->SetUniform("ambientColor", ambient.color, true); shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(camera.GetMatrix())); shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(camera.GetProjection())); diff --git a/examples/movement/shaders/fragmentShader.frag b/examples/movement/shaders/fragmentShader.frag index c91f38c..ee12187 100644 --- a/examples/movement/shaders/fragmentShader.frag +++ b/examples/movement/shaders/fragmentShader.frag @@ -6,7 +6,12 @@ out vec4 FragColor; uniform sampler2D texture1; uniform sampler2D texture2; +uniform float ambientStrength; +uniform vec3 ambientColor; + void main() { - FragColor = mix(texture(texture1, oUV), texture(texture2, oUV), 0.2); + vec3 ambient = ambientColor * ambientStrength; + + FragColor = mix(texture(texture1, oUV), texture(texture2, oUV), 0.2) * vec4(ambient, 1.0); } \ No newline at end of file diff --git a/include/color.hpp b/include/color.hpp index 469b206..a5fed3a 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -33,7 +33,7 @@ namespace oglu * @param green Green component * @param alpha Red component */ - Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha = 255); + Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha = 0.f); public: GLfloat r; ///< Red channel diff --git a/include/lighting/ambient.hpp b/include/lighting/ambient.hpp new file mode 100644 index 0000000..a4c9cd3 --- /dev/null +++ b/include/lighting/ambient.hpp @@ -0,0 +1,22 @@ +#ifndef AMBIENT_HPP +#define AMBIENT_HPP + +#include +#include + +namespace oglu +{ + class OGLU_API AmbientLight + { + public: + AmbientLight(); + AmbientLight(GLfloat r, GLfloat g, GLfloat b, GLfloat intensity); + AmbientLight(const Color& color, GLfloat intensity); + AmbientLight(const AmbientLight& other); + + GLfloat intensity; + Color color; + }; +} + +#endif \ No newline at end of file diff --git a/include/openglu.hpp b/include/openglu.hpp index 46c93bd..af5add8 100644 --- a/include/openglu.hpp +++ b/include/openglu.hpp @@ -15,6 +15,8 @@ #include #include +#include + namespace oglu { /** diff --git a/src/color.cpp b/src/color.cpp index 616e0ff..b8fed20 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -13,7 +13,7 @@ namespace oglu const Color Color::Transparent(0.f, 0.f, 0.f, 0.f); Color::Color() : - r(0.f), g(0.f), b(0.f), a(0.f) + r(0.f), g(0.f), b(0.f), a(1.f) { } diff --git a/src/lighting/ambient.cpp b/src/lighting/ambient.cpp new file mode 100644 index 0000000..f70fd76 --- /dev/null +++ b/src/lighting/ambient.cpp @@ -0,0 +1,24 @@ +#include "lighting/ambient.hpp" + +namespace oglu +{ + AmbientLight::AmbientLight() : + color(1.f, 1.f, 1.f), intensity(1.0f) + { + } + + AmbientLight::AmbientLight(GLfloat r, GLfloat g, GLfloat b, GLfloat intensity) : + color(r, g, b), intensity(intensity) + { + } + + AmbientLight::AmbientLight(const Color& color, GLfloat intensity) : + color(color), intensity(intensity) + { + } + + AmbientLight::AmbientLight(const AmbientLight& other) : + color(other.color), intensity(other.intensity) + { + } +} \ No newline at end of file