Load skybox from Json file

This commit is contained in:
2021-01-10 22:26:16 +01:00
parent ad7ec85dce
commit d4b3a00d73
6 changed files with 26 additions and 13 deletions

View File

@@ -2,7 +2,10 @@
"models": [
{
"unique_name": "backpack",
"path": "res/models/backpack.ffo"
"path": "res/models/backpack.ffo",
"position": ["0.0", "0.0", "0.0"],
"rotation": ["0.0", "0.0", "0.0"]
},
{
"unique_name": "ground",

View File

@@ -105,9 +105,6 @@ void Controller::run()
World world(shaderPrograms);
Model *skyboxModel = world.getModelByName("cube");
Skybox skybox(skyboxModel, getShaderProgramByName("skyboxProgram"), "res/textures/skybox/");
Entity *lightSource = world.getEntityByName("light");
lightSource->setScale(0.1f);
lightSource->setRotation(glm::vec3(0.f));
@@ -163,7 +160,7 @@ void Controller::run()
glViewport(0, 0, gameWindow->getWindowWidth(), gameWindow->getWindowHeight());
skybox.draw(camera->getView(), camera->getProj());
world.getSkybox()->draw(camera->getView(), camera->getProj());
world.draw(camera->getViewProj(), camera->getPosition());
pp_framebuffer->unbind();

View File

@@ -106,3 +106,15 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
return temp_shaderPrograms;
}
Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram)
{
Skybox* temp_skybox;
const Json::Value shaderProgramsJson = root["skybox"];
std::string skybox_texturePath = shaderProgramsJson["texturePath"].asString();
temp_skybox = new Skybox(cubeModel, skyboxProgram, skybox_texturePath.c_str());
std::cout << "Loaded Skybox \"" << skybox_texturePath << "\"" << std::endl;
return temp_skybox;
}

View File

@@ -16,6 +16,7 @@ public:
std::vector<Model*> getModels();
std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms);
Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram);
std::vector<ShaderProgram*> getShaderPrograms();

View File

@@ -30,6 +30,7 @@ World::World(std::vector<ShaderProgram*> shaderPrograms) :
JsonParser worldParser("res/models.json");
models = worldParser.getModels();
entities = worldParser.getEntities(models, shaderPrograms);
skybox = worldParser.getSkybox(getModelByName("cube"), Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram"));
}
World::~World()
@@ -45,6 +46,8 @@ World::~World()
for (auto it = entities.begin(); it != entities.end(); it++) {
delete (*it);
}
delete skybox;
}
void World::addEntity(Entity *entity)
@@ -71,12 +74,6 @@ void World::clearEntities()
}
}
void World::loadWorld ( unsigned int id )
{
// Load World from File...
}
void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color)
{
pointLights[lightId].setActive(active);

View File

@@ -18,8 +18,6 @@ public:
void removeEntityByName(std::string name);
void clearEntities();
void loadWorld(unsigned int id);
void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color);
void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color);
@@ -32,6 +30,10 @@ public:
{
return pointLights.data();
}
Skybox *getSkybox()
{
return skybox;
}
Entity* getEntityByName(std::string name);
Entity* getEntityById(uint32_t id);
@@ -45,6 +47,7 @@ private:
std::vector<Model*> models;
std::vector<Entity*> entities;
Skybox *skybox;
// Lights
DirectionalLight directionalLight;