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;
|
using namespace std;
|
||||||
|
|
||||||
Model model;
|
|
||||||
Texture texture;
|
|
||||||
Shader shader;
|
Shader shader;
|
||||||
Object object;
|
Level level;
|
||||||
|
|
||||||
// gets called after the OpenGL window is prepared:
|
// gets called after the OpenGL window is prepared:
|
||||||
void initCustomResources()
|
void initCustomResources()
|
||||||
@ -21,18 +19,15 @@ void initCustomResources()
|
|||||||
ACGL::Base::Settings::the()->setTexturePath("Geometry/");
|
ACGL::Base::Settings::the()->setTexturePath("Geometry/");
|
||||||
ACGL::Base::Settings::the()->setGeometryPath("Geometry/");
|
ACGL::Base::Settings::the()->setGeometryPath("Geometry/");
|
||||||
|
|
||||||
// load the geometry of the stanford bunny and build a VAO:
|
// load Model to give shader correct Attribute locations
|
||||||
model = Model("Bunny.obj");
|
// TODO look up if this is really necessary, since this looks really stupid.
|
||||||
|
Model model = Model("Bunny.obj");
|
||||||
// load a texture:
|
|
||||||
texture = Texture("clownfishBunny.png");
|
|
||||||
|
|
||||||
// look up all shader files starting with 'HelloWorld' and build a ShaderProgram from it:
|
// look up all shader files starting with 'HelloWorld' and build a ShaderProgram from it:
|
||||||
shader = Shader("HelloWorld", model);
|
shader = Shader("HelloWorld", model);
|
||||||
|
|
||||||
//Create object
|
// load Level
|
||||||
object = Object(model, texture, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
level.load(shader);
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
|
||||||
|
|
||||||
// just in case: check for errors
|
// just in case: check for errors
|
||||||
openGLCriticalError();
|
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) );
|
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
||||||
|
|
||||||
// render the bunny:
|
// render the bunny:
|
||||||
object.render();
|
level.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void resizeCallback( GLFWwindow *, int newWidth, int newHeight )
|
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
|
#define LEVEL_HH_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "object.hh"
|
||||||
|
#include "light.hh"
|
||||||
#include "entity.hh"
|
#include "entity.hh"
|
||||||
#include "terrain.hh"
|
#include "terrain.hh"
|
||||||
|
#include "shader.hh"
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
Level(std::string filePath);
|
Level(std::string filePath);
|
||||||
|
Level();
|
||||||
~Level();
|
~Level();
|
||||||
void load();
|
void load(Shader shader); // Shader is necessary for correct texture assigning
|
||||||
|
void render();
|
||||||
private:
|
private:
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
std::vector<Entity> entities;
|
std::vector<Object> objects;
|
||||||
|
std::vector<Light> lights;
|
||||||
|
glm::vec3 ambientLight;
|
||||||
Terrain terrain;
|
Terrain terrain;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user