BambooIsland: C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/SceneObject_PostEffect.cpp Source File

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

# C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/SceneObject_PostEffect.cpp

    00001 /*
    00002  * source file for SceneObject_PostEffect class
    00003  * written by: christian moellinger <ch.moellinger@gmail.com>
    00004  * 11/2010
    00005  */
    00006
    00007 #include <string>
    00008
    00009 #include "TextureManager.h"
    00010 #include "Logger.h"
    00011 #include "ShaderManager.h"
    00012 #include "SceneObject_PostEffect.h"
    00013
    00014 SceneObject_PostEffect::SceneObject_PostEffect(std::string shader_name, std::string texture_name, std::string texture_name2, std::string texture_name3)
    00015     : m_sShaderName(shader_name),
    00016     m_sTextureName(texture_name),
    00017     m_sTextureName2(texture_name2),
    00018     m_sTextureName3(texture_name3)
    00019 {
    00020     const GLdouble vertices3f[]= {
    00021       -1.0, 1.0, 0.0,    //vertex position
    00022       0.0, 1.0, 0.0,    //texcoords
    00023
    00024      -1.0, -1.0, 0.0,       //vertex position
    00025      0.0, 0.0, 0.0,         //texcoords
    00026
    00027       1.0, 1.0, 0.0,        //vertex position
    00028       1.0, 1.0, 0.0,        //texcoords
    00029
    00030       1.0, -1.0, 0.0,
    00031       1.0, 0.0, 0.0,        //texcoords
    00032     };
    00033
    00034     //clear error status
    00035     glGetError();
    00036
    00037     // create VAO
    00038     glGenVertexArrays(1, &this->vao);
    00039     glBindVertexArray(this->vao);
    00040
    00041     //in vec3 in_Position;
    00042     glGenBuffers(1, &this->buffer_vertices3f);
    00043
    00044     glBindBuffer(GL_ARRAY_BUFFER, this->buffer_vertices3f);
    00045     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices3f), vertices3f, GL_STATIC_DRAW);
    00046
    00047      //check for error
    00048     GLenum error = glGetError();
    00049
    00050     if (error != GL_NO_ERROR)
    00051         Logger::instance()->log(Logger::ERROR, translateGLerror(error));
    00052
    00053     Logger::instance()->log(Logger::DEBUG, "SceneObject_PostEffect created");
    00054 }
    00055
    00056 void SceneObject_PostEffect::itlRender()
    00057 {
    00058     glBindVertexArray(vao);
    00059     glBindBuffer(GL_ARRAY_BUFFER, this->buffer_vertices3f);
    00060
    00061     ShaderManager::instance()->pushActiveShader();
    00062     ShaderManager::instance()->activateShader(m_sShaderName);
    00063
    00064     sendLightPosition();
    00065
    00066     const GLint l_in_Position(ShaderManager::instance()->getAttribute("in_Position"));
    00067     const GLint l_texcoords(ShaderManager::instance()->getAttribute("in_Texcoord"));
    00068
    00069     glVertexAttribPointer(l_in_Position, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(GLdouble), NULL);
    00070     glVertexAttribPointer(l_texcoords, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(GLdouble), (GLvoid *) (3 * sizeof(GLdouble)));
    00071
    00072     glEnableVertexAttribArray(l_in_Position);
    00073     glEnableVertexAttribArray(l_texcoords);
    00074
    00075     //load first texture and tell the shader the units id
    00076     GLuint used_texture_unit1 = TextureManager::instance()->useTexture(m_sTextureName);     //load texture in texture unit
    00077
    00078     glUniform1i(ShaderManager::instance()->getUniform("texture1"),used_texture_unit1);   //tell the shader which texture unit was used
    00079
    00080     //if two textures were given, load the second texture in an unit and tell the id the shader
    00081     if (m_sTextureName2.length() > 0)
    00082     {
    00083         GLuint used_texture_unit2 = TextureManager::instance()->useTexture(m_sTextureName2);        //load texture in texture unit
    00084         glUniform1i(ShaderManager::instance()->getUniform("texture2"),used_texture_unit2);   //tell the shader which texture unit was used
    00085     }
    00086
    00087     if (m_sTextureName3.length() > 0)
    00088     {
    00089         GLuint used_texture_unit3 = TextureManager::instance()->useTexture(m_sTextureName3);        //load texture in texture unit
    00090         glUniform1i(ShaderManager::instance()->getUniform("texture3"),used_texture_unit3);   //tell the shader which texture unit was used
    00091     }
    00092
    00093     //draw data
    00094     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    00095
    00096     //release used texture units
    00097     TextureManager::instance()->unuseTexture(m_sTextureName);                               //tell the texturemanager to release the used texture unit
    00098     if (m_sTextureName2.length() > 0)
    00099         TextureManager::instance()->unuseTexture(m_sTextureName2);
    00100
    00101     if (m_sTextureName3.length() > 0)
    00102         TextureManager::instance()->unuseTexture(m_sTextureName3);
    00103
    00104     ShaderManager::instance()->popActiveShader();
    00105 }
    00106
    00107 SceneObject_PostEffect::~SceneObject_PostEffect()
    00108 {
    00109
    00110 }

All Classes Functions Variables Enumerations Enumerator