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

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

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

    00001 /*
    00002  * source file for SceneObject_Water 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_Water.h"
    00013
    00014 SceneObject_Water::SceneObject_Water()
    00015 {
    00016         const GLfloat vertices3f[4*3 + 4*2]= {
    00017                 -100.0f, 0.0f,-100.0f,
    00018                 -100.0f, 0.0f, 100.0f,
    00019                 100.0f, 0.0f, -100.0f,
    00020                 100.0f, 0.0f, 100.0f,
    00021                 0.0f, 0.0f,
    00022                 0.0f, 100.0f,
    00023                 100.0f, 0.0f,
    00024                 100.0f, 100.0f
    00025         };
    00026
    00027     //clear error status
    00028     glGetError();
    00029
    00030     // create VAO
    00031     glGenVertexArrays(1, &this->vao);
    00032     glBindVertexArray(this->vao);
    00033
    00034     //in vec3 in_Position;
    00035     glGenBuffers(1, &this->buffer_vertices3f);
    00036     glBindBuffer(GL_ARRAY_BUFFER, this->buffer_vertices3f);
    00037     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices3f), vertices3f, GL_STATIC_DRAW);
    00038
    00039     //check for error
    00040     GLenum error = glGetError();
    00041
    00042     if (error != GL_NO_ERROR)
    00043         Logger::instance()->log(Logger::ERROR, translateGLerror(error));
    00044
    00045     Logger::instance()->log(Logger::DEBUG, "SceneObject_SimpleTriangle created");
    00046 }
    00047
    00048 void SceneObject_Water::itlBeforeRender()
    00049 {
    00050     if (m_tRenderState == LightAsCam)
    00051         return;
    00052
    00053     //because our childs should be reflected objects, we must change the culling face to front (because front in normal == back in reflection ...)
    00054     glCullFace(GL_FRONT);
    00055
    00056     //Enable custom clipping plane 0, which is defined in the shader
    00057     glEnable(GL_CLIP_DISTANCE0);
    00058
    00059     ShaderManager::instance()->pushActiveShader();
    00060     ShaderManager::instance()->activateShader("phong_shader-reflection");
    00061     ShaderManager::instance()->lockActiveShader();
    00062
    00063     //change renderstate to reflected
    00064     m_tRenderState = Reflected;
    00065
    00066 }
    00067
    00068 void SceneObject_Water::itlRender()
    00069 {
    00070     if (m_tRenderState == LightAsCam)
    00071         return;
    00072
    00073     glCullFace(GL_BACK);
    00074     //Enable custom clipping plane 0, which is defined in the shader
    00075     glDisable(GL_CLIP_DISTANCE0);
    00076
    00077     ShaderManager::instance()->unlockActiveShader();
    00078     ShaderManager::instance()->activateShader("water");
    00079     GLuint used_unit = TextureManager::instance()->useTexture("scene_reflection");
    00080     GLuint used_unit2 = TextureManager::instance()->useTexture("water_bump");
    00081     GLuint used_unit3 = TextureManager::instance()->useTexture("scene_refraction");
    00082
    00083     const GLint l_in_Position(ShaderManager::instance()->getAttribute("in_Position"));
    00084     const GLint l_in_Texcoord(ShaderManager::instance()->getAttribute("in_Texcoord"));
    00085     const GLint l_refraction_texture(ShaderManager::instance()->getUniform("refraction_texture"));
    00086     const GLint l_reflection_texture(ShaderManager::instance()->getUniform("reflection_texture"));
    00087     const GLint l_water_texture(ShaderManager::instance()->getUniform("water_texture"));
    00088
    00089     GLint l_shadow_texture = ShaderManager::instance()->getUniform("shadowmap");
    00090     if (l_shadow_texture != -1)
    00091     {
    00092             GLuint texture_unit_shadowmap = TextureManager::instance()->useTexture("fbo_light_color");      //load texture in texture unit
    00093             glUniform1i(l_shadow_texture, texture_unit_shadowmap);   //tell the shader which texture unit was used
    00094     }
    00095
    00096     glUniform1i(l_reflection_texture, used_unit);
    00097     glUniform1i(l_refraction_texture, used_unit3);
    00098     glUniform1i(l_water_texture, used_unit2);
    00099
    00100     this->sendTransformMatrices(true);
    00101
    00102     glBindVertexArray(vao);
    00103     glBindBuffer(GL_ARRAY_BUFFER, this->buffer_vertices3f);
    00104
    00105     glVertexAttribPointer(l_in_Position, 3, GL_FLOAT, GL_TRUE, 0, NULL);
    00106     glVertexAttribPointer(l_in_Texcoord, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid *) (12 * sizeof(GLfloat)));
    00107     glEnableVertexAttribArray(l_in_Position);
    00108     glEnableVertexAttribArray(l_in_Texcoord);
    00109
    00110     // draw the geometry
    00111     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    00112
    00113     TextureManager::instance()->unuseTexture("scene_reflection");
    00114     TextureManager::instance()->unuseTexture("scene_refraction");
    00115     TextureManager::instance()->unuseTexture("water_bump");
    00116     if (l_shadow_texture != -1)
    00117         TextureManager::instance()->unuseTexture("fbo_light_color");
    00118
    00119     ShaderManager::instance()->popActiveShader();
    00120 }
    00121
    00122 SceneObject_Water::~SceneObject_Water()
    00123 {
    00124
    00125 }

All Classes Functions Variables Enumerations Enumerator