You can render objects with multiple shaders now.
This commit is contained in:
parent
79fd16ad8d
commit
8af201fd2f
@ -148,8 +148,8 @@ void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader)
|
|||||||
shader->setUniform("ambientColor", level->getAmbientLight());
|
shader->setUniform("ambientColor", level->getAmbientLight());
|
||||||
shader->setUniform("camera", level->getCameraPosition());
|
shader->setUniform("camera", level->getCameraPosition());
|
||||||
|
|
||||||
// render the level(currently only a bunny):
|
// render the level
|
||||||
level->render();
|
level->render(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::setWindowSize(glm::uvec2 windowSize) {
|
void Graphics::setWindowSize(glm::uvec2 windowSize) {
|
||||||
|
18
level.cc
18
level.cc
@ -17,7 +17,7 @@ Level::~Level() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
void Level::load() {
|
||||||
|
|
||||||
this->physics = Physics();
|
this->physics = Physics();
|
||||||
this->physics.init();
|
this->physics.init();
|
||||||
@ -29,7 +29,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
Model model = Model("MarbleSmooth.obj", 0.75f);
|
Model model = Model("MarbleSmooth.obj", 0.75f);
|
||||||
Material material = Material("marbleTexture_small.png", 0.1f, 0.5f, 0.5f, 3.0f);
|
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),
|
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);
|
objects.push_back(object);
|
||||||
this->physics.addPlayer(1.25f,*object,8.0f,1);
|
this->physics.addPlayer(1.25f,*object,8.0f,1);
|
||||||
cameraCenter = object;
|
cameraCenter = object;
|
||||||
@ -37,7 +37,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
Model skydomeModel = Model("skydome.obj", skydomeSize);
|
Model skydomeModel = Model("skydome.obj", skydomeSize);
|
||||||
Material skydomeMaterial = Material("skydome.png", 0.7f, 0.0f, 0.0f, 0.0f);
|
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),
|
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);
|
objects.push_back(skydomeObject);
|
||||||
skydome = 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);
|
Material torchMaterial = Material("torchTexture.png", 0.1f, 0.3f, 0.7f, 10.0f);
|
||||||
//Create object
|
//Create object
|
||||||
Object* torchObject = new Object(torchModel, torchMaterial, glm::vec3(-3.0f, 6.0f, 0.0f),
|
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);
|
objects.push_back(torchObject);
|
||||||
|
|
||||||
Model blockModel = Model("Block.obj", 1.0f);
|
Model blockModel = Model("Block.obj", 1.0f);
|
||||||
Material blockMaterial = Material("blockTexture_small.png", 0.1f, 0.6, 0.4f, 2.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),
|
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);
|
objects.push_back(blockObject);
|
||||||
physics.addBox(1,1,1,*blockObject,0,2);
|
physics.addBox(1,1,1,*blockObject,0,2);
|
||||||
|
|
||||||
Model columnModel = Model("Column.obj", 1.0f);
|
Model columnModel = Model("Column.obj", 1.0f);
|
||||||
Material columnMaterial = Material("columnTexture_small.png", 0.1f, 0.6, 0.4f, 2.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),
|
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);
|
objects.push_back(columnObject);
|
||||||
|
|
||||||
//make non physics objects
|
//make non physics objects
|
||||||
@ -81,16 +81,16 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
//Create object
|
//Create object
|
||||||
Object* terrainObject = new Object(terrainModel, terrainMaterial,
|
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.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);
|
objects.push_back(terrainObject);
|
||||||
|
|
||||||
//addTerrainPhysic
|
//addTerrainPhysic
|
||||||
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
|
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::render() {
|
void Level::render(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||||
objects.at(i)->render();
|
objects.at(i)->render(shader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
level.hh
4
level.hh
@ -15,9 +15,9 @@ class Level {
|
|||||||
Level(std::string filePath);
|
Level(std::string filePath);
|
||||||
Level();
|
Level();
|
||||||
~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 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();
|
glm::vec3 getAmbientLight();
|
||||||
Light* getDirectionalLight();
|
Light* getDirectionalLight();
|
||||||
std::vector<Light> getLights();
|
std::vector<Light> getLights();
|
||||||
|
2
main.cc
2
main.cc
@ -60,7 +60,7 @@ void Application::init()
|
|||||||
shader->use();
|
shader->use();
|
||||||
|
|
||||||
// load Level
|
// load Level
|
||||||
level.load(shader);
|
level.load();
|
||||||
|
|
||||||
// just in case: check for errors
|
// just in case: check for errors
|
||||||
openGLCriticalError();
|
openGLCriticalError();
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
#include "object.hh"
|
#include "object.hh"
|
||||||
|
|
||||||
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation,
|
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation) :
|
||||||
ACGL::OpenGL::SharedShaderProgram shader) :
|
|
||||||
Entity(position, rotation) {
|
Entity(position, rotation) {
|
||||||
this->model = model;
|
this->model = model;
|
||||||
this->material = material;
|
this->material = material;
|
||||||
this->shader = shader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Object() {
|
Object::Object() {
|
||||||
@ -14,7 +12,7 @@ Object::Object() {
|
|||||||
Object::~Object() {
|
Object::~Object() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::render() {
|
void Object::render(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||||
// set lightning parameters for this object
|
// set lightning parameters for this object
|
||||||
shader->setUniform("ambientFactor", material.getAmbientFactor());
|
shader->setUniform("ambientFactor", material.getAmbientFactor());
|
||||||
shader->setUniform("diffuseFactor", material.getDiffuseFactor());
|
shader->setUniform("diffuseFactor", material.getDiffuseFactor());
|
||||||
|
@ -11,15 +11,14 @@
|
|||||||
|
|
||||||
class Object : public Entity {
|
class Object : public Entity {
|
||||||
public:
|
public:
|
||||||
Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation,
|
Object(Model model, Material material,
|
||||||
ACGL::OpenGL::SharedShaderProgram shader);
|
glm::vec3 position, glm::vec3 rotation);
|
||||||
Object();
|
Object();
|
||||||
~Object();
|
~Object();
|
||||||
void render();
|
void render(ACGL::OpenGL::SharedShaderProgram shader);
|
||||||
private:
|
private:
|
||||||
Model model;
|
Model model;
|
||||||
Material material;
|
Material material;
|
||||||
ACGL::OpenGL::SharedShaderProgram shader;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user