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

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

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

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

All Classes Functions Variables Enumerations Enumerator