From d58147a935299277ac5ac86563a98bf8741fbb39 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Fri, 28 Nov 2014 00:17:56 +0100 Subject: [PATCH] You can render objects with multiple shaders now. --- graphics.cc | 4 ++-- level.cc | 18 +++++++++--------- level.hh | 4 ++-- main.cc | 2 +- object.cc | 6 ++---- object.hh | 7 +++---- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/graphics.cc b/graphics.cc index 3745972..f8dbb32 100644 --- a/graphics.cc +++ b/graphics.cc @@ -148,8 +148,8 @@ void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader) shader->setUniform("ambientColor", level->getAmbientLight()); shader->setUniform("camera", level->getCameraPosition()); - // render the level(currently only a bunny): - level->render(); + // render the level + level->render(shader); } void Graphics::setWindowSize(glm::uvec2 windowSize) { diff --git a/level.cc b/level.cc index 6ca0ea8..45497cc 100644 --- a/level.cc +++ b/level.cc @@ -17,7 +17,7 @@ Level::~Level() { } } -void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { +void Level::load() { this->physics = Physics(); this->physics.init(); @@ -29,7 +29,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { Model model = Model("MarbleSmooth.obj", 0.75f); Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f); Object* object = new Object(model, material, glm::vec3(0.0f, 10.0f, 0.0f), - glm::vec3(0.0f, 0.0f, 0.0f), shader); + glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(object); this->physics.addPlayer(1.25f,*object,8.0f,1); cameraCenter = object; @@ -37,7 +37,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { Model skydomeModel = Model("skydome.obj", skydomeSize); Material skydomeMaterial = Material("skydome.png", 0.7f, 0.0f, 0.0f, 0.0f); Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f), - glm::vec3(0.0f, 0.0f, 0.0f), shader); + glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(skydomeObject); skydome = skydomeObject; @@ -45,20 +45,20 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f); //Create object Object* torchObject = new Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f), - glm::vec3(0.0f, 1.0472f, 0.0f), shader); + glm::vec3(0.0f, 1.0472f, 0.0f)); objects.push_back(torchObject); Model blockModel = Model("Block.obj", 1.0f); Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); Object* blockObject = new Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f), - glm::vec3(0.0f, 0.0f, 0.0f), shader); + glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(blockObject); physics.addBox(1,1,1,*blockObject,0,2); Model columnModel = Model("Column.obj", 1.0f); Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.0f); Object* columnObject = new Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f), - glm::vec3(0.0f, 0.0f, 0.0f), shader); + glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(columnObject); //make non physics objects @@ -81,16 +81,16 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { //Create object Object* terrainObject = new Object(terrainModel, terrainMaterial, glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()), - glm::vec3(0.0f, 0.0f, 0.0f), shader); + glm::vec3(0.0f, 0.0f, 0.0f)); objects.push_back(terrainObject); //addTerrainPhysic physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap()); } -void Level::render() { +void Level::render(ACGL::OpenGL::SharedShaderProgram shader) { for(unsigned int i = 0; irender(); + objects.at(i)->render(shader); } } diff --git a/level.hh b/level.hh index 920be96..7a7f6a6 100644 --- a/level.hh +++ b/level.hh @@ -15,9 +15,9 @@ class Level { Level(std::string filePath); Level(); ~Level(); - void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning + void load(); void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed); - void render(); + void render(ACGL::OpenGL::SharedShaderProgram shader); glm::vec3 getAmbientLight(); Light* getDirectionalLight(); std::vector getLights(); diff --git a/main.cc b/main.cc index 797e3d8..0832167 100644 --- a/main.cc +++ b/main.cc @@ -60,7 +60,7 @@ void Application::init() shader->use(); // load Level - level.load(shader); + level.load(); // just in case: check for errors openGLCriticalError(); diff --git a/object.cc b/object.cc index b4a6d39..298d242 100644 --- a/object.cc +++ b/object.cc @@ -1,11 +1,9 @@ #include "object.hh" -Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, - ACGL::OpenGL::SharedShaderProgram shader) : +Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation) : Entity(position, rotation) { this->model = model; this->material = material; - this->shader = shader; } Object::Object() { @@ -14,7 +12,7 @@ Object::Object() { Object::~Object() { } -void Object::render() { +void Object::render(ACGL::OpenGL::SharedShaderProgram shader) { // set lightning parameters for this object shader->setUniform("ambientFactor", material.getAmbientFactor()); shader->setUniform("diffuseFactor", material.getDiffuseFactor()); diff --git a/object.hh b/object.hh index e3877ba..d5a4c2f 100644 --- a/object.hh +++ b/object.hh @@ -11,15 +11,14 @@ class Object : public Entity { public: - Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, - ACGL::OpenGL::SharedShaderProgram shader); + Object(Model model, Material material, + glm::vec3 position, glm::vec3 rotation); Object(); ~Object(); - void render(); + void render(ACGL::OpenGL::SharedShaderProgram shader); private: Model model; Material material; - ACGL::OpenGL::SharedShaderProgram shader; }; #endif