diff --git a/graphics.cc b/graphics.cc index 37b899d..2d7e4ab 100644 --- a/graphics.cc +++ b/graphics.cc @@ -1,11 +1,11 @@ #include "graphics.hh" #include "model.hh" -#include "shader.hh" +#include 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(1.0472f * runTime, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale(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; igetUniformLocation("lightSources"), + glUniform3fv(shader->getUniformLocation("lightSources"), sizeof(lightSources), (GLfloat*) lightSources); // Build light colour array glm::vec3 lightColours[level.getLights().size()]; - for(int i = 0; igetUniformLocation("lightColors"), + glUniform3fv(shader->getUniformLocation("lightColors"), sizeof(lightColours), (GLfloat*) lightColours); // Build light attenuation array float lightIntensities[level.getLights().size()]; - for(int i = 0; igetUniformLocation("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(); diff --git a/level.cc b/level.cc index fd1038f..e5e2d56 100644 --- a/level.cc +++ b/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; iterrain.render(); diff --git a/level.hh b/level.hh index 0fc8589..a2da274 100644 --- a/level.hh +++ b/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 getLights(); diff --git a/object.cc b/object.cc index d61fe5e..8d4b910 100644 --- a/object.cc +++ b/object.cc @@ -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() { diff --git a/object.hh b/object.hh index 6845050..000a4c9 100644 --- a/object.hh +++ b/object.hh @@ -4,7 +4,6 @@ #include "entity.hh" #include "model.hh" #include "material.hh" -#include "shader.hh" #include #include #include @@ -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(); diff --git a/ourShader.cc b/ourShader.cc deleted file mode 100644 index 2dd64ce..0000000 --- a/ourShader.cc +++ /dev/null @@ -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; -} diff --git a/ourShader.hh b/ourShader.hh deleted file mode 100644 index 7779552..0000000 --- a/ourShader.hh +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SHADER_HH_INCLUDED -#define SHADER_HH_INCLUDED - -#include "model.hh" -#include -#include - -class OurShader { - public: - OurShader(std::string filePath, Model model); - OurShader(); - ACGL::OpenGL::SharedShaderProgram getReference(); - ~OurShader(); - private: - ACGL::OpenGL::SharedShaderProgram reference; -}; - -#endif diff --git a/shader.cc b/shader.cc deleted file mode 100644 index 159d02c..0000000 --- a/shader.cc +++ /dev/null @@ -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; -} diff --git a/shader.hh b/shader.hh deleted file mode 100644 index 9c264ce..0000000 --- a/shader.hh +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SHADER_HH_INCLUDED -#define SHADER_HH_INCLUDED - -#include "model.hh" -#include -#include - -class Shader { - public: - Shader(std::string filePath, Model model); - Shader(); - ACGL::OpenGL::SharedShaderProgram getReference(); - ~Shader(); - private: - ACGL::OpenGL::SharedShaderProgram reference; -}; - -#endif