diff options
author | Aki <please@ignore.pl> | 2022-11-07 19:16:34 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-11-07 19:16:34 +0100 |
commit | c50dd6c72bba260d22c10761a979b0c1426dffec (patch) | |
tree | 558a1f292606a84530fdd08e46cee635c2d7fdfa | |
parent | e2dfc5c083857f279b55e4845430ccfa1c503828 (diff) | |
download | kurator-c50dd6c72bba260d22c10761a979b0c1426dffec.zip kurator-c50dd6c72bba260d22c10761a979b0c1426dffec.tar.gz kurator-c50dd6c72bba260d22c10761a979b0c1426dffec.tar.bz2 |
Added example rather low quality skybox
-rw-r--r-- | kurator/CMakeLists.txt | 4 | ||||
-rw-r--r-- | kurator/resources/shaders/330/skybox.fs | 14 | ||||
-rw-r--r-- | kurator/resources/shaders/330/skybox.vs | 17 | ||||
-rw-r--r-- | kurator/resources/skybox.png | bin | 0 -> 3141841 bytes | |||
-rw-r--r-- | kurator/src/Skybox.cpp | 49 | ||||
-rw-r--r-- | kurator/src/Skybox.h | 23 | ||||
-rw-r--r-- | kurator/src/SkyboxTest.cpp | 47 | ||||
-rw-r--r-- | kurator/src/SkyboxTest.h | 29 | ||||
-rw-r--r-- | kurator/src/Title.cpp | 4 |
9 files changed, 184 insertions, 3 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 75d00a4..0250b9d 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -1,9 +1,11 @@ project(kurator) add_executable( ${PROJECT_NAME} - src/main.cpp src/GameOver.cpp + src/main.cpp src/Session.cpp + src/Skybox.cpp + src/SkyboxTest.cpp src/Title.cpp ) target_link_libraries( diff --git a/kurator/resources/shaders/330/skybox.fs b/kurator/resources/shaders/330/skybox.fs new file mode 100644 index 0000000..ccc97d4 --- /dev/null +++ b/kurator/resources/shaders/330/skybox.fs @@ -0,0 +1,14 @@ +#version 330 + +in vec3 fragPosition; + +uniform samplerCube environmentMap; + +out vec4 finalColor; + + +void main() +{ + vec3 color = texture(environmentMap, fragPosition).rgb; + finalColor = vec4(color, 1.0); +} diff --git a/kurator/resources/shaders/330/skybox.vs b/kurator/resources/shaders/330/skybox.vs new file mode 100644 index 0000000..cfb2599 --- /dev/null +++ b/kurator/resources/shaders/330/skybox.vs @@ -0,0 +1,17 @@ +#version 330 + +in vec3 vertexPosition; + +uniform mat4 matProjection; +uniform mat4 matView; + +out vec3 fragPosition; + + +void main() +{ + fragPosition = vertexPosition; + mat4 rotView = mat4(mat3(matView)); + vec4 clipPos = matProjection * rotView * vec4(vertexPosition, 1.0); + gl_Position = clipPos; +} diff --git a/kurator/resources/skybox.png b/kurator/resources/skybox.png Binary files differnew file mode 100644 index 0000000..a351869 --- /dev/null +++ b/kurator/resources/skybox.png diff --git a/kurator/src/Skybox.cpp b/kurator/src/Skybox.cpp new file mode 100644 index 0000000..036f2a7 --- /dev/null +++ b/kurator/src/Skybox.cpp @@ -0,0 +1,49 @@ +#include "Skybox.h" + +#include <string> + +#include <raylib.h> +#include <rlgl.h> + + +namespace kurator +{ + + +Skybox::Skybox(const std::string& texture) +{ + Mesh cube = GenMeshCube(1.f, 1.f, 1.f); + model = LoadModelFromMesh(cube); + model.materials[0].shader = LoadShader("resources/shaders/330/skybox.vs", "resources/shaders/330/skybox.fs"); + int value {MATERIAL_MAP_CUBEMAP}; + SetShaderValue( + model.materials[0].shader, + GetShaderLocation(model.materials[0].shader, "environmentMap"), + &value, + SHADER_UNIFORM_INT); + Image image = LoadImage(texture.c_str()); + model.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(image, CUBEMAP_LAYOUT_AUTO_DETECT); + UnloadImage(image); +} + + +Skybox::~Skybox() +{ + UnloadShader(model.materials[0].shader); + UnloadTexture(model.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture); + UnloadModel(model); +} + + +void +Skybox::draw() const +{ + rlDisableBackfaceCulling(); + rlDisableDepthMask(); + DrawModel(model, {0.f, 0.f, 0.f}, 1.0f, WHITE); + rlEnableBackfaceCulling(); + rlEnableDepthMask(); +} + + +} // namespace kurator diff --git a/kurator/src/Skybox.h b/kurator/src/Skybox.h new file mode 100644 index 0000000..3f71837 --- /dev/null +++ b/kurator/src/Skybox.h @@ -0,0 +1,23 @@ +#pragma once + +#include <string> + +#include <raylib.h> + + +namespace kurator +{ + + +class Skybox +{ +public: + explicit Skybox(const std::string& texture); + ~Skybox(); + void draw() const; +private: + Model model; +}; + + +} // namespace kurator diff --git a/kurator/src/SkyboxTest.cpp b/kurator/src/SkyboxTest.cpp new file mode 100644 index 0000000..85809f4 --- /dev/null +++ b/kurator/src/SkyboxTest.cpp @@ -0,0 +1,47 @@ +#include "SkyboxTest.h" + +#include <memory> +#include <utility> + +#include <raylib.h> + +#include "GameOver.h" +#include "Session.h" + + +namespace kurator +{ + + +SkyboxTest::SkyboxTest(std::shared_ptr<Session> _session) : + session {std::move(_session)}, + camera {{1.f, 1.f, 1.f}, {4.f, 1.f, 4.f}, {0.f, 1.f, 0.f}, 45.f, 0}, + skybox {"resources/skybox.png"} +{ + SetCameraMode(camera, CAMERA_FIRST_PERSON); +} + + +void +SkyboxTest::update(const float) +{ + UpdateCamera(&camera); + if (IsKeyPressed(KEY_SPACE)) { + auto next = std::make_shared<GameOver>(session); + session->set(next); + } +} + + +void +SkyboxTest::draw() const +{ + ClearBackground(BLACK); + BeginMode3D(camera); + skybox.draw(); + DrawGrid(10, 1.f); + EndMode3D(); +} + + +} // namespace kurator diff --git a/kurator/src/SkyboxTest.h b/kurator/src/SkyboxTest.h new file mode 100644 index 0000000..f1ec06b --- /dev/null +++ b/kurator/src/SkyboxTest.h @@ -0,0 +1,29 @@ +#pragma once + +#include <memory> + +#include <raylib.h> + +#include "Scene.h" +#include "Session.h" +#include "Skybox.h" + + +namespace kurator +{ + + +class SkyboxTest : public Scene +{ +public: + explicit SkyboxTest(std::shared_ptr<Session> _session); + void update(float dt) override; + void draw() const override; +private: + std::shared_ptr<Session> session; + Camera camera; + Skybox skybox; +}; + + +} // namespace kurator diff --git a/kurator/src/Title.cpp b/kurator/src/Title.cpp index 56f52a8..92d0b4d 100644 --- a/kurator/src/Title.cpp +++ b/kurator/src/Title.cpp @@ -5,8 +5,8 @@ #include <raylib.h> -#include "GameOver.h" #include "Session.h" +#include "SkyboxTest.h" namespace kurator @@ -23,7 +23,7 @@ void Title::update(const float) { if (IsKeyPressed(KEY_SPACE)) { - auto next = std::make_shared<GameOver>(session); + auto next = std::make_shared<SkyboxTest>(session); session->set(next); } } |