Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7823 in orxonox.OLD for branches/water


Ignore:
Timestamp:
May 24, 2006, 6:10:25 PM (18 years ago)
Author:
stefalie
Message:

branches/water: the texture mooooves

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

Legend:

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

    r7817 r7823  
    1818#include "util/loading/factory.h"
    1919#include "util/loading/resource_manager.h"
     20#include "state.h"
    2021
    2122
     
    3839  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0);
    3940  // load refraction texture
    40   //mat.setDiffuseMap(&this->refractionTexture, 1);
     41  mat.setDiffuseMap("pictures/sky-replace.jpg", 1);
    4142  // load normal map
    42   //mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
     43  mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
    4344  // load dudv map
    44   //mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
     45  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
    4546  // set up depth texture
    46   //mat.setDiffuseMap(&this->depthTexture, 4);
     47  mat.setDiffuseMap("pictures/sky-replace.jpg", 4);
    4748
    4849  // set the size of the refraction and reflection textures
     
    5556  unsigned int channels = 32;
    5657  GLenum type = GL_RGBA;
    57   unsigned int* pTexture = new unsigned int [this->textureSize * this->textureSize * channels];
    58   memset(pTexture, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
     58  unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
     59  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));
    5962  // Register the texture with OpenGL and bind it to the texture ID
    6063  mat.select();
     
    6265
    6366  // Create the texture and store it on the video card
    64   glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTexture);
     67  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
    6568
    6669  //gluBuild2DMipmaps(GL_TEXTURE_2D, channels, this->textureSize, this->textureSize, type,  GL_UNSIGNED_INT, pTexture);
     70
     71  //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);
    6774
    6875  // Set the texture quality
     
    7380
    7481  // Since we stored the texture space with OpenGL, we can delete the image data
    75   delete [] pTexture;
     82  delete [] pTextureReflection;
     83  delete [] pTextureRefraction;
    7684
    7785
    7886  //shader = new Shader( "/home/stefalie/svn/orxonox/data/trunk/shaders/water.vert", "/home/stefalie/svn/orxonox/data/trunk/shaders/mapped_water.frag");
    7987  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
     88
     89  this->move = 0.0f;
     90  this->g_WaterUV = 35.0f;
     91  this->kNormalMapScale = 0.25f;
     92  this->g_WaterFlow = 0.0015f;
    8093}
    8194
     
    119132
    120133  // Shader init
    121   //this->shader->activateShader();
    122   //GLint uniform;
     134  this->shader->activateShader();
     135  GLint uniform;
    123136
    124137  // Set the variable "reflection" to correspond to the first texture unit
    125   //uniform = glGetUniformLocationARB(shader->getProgram(), "reflection");
    126   //glUniform1iARB(uniform, 0); //second paramter is the texture unit
     138  uniform = glGetUniformLocationARB(shader->getProgram(), "reflection");
     139  glUniform1iARB(uniform, 0); //second paramter is the texture unit
    127140
    128141  // Set the variable "refraction" to correspond to the second texture unit
    129   //uniform = glGetUniformLocationARB(shader->getProgram(), "refraction");
    130   //glUniform1iARB(uniform, 0);
    131   // FIXME glUniform1iARB(uniform, 1);
     142  uniform = glGetUniformLocationARB(shader->getProgram(), "refraction");
     143  glUniform1iARB(uniform, 1);
    132144
    133145  // Set the variable "normalMap" to correspond to the third texture unit
    134   //uniform = glGetUniformLocationARB(shader->getProgram(), "normalMap");
    135   //glUniform1iARB(uniform, 2);
     146  uniform = glGetUniformLocationARB(shader->getProgram(), "normalMap");
     147  glUniform1iARB(uniform, 2);
    136148
    137149  // Set the variable "dudvMap" to correspond to the fourth texture unit
    138   //uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");
    139   //glUniform1iARB(uniform, 3);
     150  uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");
     151  glUniform1iARB(uniform, 3);
    140152
    141153  // Set the variable "depthMap" to correspond to the fifth texture unit
    142   //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");
    143   //glUniform1iARB(uniform, 4);
     154  uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");
     155  glUniform1iARB(uniform, 4);
    144156  // FIXME we dont have a depthMap yet :-(
    145157
    146158  // Give the variable "waterColor" a blue color
    147   //uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");
    148   //glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);
     159  uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");
     160  glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);
    149161
    150162  // FIXME set camera and light information
    151   Vector lightPos(100.0f, 150.0f, 100.0f);
    152 
     163  Vector lightPos(100.0f, 600.0f, 100.0f);
     164  Vector vPosition = State::getCameraNode()->getAbsCoor();
    153165  // Store the camera position in a variable
    154166  //CVector3 vPosition = g_Camera.Position();
     
    156168
    157169  // 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);
     170  uniform = glGetUniformLocationARB(shader->getProgram(), "lightPos");
     171  glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f);
    160172
    161173  // Give the variable "cameraPos" our camera position
    162   //uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos");
    163   //glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f);
     174  uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos");
     175  glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f);
     176
     177
     178
     179  float move2 = this->move * this->kNormalMapScale;
     180  float refrUV = this->g_WaterUV;
     181  float normalUV = this->g_WaterUV * this->kNormalMapScale;
     182
    164183
    165184  glBegin(GL_QUADS);
    166   glNormal3f(0, 1, 0);
    167   glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
    168   glMultiTexCoord2f(GL_TEXTURE1, 0, 0);
    169   glMultiTexCoord2f(GL_TEXTURE2, 0, 0);
    170   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);
    171   glMultiTexCoord2f(GL_TEXTURE4, 0, 0);
    172   glVertex3f(0, 0, 0);
    173 
    174   glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
    175   glMultiTexCoord2f(GL_TEXTURE1, 1, 0);
    176   glMultiTexCoord2f(GL_TEXTURE2, 1, 0);
    177   glMultiTexCoord2f(GL_TEXTURE3, 1, 0);
    178   glMultiTexCoord2f(GL_TEXTURE4, 1, 0);
    179   glVertex3f(0, 0, 1000);
    180 
    181   glMultiTexCoord2f(GL_TEXTURE0, 1, 1);
    182   glMultiTexCoord2f(GL_TEXTURE1, 1, 1);
    183   glMultiTexCoord2f(GL_TEXTURE2, 1, 1);
    184   glMultiTexCoord2f(GL_TEXTURE3, 1, 1);
    185   glMultiTexCoord2f(GL_TEXTURE4, 1, 1);
    186   glVertex3f(1000, 0, 1000);
    187 
    188   glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
    189   glMultiTexCoord2f(GL_TEXTURE1, 0, 1);
    190   glMultiTexCoord2f(GL_TEXTURE2, 0, 1);
    191   glMultiTexCoord2f(GL_TEXTURE3, 0, 1);
    192   glMultiTexCoord2f(GL_TEXTURE4, 0, 1);
    193   glVertex3f(1000, 0, 0);
     185  // The back left vertice for the water
     186  glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, g_WaterUV);            // Reflection texture
     187  glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, refrUV - move);        // Refraction texture
     188  glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, normalUV + move2);     // Normal map texture
     189  glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                       // DUDV map texture
     190  glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                       // Depth texture
     191  glVertex3f(0.0f, waterHeight, 0.0f);
     192
     193  // The front left vertice for the water
     194  glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);                  // Reflection texture
     195  glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f - move);           // Refraction texture
     196  glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0f, 0.0f + move2);          // Normal map texture
     197  glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                        // DUDV map texture
     198  glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                        // Depth texture
     199  glVertex3f(0.0f, waterHeight, 1000.0f);
     200
     201  // The front right vertice for the water
     202  glMultiTexCoord2fARB(GL_TEXTURE0_ARB, g_WaterUV, 0.0f);             // Reflection texture
     203  glMultiTexCoord2fARB(GL_TEXTURE1_ARB, refrUV, 0.0f - move);         // Refraction texture
     204  glMultiTexCoord2fARB(GL_TEXTURE2_ARB, normalUV, 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
     207  glVertex3f(1000.0f, waterHeight, 1000.0f);
     208
     209  // The back right vertice for the water
     210  glMultiTexCoord2fARB(GL_TEXTURE0_ARB, g_WaterUV, g_WaterUV);        // Reflection texture
     211  glMultiTexCoord2fARB(GL_TEXTURE1_ARB, refrUV, refrUV - move);       // Refraction texture
     212  glMultiTexCoord2fARB(GL_TEXTURE2_ARB, normalUV, normalUV + move2);  // Normal map texture
     213  glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);                        // DUDV map texture
     214  glMultiTexCoord2fARB(GL_TEXTURE4_ARB, 0, 0);                        // Depth texture
     215  glVertex3f(1000.0f, waterHeight, 0.0f);
    194216  glEnd();
    195217
    196218  this->shader->deactivateShader();
    197219
     220
    198221  glPopMatrix();
    199222}
     
    201224void MappedWater::tick(float dt)
    202225{
     226  this->move += this->g_WaterFlow;
    203227}
    204228
  • branches/water/src/world_entities/environments/mapped_water.h

    r7816 r7823  
    3434
    3535  private:
    36     float           waterHeight;       //!< y-coord of the Water
     36    float           waterHeight;                //!< y-coord of the Water
    3737    Material        mat;
     38    float           move;
     39    float           g_WaterUV;          //!< The scale for the water textures
     40    float           kNormalMapScale;
     41    float           g_WaterFlow;
    3842
    39     int             textureSize;       //!< size of the texture
     43    int             textureSize;                //!< size of the texture
    4044    Shader*         shader;
    4145
Note: See TracChangeset for help on using the changeset viewer.