Restructured some elements from the graphis into the level. Now using a vector for all objects.
This commit is contained in:
parent
62d8a83ddb
commit
5c4b125e4d
19
graphics.cc
19
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 )
|
||||
|
30
level.cc
Normal file
30
level.cc
Normal file
@ -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<objects.size(); i++) {
|
||||
objects[i].render();
|
||||
}
|
||||
}
|
11
level.hh
11
level.hh
@ -2,17 +2,24 @@
|
||||
#define LEVEL_HH_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#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<Entity> entities;
|
||||
std::vector<Object> objects;
|
||||
std::vector<Light> lights;
|
||||
glm::vec3 ambientLight;
|
||||
Terrain terrain;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user