From 5c4b125e4d77a0ca24d2348c09b21c76a3488dbe Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 30 Oct 2014 23:54:19 +0100 Subject: [PATCH] Restructured some elements from the graphis into the level. Now using a vector for all objects. --- graphics.cc | 19 +++++++------------ level.cc | 30 ++++++++++++++++++++++++++++++ level.hh | 11 +++++++++-- 3 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 level.cc diff --git a/graphics.cc b/graphics.cc index 31ec6a6..2c21566 100644 --- a/graphics.cc +++ b/graphics.cc @@ -7,10 +7,8 @@ using namespace std; -Model model; -Texture texture; Shader shader; -Object object; +Level level; // gets called after the OpenGL window is prepared: void initCustomResources() @@ -21,18 +19,15 @@ void initCustomResources() ACGL::Base::Settings::the()->setTexturePath("Geometry/"); ACGL::Base::Settings::the()->setGeometryPath("Geometry/"); - // load the geometry of the stanford bunny and build a VAO: - model = Model("Bunny.obj"); - - // load a texture: - texture = Texture("clownfishBunny.png"); + // load Model to give shader correct Attribute locations + // TODO look up if this is really necessary, since this looks really stupid. + Model model = Model("Bunny.obj"); // look up all shader files starting with 'HelloWorld' and build a ShaderProgram from it: shader = Shader("HelloWorld", model); - //Create object - object = Object(model, texture, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), - glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); + // load Level + level.load(shader); // just in case: check for errors openGLCriticalError(); @@ -54,7 +49,7 @@ void draw( float runTime ) shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) ); // render the bunny: - object.render(); + level.render(); } void resizeCallback( GLFWwindow *, int newWidth, int newHeight ) diff --git a/level.cc b/level.cc new file mode 100644 index 0000000..093a0ec --- /dev/null +++ b/level.cc @@ -0,0 +1,30 @@ +#include "level.hh" + +Level::Level(std::string filePath){ + this->filePath = filePath; +} + +Level::Level() { +} + +Level::~Level() { +} + +void Level::load(Shader shader) { + // currently hard coded should later read this stuff out of a file + // load the geometry of the stanford bunny and build a VAO: + Model model = Model("Bunny.obj"); + // load a texture: + Texture texture = Texture("clownfishBunny.png"); + //Create object + Object object = Object(model, texture, glm::vec3(0.0f, 0.0f, 0.0f), + glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), + glm::vec3(0.0f, 0.0f, 0.0f), shader); + objects.push_back(object); +} + +void Level::render() { + for(int i = 0; i +#include "object.hh" +#include "light.hh" #include "entity.hh" #include "terrain.hh" +#include "shader.hh" class Level { public: Level(std::string filePath); + Level(); ~Level(); - void load(); + void load(Shader shader); // Shader is necessary for correct texture assigning + void render(); private: std::string filePath; - std::vector entities; + std::vector objects; + std::vector lights; + glm::vec3 ambientLight; Terrain terrain; };