Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 30, 2006, 4:48:20 PM (19 years ago)
Author:
stefalie
Message:

branches/water: …

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

Legend:

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

    r7982 r7983  
    4343  mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
    4444  // load dudv map
    45   mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
     45   mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
    4646  // set up depth texture
    47   mat.setDiffuseMap("pictures/sky-replace.jpg", 4);
     47//  mat.setDiffuseMap("pictures/sky-replace.jpg", 4);
    4848
    4949  // set the size of the refraction and reflection textures
     
    5858  unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
    5959  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));
     60//  unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
     61//  memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    6262  // Register the texture with OpenGL and bind it to the texture ID
    6363  mat.select();
     
    7070
    7171  //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);
     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);
    7474
    7575  // Set the texture quality
     
    8181  // Since we stored the texture space with OpenGL, we can delete the image data
    8282  delete [] pTextureReflection;
    83   delete [] pTextureRefraction;
     83//  delete [] pTextureRefraction;
    8484
    8585
     
    9191  this->kNormalMapScale = 0.25f;
    9292  this->g_WaterFlow = 0.0015f;
     93
     94  /// Initialization of the shaders
     95  this->shader->activateShader();
     96  // Set the variable "reflection" to correspond to the first texture unit
     97  Shader::Uniform(shader, "reflection").set(0);
     98
     99  // 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
     103  // Set the variable "normalMap" to correspond to the third texture unit
     104  Shader::Uniform(shader, "normalMap").set(2);
     105
     106  // Set the variable "dudvMap" to correspond to the fourth texture unit
     107  Shader::Uniform(shader, "dudvMap").set(3);
     108
     109  // 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();
    93113}
    94114
     
    111131  glTranslatef(0,this->waterHeight,0);
    112132
    113   //HACK
    114  
    115   //glEnable(GL_LIGHTING);
    116 
    117 
    118   //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
    119   //mat.setTransparency(1.0);
    120   //mat.setDiffuse(1.0, 0, .1);
    121 
    122 
    123   // HACK
    124 
    125   //glActiveTexture(GL_TEXTURE0);
    126   //glBindTexture(GL_TEXTURE_2D, this->texture);
    127133  mat.unselect();
    128134  mat.select();
    129   //glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
     135
    130136
    131137
     
    133139  this->shader->activateShader();
    134140  GLint uniform;
    135   Shader::Uniform* uni;
    136 
    137   // Set the variable "reflection" to correspond to the first texture unit
    138   uni = new Shader::Uniform (shader, "reflection");
    139   uni->set(0);
    140   //uniform = glGetUniformLocationARB(shader->getProgram(), "reflection");
    141   //glUniform1iARB(uniform, 0); //second paramter is the texture unit
    142 
    143   // Set the variable "refraction" to correspond to the second texture unit
    144  // uni = new Shader::Uniform (shader, "refraction");
    145  // uni->set(1);
    146   //uniform = glGetUniformLocationARB(shader->getProgram(), "refraction");
    147   //glUniform1iARB(uniform, 1);
    148 
    149   // Set the variable "normalMap" to correspond to the third texture unit
    150   uni = new Shader::Uniform (shader, "normalMap");
    151   uni->set(2);
    152   //uniform = glGetUniformLocationARB(shader->getProgram(), "normalMap");
    153   //glUniform1iARB(uniform, 2);
    154 
    155   // Set the variable "dudvMap" to correspond to the fourth texture unit
    156   uni = new Shader::Uniform (shader, "dudvMap");
    157   uni->set(3);
    158   //uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");
    159   //glUniform1iARB(uniform, 3);
    160 
    161   // Set the variable "depthMap" to correspond to the fifth texture unit
    162  // uni = new Shader::Uniform (shader, "depthMap");
    163  // uni->set(4);
    164   //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");
    165   //glUniform1iARB(uniform, 4);
    166   // FIXME we dont have a depthMap yet :-(
     141
     142
     143
     144
    167145
    168146  // Give the variable "waterColor" a blue color
     
    192170  glBegin(GL_QUADS);
    193171  // The back left vertice for the water
    194   glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, g_WaterUV);            // Reflection texture
    195   glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, refrUV - move);        // Refraction texture
    196   glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, normalUV + move2);     // Normal map texture
    197   glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                       // DUDV map texture
    198   glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                       // Depth texture
     172  glMultiTexCoord2f(GL_TEXTURE0, 0.0f, g_WaterUV);            // Reflection texture
     173  glMultiTexCoord2f(GL_TEXTURE1, 0.0f, refrUV - move);        // Refraction texture
     174  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2);     // Normal map texture
     175  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
     176  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                       // Depth texture
    199177  glVertex3f(0.0f, waterHeight, 0.0f);
    200178
    201179  // The front left vertice for the water
    202   glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);                  // Reflection texture
    203   glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f - move);           // Refraction texture
    204   glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 0.0f + move2);          // Normal map texture
    205   glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                        // DUDV map texture
    206   glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                        // Depth texture
     180  glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);                  // Reflection texture
     181  glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f - move);           // Refraction texture
     182  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2);          // Normal map texture
     183  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
     184  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    207185  glVertex3f(0.0f, waterHeight, 1000.0f);
    208186
    209187  // The front right vertice for the water
    210   glMultiTexCoord2fARB(GL_TEXTURE0_ARB, g_WaterUV, 0.0f);             // Reflection texture
    211   glMultiTexCoord2fARB(GL_TEXTURE1_ARB, refrUV, 0.0f - move);         // Refraction texture
    212   glMultiTexCoord2fARB(GL_TEXTURE2_ARB, normalUV, 0.0f + move2);      // Normal map texture
    213   glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                        // DUDV map texture
    214   glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                        // Depth texture
     188  glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, 0.0f);             // Reflection texture
     189  glMultiTexCoord2f(GL_TEXTURE1, refrUV, 0.0f - move);         // Refraction texture
     190  glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2);      // Normal map texture
     191  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
     192  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    215193  glVertex3f(1000.0f, waterHeight, 1000.0f);
    216194
    217195  // The back right vertice for the water
    218   glMultiTexCoord2fARB(GL_TEXTURE0_ARB, g_WaterUV, g_WaterUV);        // Reflection texture
    219   glMultiTexCoord2fARB(GL_TEXTURE1_ARB, refrUV, refrUV - move);       // Refraction texture
    220   glMultiTexCoord2fARB(GL_TEXTURE2_ARB, normalUV, normalUV + move2);  // Normal map texture
    221   glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                        // DUDV map texture
    222   glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                        // Depth texture
     196  glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, g_WaterUV);        // Reflection texture
     197  glMultiTexCoord2f(GL_TEXTURE1, refrUV, refrUV - move);       // Refraction texture
     198  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
     199  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
     200  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    223201  glVertex3f(1000.0f, waterHeight, 0.0f);
    224202  glEnd();
     
    226204  this->shader->deactivateShader();
    227205
    228 
    229   Material::unselect();
     206  mat.unselect();
    230207
    231208  glPopMatrix();
     
    234211void MappedWater::tick(float dt)
    235212{
    236   this->move += this->g_WaterFlow = 0.004;
     213  // makes the water flow
     214  this->move += this->g_WaterFlow;
    237215  this->move2 = this->move * this->kNormalMapScale;
    238216  this->refrUV = this->g_WaterUV;
     
    248226{
    249227  glPushAttrib(GL_VIEWPORT_BIT);
    250  
     228
    251229
    252230  //glLoadIdentity();
     
    269247
    270248  // Since the world is updside down we need to change the culling to FRONT
    271   glCullFace(GL_FRONT);
     249  //glCullFace(GL_FRONT);
    272250
    273251  // Set our plane equation and turn clipping on
    274   double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     252  //double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
    275253  //glEnable(GL_CLIP_PLANE0);
    276254  //glClipPlane(GL_CLIP_PLANE0, plane);
     
    306284
    307285  //mat.setDiffuseMap(&texture, 0);
     286
    308287  mat.select();
    309288  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
  • branches/water/src/world_entities/environments/mapped_water.h

    r7982 r7983  
    1010#include "world_entity.h"
    1111#include "material.h"
    12 #include "texture.h"
    1312#include "shader.h"
    1413
     
    3433
    3534  private:
    36     float           waterHeight;                //!< y-coord of the Water
    37     Material        mat;
    38     float           move;
    39     float           g_WaterUV;          //!< The scale for the water textures
    40     float           kNormalMapScale;
    41     float           g_WaterFlow;
    42     float           move2;
    43     float           refrUV;
    44     float           normalUV;
     35    float               waterHeight;                //!< y-coord of the Water
    4536
    46     int             textureSize;                //!< size of the texture
    47     Shader*         shader;
     37    float               move;                       //!< textures coords, speeds, positions for the shaded textures....
     38    float               move2;                      //!<
     39    float               g_WaterUV;                  //!<
     40    float               g_WaterFlow;                //!<
     41    float               refrUV;                     //!<
     42    float               normalUV;                   //!<
     43    float               kNormalMapScale;            //!<
     44
     45    int                 textureSize;                //!< size of the texture
     46    Material            mat;
     47    Shader*             shader;
     48    Shader::Uniform*    uni;
    4849
    4950};
Note: See TracChangeset for help on using the changeset viewer.