Removed own Shader wrapper, because it does nothing useful.
This commit is contained in:
parent
0754ad09db
commit
c38629823d
30
graphics.cc
30
graphics.cc
@ -1,11 +1,11 @@
|
||||
#include "graphics.hh"
|
||||
|
||||
#include "model.hh"
|
||||
#include "shader.hh"
|
||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Shader shader;
|
||||
ACGL::OpenGL::SharedShaderProgram shader;
|
||||
Level level;
|
||||
|
||||
// gets called after the OpenGL window is prepared:
|
||||
@ -22,7 +22,9 @@ void initCustomResources()
|
||||
Model model = Model("Bunny.obj");
|
||||
|
||||
// look up all shader files starting with 'phong' and build a ShaderProgram from it:
|
||||
shader = Shader("phong", model);
|
||||
shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations(
|
||||
model.getReference()->getAttributeLocations()).create();
|
||||
shader->use();
|
||||
|
||||
// load Level
|
||||
level.load(shader);
|
||||
@ -43,40 +45,40 @@ void draw( float runTime )
|
||||
|
||||
// set view and projection matrix:
|
||||
glm::mat4 viewMatrix = glm::translate(glm::vec3(0.0f, -1.0f, -2.0f)) * glm::rotate<float>(1.0472f * runTime, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale<float>(glm::vec3(0.25f));
|
||||
shader.getReference()->setUniform( "uViewMatrix", viewMatrix );
|
||||
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
||||
shader->setUniform( "uViewMatrix", viewMatrix );
|
||||
shader->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
||||
|
||||
//set lighting parameters
|
||||
if (level.getLights().size() > 0) {
|
||||
shader.getReference()->setUniform("lightCount", (int) level.getLights().size());
|
||||
shader->setUniform("lightCount", (int) level.getLights().size());
|
||||
|
||||
// TODO look into doing this less often
|
||||
// Build light position array
|
||||
glm::vec3 lightSources[level.getLights().size()];
|
||||
for(int i = 0; i<level.getLights().size(); i++) {
|
||||
for(unsigned int i = 0; i<level.getLights().size(); i++) {
|
||||
lightSources[i] = level.getLights()[i].getPosition();
|
||||
}
|
||||
glUniform3fv(shader.getReference()->getUniformLocation("lightSources"),
|
||||
glUniform3fv(shader->getUniformLocation("lightSources"),
|
||||
sizeof(lightSources), (GLfloat*) lightSources);
|
||||
// Build light colour array
|
||||
glm::vec3 lightColours[level.getLights().size()];
|
||||
for(int i = 0; i<level.getLights().size(); i++) {
|
||||
for(unsigned int i = 0; i<level.getLights().size(); i++) {
|
||||
lightColours[i] = level.getLights()[i].getColour();
|
||||
}
|
||||
glUniform3fv(shader.getReference()->getUniformLocation("lightColors"),
|
||||
glUniform3fv(shader->getUniformLocation("lightColors"),
|
||||
sizeof(lightColours), (GLfloat*) lightColours);
|
||||
// Build light attenuation array
|
||||
float lightIntensities[level.getLights().size()];
|
||||
for(int i = 0; i<level.getLights().size(); i++) {
|
||||
for(unsigned int i = 0; i<level.getLights().size(); i++) {
|
||||
lightIntensities[i] = level.getLights()[i].getIntensity();
|
||||
}
|
||||
glUniform1fv(shader.getReference()->getUniformLocation("lightIntensities"),
|
||||
glUniform1fv(shader->getUniformLocation("lightIntensities"),
|
||||
sizeof(lightIntensities), (GLfloat*) lightIntensities);
|
||||
}
|
||||
|
||||
// set Material Parameters
|
||||
shader.getReference()->setUniform("ambientColor", level.getAmbientLight());
|
||||
shader.getReference()->setUniform("camera", glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
shader->setUniform("ambientColor", level.getAmbientLight());
|
||||
shader->setUniform("camera", glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
// render the level(currently only a bunny):
|
||||
level.render();
|
||||
|
4
level.cc
4
level.cc
@ -11,7 +11,7 @@ Level::Level() {
|
||||
Level::~Level() {
|
||||
}
|
||||
|
||||
void Level::load(Shader shader) {
|
||||
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
||||
//this->terrain.load();
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ void Level::load(Shader shader) {
|
||||
}
|
||||
|
||||
void Level::render() {
|
||||
for(int i = 0; i<objects.size(); i++) {
|
||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||
objects[i].render();
|
||||
}
|
||||
//this->terrain.render();
|
||||
|
3
level.hh
3
level.hh
@ -7,14 +7,13 @@
|
||||
#include "entity.hh"
|
||||
#include "terrain.hh"
|
||||
#include "material.hh"
|
||||
#include "shader.hh"
|
||||
|
||||
class Level {
|
||||
public:
|
||||
Level(std::string filePath);
|
||||
Level();
|
||||
~Level();
|
||||
void load(Shader shader); // Shader is necessary for correct texture assigning
|
||||
void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning
|
||||
void render();
|
||||
glm::vec3 getAmbientLight();
|
||||
std::vector<Light> getLights();
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "object.hh"
|
||||
|
||||
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation,
|
||||
glm::vec3 velocity, glm::vec3 angularVelocity, Shader shader) :
|
||||
glm::vec3 velocity, glm::vec3 angularVelocity, ACGL::OpenGL::SharedShaderProgram shader) :
|
||||
Entity(position, rotation) {
|
||||
this->model = model.getReference();
|
||||
this->material = material;
|
||||
this->velocity = velocity;
|
||||
this->angularVelocity = angularVelocity;
|
||||
this->shader = shader.getReference();
|
||||
this->shader = shader;
|
||||
}
|
||||
|
||||
Object::Object() {
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "entity.hh"
|
||||
#include "model.hh"
|
||||
#include "material.hh"
|
||||
#include "shader.hh"
|
||||
#include <string>
|
||||
#include <ACGL/Math/Math.hh>
|
||||
#include <ACGL/OpenGL/Managers.hh>
|
||||
@ -13,7 +12,8 @@
|
||||
class Object : public Entity {
|
||||
public:
|
||||
Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation,
|
||||
glm::vec3 velocity, glm::vec3 angularVelocity, Shader shader);
|
||||
glm::vec3 velocity, glm::vec3 angularVelocity,
|
||||
ACGL::OpenGL::SharedShaderProgram shader);
|
||||
Object();
|
||||
~Object();
|
||||
void render();
|
||||
|
17
ourShader.cc
17
ourShader.cc
@ -1,17 +0,0 @@
|
||||
#include "ourShader.hh"
|
||||
|
||||
OurShader::OurShader(std::string filePath, Model model) {
|
||||
reference = ACGL::OpenGL::ShaderProgramCreator(filePath).attributeLocations(
|
||||
model.getReference()->getAttributeLocations()).create();
|
||||
reference->use();
|
||||
}
|
||||
|
||||
OurShader::OurShader() {
|
||||
}
|
||||
|
||||
OurShader::~OurShader() {
|
||||
}
|
||||
|
||||
ACGL::OpenGL::SharedShaderProgram OurShader::getReference() {
|
||||
return reference;
|
||||
}
|
18
ourShader.hh
18
ourShader.hh
@ -1,18 +0,0 @@
|
||||
#ifndef SHADER_HH_INCLUDED
|
||||
#define SHADER_HH_INCLUDED
|
||||
|
||||
#include "model.hh"
|
||||
#include <string>
|
||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
||||
|
||||
class OurShader {
|
||||
public:
|
||||
OurShader(std::string filePath, Model model);
|
||||
OurShader();
|
||||
ACGL::OpenGL::SharedShaderProgram getReference();
|
||||
~OurShader();
|
||||
private:
|
||||
ACGL::OpenGL::SharedShaderProgram reference;
|
||||
};
|
||||
|
||||
#endif
|
17
shader.cc
17
shader.cc
@ -1,17 +0,0 @@
|
||||
#include "shader.hh"
|
||||
|
||||
Shader::Shader(std::string filePath, Model model) {
|
||||
reference = ACGL::OpenGL::ShaderProgramCreator(filePath).attributeLocations(
|
||||
model.getReference()->getAttributeLocations()).create();
|
||||
reference->use();
|
||||
}
|
||||
|
||||
Shader::Shader() {
|
||||
}
|
||||
|
||||
Shader::~Shader() {
|
||||
}
|
||||
|
||||
ACGL::OpenGL::SharedShaderProgram Shader::getReference() {
|
||||
return reference;
|
||||
}
|
18
shader.hh
18
shader.hh
@ -1,18 +0,0 @@
|
||||
#ifndef SHADER_HH_INCLUDED
|
||||
#define SHADER_HH_INCLUDED
|
||||
|
||||
#include "model.hh"
|
||||
#include <string>
|
||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
Shader(std::string filePath, Model model);
|
||||
Shader();
|
||||
ACGL::OpenGL::SharedShaderProgram getReference();
|
||||
~Shader();
|
||||
private:
|
||||
ACGL::OpenGL::SharedShaderProgram reference;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user