diff --git a/resources/config/textures.xml b/resources/config/textures.xml
index a76be6590..2082e678a 100644
--- a/resources/config/textures.xml
+++ b/resources/config/textures.xml
@@ -2,6 +2,7 @@
+
diff --git a/resources/textures/moon_phases.png b/resources/textures/moon_phases.png
new file mode 100644
index 000000000..82d7c4b44
Binary files /dev/null and b/resources/textures/moon_phases.png differ
diff --git a/source/client/graphics/CelestialObject.cpp b/source/client/graphics/CelestialObject.cpp
index 83eddd72f..f0b9c19e0 100644
--- a/source/client/graphics/CelestialObject.cpp
+++ b/source/client/graphics/CelestialObject.cpp
@@ -26,6 +26,7 @@
*/
#include
#include
+#include
#include
#include "CelestialObject.hpp"
@@ -62,14 +63,25 @@ void CelestialObject::updateVertexBuffer() const {
}
if (m_texture) {
- vertices[0].texCoord[0] = 1.f;
- vertices[0].texCoord[1] = 0.f;
- vertices[1].texCoord[0] = 0.f;
- vertices[1].texCoord[1] = 0.f;
- vertices[2].texCoord[0] = 0.f;
- vertices[2].texCoord[1] = 1.f;
- vertices[3].texCoord[0] = 1.f;
- vertices[3].texCoord[1] = 1.f;
+ gk::FloatRect texRect{0, 0, 1, 1};
+
+ if (m_phaseCount && m_phaseSize && m_currentPhase < m_phaseCount) {
+ u16 currentPhaseX = m_currentPhase % (m_texture->getSize().x / m_phaseSize);
+ u16 currentPhaseY = m_currentPhase / (m_texture->getSize().x / m_phaseSize);
+ texRect.x = currentPhaseX / float(m_texture->getSize().x);
+ texRect.y = currentPhaseY / float(m_texture->getSize().y);
+ texRect.sizeX = m_phaseSize / float(m_texture->getSize().x);
+ texRect.sizeY = m_phaseSize / float(m_texture->getSize().y);
+ }
+
+ vertices[0].texCoord[0] = texRect.x + texRect.sizeX;
+ vertices[0].texCoord[1] = texRect.y;
+ vertices[1].texCoord[0] = texRect.x;
+ vertices[1].texCoord[1] = texRect.y;
+ vertices[2].texCoord[0] = texRect.x;
+ vertices[2].texCoord[1] = texRect.y + texRect.sizeY;
+ vertices[3].texCoord[0] = texRect.x + texRect.sizeX;
+ vertices[3].texCoord[1] = texRect.y + texRect.sizeY;
}
gk::VertexBuffer::bind(&m_vbo);
diff --git a/source/client/graphics/CelestialObject.hpp b/source/client/graphics/CelestialObject.hpp
index d0351fc01..1111d2b41 100644
--- a/source/client/graphics/CelestialObject.hpp
+++ b/source/client/graphics/CelestialObject.hpp
@@ -42,6 +42,8 @@ class CelestialObject : public gk::Drawable, public gk::Transformable {
void setColor(const gk::Color &color) { m_color = color; m_isUpdateNeeded = true; }
void setSize(float width, float height) { m_width = width; m_height = height; m_isUpdateNeeded = true; }
void setTexture(const std::string &textureName);
+ void setPhaseCount(u16 phaseCount, u16 phaseSize) { m_phaseCount = phaseCount; m_phaseSize = phaseSize; m_isUpdateNeeded = true; }
+ void setCurrentPhase(u16 currentPhase) { m_currentPhase = currentPhase; m_isUpdateNeeded = true; }
private:
void updateVertexBuffer() const;
@@ -58,6 +60,10 @@ class CelestialObject : public gk::Drawable, public gk::Transformable {
const gk::Texture *m_texture = nullptr;
mutable bool m_isUpdateNeeded = true;
+
+ u16 m_phaseCount = 0;
+ u16 m_phaseSize = 0;
+ u16 m_currentPhase = 0;
};
#endif // CELESTIALOBJECT_HPP_
diff --git a/source/client/graphics/Skybox.cpp b/source/client/graphics/Skybox.cpp
index 5d868ff03..8b1f9d096 100644
--- a/source/client/graphics/Skybox.cpp
+++ b/source/client/graphics/Skybox.cpp
@@ -37,13 +37,16 @@ Skybox::Skybox(gk::Camera &camera, ClientWorld &world) : m_camera(camera), m_wor
m_shader.linkProgram();
m_sun.setColor(gk::Color::Yellow);
- m_sun.setSize(100, 100);
- m_sun.setPosition(300, -m_sun.width() / 2, -m_sun.height() / 2);
+ m_sun.setSize(200, 200);
+ m_sun.setPosition(500, -m_sun.width() / 2, -m_sun.height() / 2);
m_sun.setTexture("texture-sun");
m_moon.setColor(gk::Color{240, 240, 240});
- m_moon.setSize(20, 20);
- m_moon.setPosition(-300, -m_moon.width() / 2, -m_moon.height() / 2);
+ m_moon.setSize(200, 200);
+ m_moon.setPosition(-500, -m_moon.width() / 2, -m_moon.height() / 2);
+ m_moon.setTexture("texture-moon_phases");
+ m_moon.setPhaseCount(8, 32);
+ m_moon.setCurrentPhase(0);
}
void Skybox::draw(gk::RenderTarget &target, gk::RenderStates states) const {