Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7986 in orxonox.OLD for branches


Ignore:
Timestamp:
May 30, 2006, 6:32:51 PM (18 years ago)
Author:
stefalie
Message:

branches/water: everything fine so far, but i need another TextureUnit

Location:
branches/water/src/world_entities/environments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/water/src/world_entities/environments/mapped_water.cc

    r7983 r7986  
    3434    this->loadParams(root);
    3535
    36   //! todo: rename texture to reflection texture
     36  PRINTF(0)("MaxTextureUnits: %i\n", Material::getMaxTextureUnits());
     37
     38  // TODO rename texture to reflection texture
     39  /// loads the textures
    3740  // set up refleciton texture
    3841  // FIXME mat.setDiffuseMap(this->texture, 0); doesnt work,
    3942  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0);
    4043  // load refraction texture
    41  // mat.setDiffuseMap("pictures/sky-replace.jpg", 1);
     44  mat.setDiffuseMap("pictures/error_texture.png", GL_TEXTURE_2D, 1);
    4245  // load normal map
    4346  mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
    4447  // load dudv map
    45    mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
     48  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
    4649  // set up depth texture
    47 //  mat.setDiffuseMap("pictures/sky-replace.jpg", 4);
    48 
     50  //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 2);
     51
     52
     53
     54  /// MAKE THE MAPPING TEXTURE.
     55  // THIS IS A HACK AND SHOULD BE IN TEXTURE SOMEWHERE
    4956  // set the size of the refraction and reflection textures
    50 
    51 
    52 
    53   /// MAKE THE MAPPING TEXTURE.
    54   // THIS IS A HACK AND SHOULD BE IN TEXTURE SOMEWHERE.
    5557  this->textureSize = 512;
    5658  unsigned int channels = 32;
     
    5860  unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
    5961  memset(pTextureReflection, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    60 //  unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
    61 //  memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
     62  unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
     63  memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    6264  // Register the texture with OpenGL and bind it to the texture ID
    6365  mat.select();
     
    7072
    7173  //the same for the refraction
    72 //  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
    73 //  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction);
     74  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
     75  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction);
    7476
    7577  // Set the texture quality
     
    8183  // Since we stored the texture space with OpenGL, we can delete the image data
    8284  delete [] pTextureReflection;
    83 //  delete [] pTextureRefraction;
    84 
    85 
    86   //shader = new Shader( "/home/stefalie/svn/orxonox/data/trunk/shaders/water.vert", "/home/stefalie/svn/orxonox/data/trunk/shaders/mapped_water.frag");
    87   shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
    88 
     85  delete [] pTextureRefraction;
     86
     87
     88  /// initialization of the texture coords, speeds etc...
    8989  this->move = 0.0f;
    9090  this->g_WaterUV = 35.0f;
     
    9292  this->g_WaterFlow = 0.0015f;
    9393
    94   /// Initialization of the shaders
     94  /// initialization of the shaders
     95  // load shader files
     96  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
     97
    9598  this->shader->activateShader();
    9699  // Set the variable "reflection" to correspond to the first texture unit
    97100  Shader::Uniform(shader, "reflection").set(0);
    98 
    99101  // Set the variable "refraction" to correspond to the second texture unit
    100   //this->uni = new Shader::Uniform (shader, "refraction");
    101   //this->uni->set(1);
    102 
     102  Shader::Uniform(shader, "refraction").set(1);
    103103  // Set the variable "normalMap" to correspond to the third texture unit
    104104  Shader::Uniform(shader, "normalMap").set(2);
    105 
    106105  // Set the variable "dudvMap" to correspond to the fourth texture unit
    107106  Shader::Uniform(shader, "dudvMap").set(3);
    108 
    109107  // Set the variable "depthMap" to correspond to the fifth texture unit
    110   //this->uni = new Shader::Uniform (shader, "depthMap");
    111   //this->uni->set(4);
    112   this->shader->activateShader();
     108  //Shader::Uniform(shader, "depthMap").set(4);
     109  // Give the variable "waterColor" a blue color
     110  Shader::Uniform(shader, "waterColor").set(0.1f, 0.2f, 0.4f, 1.0f);
     111  // Give the variable "lightPos" our hard coded light position
     112  Shader::Uniform(shader, "lightPos").set(lightPos.x, lightPos.y, lightPos.z, 1.0f);
     113  // uniform for the camera position
     114  cam_uni = new Shader::Uniform(shader, "cameraPos");
     115
     116  this->shader->deactivateShader();
    113117}
    114118
    115119MappedWater::~MappedWater()
    116120{
    117   //delete shader;
     121  delete shader;
     122  delete cam_uni;
    118123}
    119124
     
    123128
    124129  LoadParam(root, "waterHeight", this, MappedWater, setHeight);
     130  LoadParam(root, "lightPos", this, MappedWater, setLightPosition);
    125131}
    126132
     
    134140  mat.select();
    135141
    136 
    137 
    138   // Shader init
    139142  this->shader->activateShader();
    140   GLint uniform;
    141 
    142 
    143 
    144 
    145 
    146   // Give the variable "waterColor" a blue color
    147   uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");
    148   glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);
    149 
    150   // FIXME set camera and light information
    151   Vector lightPos(100.0f, 600.0f, 100.0f);
    152   Vector vPosition = State::getCameraNode()->getAbsCoor();
    153   // Store the camera position in a variable
    154   //CVector3 vPosition = g_Camera.Position();
    155   //Vector vPosition(50.0f, 50.0f, 50.0f);
    156 
    157   // Give the variable "lightPos" our hard coded light position
    158   uniform = glGetUniformLocationARB(shader->getProgram(), "lightPos");
    159   glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f);
    160 
    161   // Give the variable "cameraPos" our camera position
    162   uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos");
    163   glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f);
    164 
    165 
    166 
    167 
    168 
     143
     144  // reset the camera uniform to the current cam position
     145  Vector pos = State::getCameraNode()->getAbsCoor();
     146  cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
    169147
    170148  glBegin(GL_QUADS);
  • branches/water/src/world_entities/environments/mapped_water.h

    r7983 r7986  
    2020    void loadParams(const TiXmlElement* root);
    2121
     22
    2223    void activateReflection();
    2324    void deactivateReflection();
     
    3031
    3132  private:
     33    void setLightPosition(float x, float y, float z) { this->lightPos = Vector(x,y,z); };
    3234    void setHeight(float height);
    3335
     
    4446
    4547    int                 textureSize;                //!< size of the texture
     48    Vector              lightPos;
    4649    Material            mat;
    4750    Shader*             shader;
    48     Shader::Uniform*    uni;
     51    Shader::Uniform*    cam_uni;                        //!< uniform that is used for the camera position
    4952
    5053};
Note: See TracChangeset for help on using the changeset viewer.