diff --git a/grk/project/Planet.h b/grk/project/Planet.h index 13749a5..07cf131 100644 --- a/grk/project/Planet.h +++ b/grk/project/Planet.h @@ -14,15 +14,19 @@ private: float scale; glm::vec3 position; glm::mat4 positionMatrix; + GLuint textureID; + GLuint normalMapID; public: - Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext) { + Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, GLuint textureID, GLuint normalMapID) { this->center = center; this->distanceFromCenter = distanceFromCenter; this->rotationSpeed = rotationSpeed; this->sphereContext = sphereContext; this->scale = scale; this->position = glm::vec3(0); + this->textureID = textureID; + this->normalMapID = normalMapID; } glm::mat4 getPositionMatrix() override { @@ -37,6 +41,6 @@ public: float rotationAngle = glm::radians(time * rotationSpeed); positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed) * glm::translate(glm::vec3(distanceFromCenter, 0, 0)); glm::mat4 modelMatrix = positionMatrix * glm::scale(glm::vec3(scale)); - Core::drawObjectPBR(sphereContext, modelMatrix, glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program); + Core::drawObjectPBRTexture(sphereContext, modelMatrix, textureID, 0.7, 0.0, program); } }; \ No newline at end of file diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index c51fa7b..8075e9c 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -43,6 +43,14 @@ namespace texture { GLuint earthTexture; } +struct TextureTuple { + GLuint textureID; + GLuint normalMapID; +}; + +std::vector planetTextures; + + void createGalaxy(glm::vec3 galaxyPosition); GLuint depthMapFBO; @@ -85,6 +93,15 @@ void updateDeltaTime(float time) { lastTime = time; } +TextureTuple getRandomPlanetTexture() { + int textureIndex = rand() % planetTextures.size(); + TextureTuple selectedTextures = planetTextures[textureIndex]; + //GLuint textureID = selectedTextures.textureID; + //GLuint normalMapID = selectedTextures.normalMapID; + + return planetTextures[textureIndex]; +} + void renderShadowapSun() { float time = glfwGetTime(); glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); @@ -113,12 +130,13 @@ void renderScene(GLFWwindow* window) sun->draw(); } - glUseProgram(program); - + glUseProgram(programTex); for (Planet* p : planets) { - p->draw(time, program); + p->draw(time, programTex); } + glUseProgram(program); + spaceship->renderBullets(glfwGetTime(), program); @@ -196,8 +214,11 @@ void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale); gu->getSuns()->push_back(sun); for (int i = 0; i < numberOfPlanets; i++) { + TextureTuple textures = getRandomPlanetTexture(); + GLuint texID = textures.textureID; + GLuint norMapID = textures.normalMapID; float distanceFromSum = (i + 1) * planetsDistance; - Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext); + Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext, texID, norMapID); planets.push_back(planet); } } @@ -210,6 +231,25 @@ void createEnemies() { } +void loadPlanetsTextures() { + planetTextures.clear(); + + std::vector> texturePaths = { + {"./textures/planets/planet1.png", "./textures/planets/planet1normal.png"}, + {"./textures/planets/planet2.png", "./textures/planets/planet2normal.png"}, + {"./textures/planets/planet3.png", "./textures/planets/planet3normal.png"}, + {"./textures/planets/planet4.png", "./textures/planets/planet4normal.png"} + }; + + for (const auto& paths : texturePaths) { + GLuint textureID = Core::LoadTexture(paths.first.c_str()); + GLuint normalMapID = Core::LoadTexture(paths.second.c_str()); + planetTextures.push_back({ textureID, normalMapID }); + } +} + + + void init(GLFWwindow* window) { GameUtils* gameUtils = GameUtils::getInstance(); @@ -244,9 +284,10 @@ void init(GLFWwindow* window) "bkg2_back6.png" }; + loadPlanetsTextures(); texture::cubemapTexture = Core::LoadCubemap(cubeFaces); texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg"); - texture::earthTexture = Core::LoadTexture("./textures/spaceship/earth_daymap.jpg"); + texture::earthTexture = Core::LoadTexture("./textures/planets/8k_earth_daymap.jpg"); spaceship->createParticles(); createSuns(); diff --git a/grk/project/textures/planets/8k_earth_clouds.jpg b/grk/project/textures/planets/8k_earth_clouds.jpg new file mode 100644 index 0000000..cddc9fd Binary files /dev/null and b/grk/project/textures/planets/8k_earth_clouds.jpg differ diff --git a/grk/project/textures/planets/8k_earth_daymap.jpg b/grk/project/textures/planets/8k_earth_daymap.jpg new file mode 100644 index 0000000..8948689 Binary files /dev/null and b/grk/project/textures/planets/8k_earth_daymap.jpg differ diff --git a/grk/project/textures/planets/8k_earth_nightmap.jpg b/grk/project/textures/planets/8k_earth_nightmap.jpg new file mode 100644 index 0000000..e211b6c Binary files /dev/null and b/grk/project/textures/planets/8k_earth_nightmap.jpg differ diff --git a/grk/project/textures/planets/8k_earth_normal_map.jpg b/grk/project/textures/planets/8k_earth_normal_map.jpg new file mode 100644 index 0000000..8b11d10 Binary files /dev/null and b/grk/project/textures/planets/8k_earth_normal_map.jpg differ diff --git a/grk/project/textures/planets/earth_daymap.jpg b/grk/project/textures/planets/earth_daymap.jpg new file mode 100644 index 0000000..6cdcffe Binary files /dev/null and b/grk/project/textures/planets/earth_daymap.jpg differ diff --git a/grk/project/textures/planets/planet1.png b/grk/project/textures/planets/planet1.png new file mode 100644 index 0000000..79d36e4 Binary files /dev/null and b/grk/project/textures/planets/planet1.png differ diff --git a/grk/project/textures/planets/planet1normal.png b/grk/project/textures/planets/planet1normal.png new file mode 100644 index 0000000..ed264ed Binary files /dev/null and b/grk/project/textures/planets/planet1normal.png differ diff --git a/grk/project/textures/planets/planet2.png b/grk/project/textures/planets/planet2.png new file mode 100644 index 0000000..50fec17 Binary files /dev/null and b/grk/project/textures/planets/planet2.png differ diff --git a/grk/project/textures/planets/planet2normal.png b/grk/project/textures/planets/planet2normal.png new file mode 100644 index 0000000..15c9f48 Binary files /dev/null and b/grk/project/textures/planets/planet2normal.png differ diff --git a/grk/project/textures/planets/planet3.png b/grk/project/textures/planets/planet3.png new file mode 100644 index 0000000..23c0c90 Binary files /dev/null and b/grk/project/textures/planets/planet3.png differ diff --git a/grk/project/textures/planets/planet3normal.png b/grk/project/textures/planets/planet3normal.png new file mode 100644 index 0000000..1f7e189 Binary files /dev/null and b/grk/project/textures/planets/planet3normal.png differ diff --git a/grk/project/textures/planets/planet4.png b/grk/project/textures/planets/planet4.png new file mode 100644 index 0000000..da62242 Binary files /dev/null and b/grk/project/textures/planets/planet4.png differ diff --git a/grk/project/textures/planets/planet4normal.png b/grk/project/textures/planets/planet4normal.png new file mode 100644 index 0000000..6921ee6 Binary files /dev/null and b/grk/project/textures/planets/planet4normal.png differ