Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2006, 2:59:09 PM (19 years ago)
Author:
stefalie
Message:

water: no culling, no clipping → textures work fine

File:
1 edited

Legend:

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

    r8241 r8249  
    8181  //mat.select();
    8282  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    83   glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
    8483  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    8584  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    8685  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    8786  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    88  
     87  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
     88
     89
    8990  unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
    9091  memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    9192  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
    92 
    93 
    94   // Set the texture quality
    9593  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    9694  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    9795  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    9896  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     97  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction);
     98
     99  // Set the texture quality
     100
    99101
    100102  // Since we stored the texture space with OpenGL, we can delete the image data
     
    238240  // In order to line up the reflection nicely with the world we have to translate
    239241  // the world to the position of our reflected surface, multiplied by two.
    240   glEnable(GL_CLIP_PLANE0);
     242  //glEnable(GL_CLIP_PLANE0);
    241243  Vector pos = State::getCameraNode()->getAbsCoor();
    242244  if(pos.y > waterHeight)
     
    247249
    248250    // Since the world is updside down we need to change the culling to FRONT
    249     glCullFace(GL_FRONT);
     251    //glCullFace(GL_FRONT);
    250252
    251253    // Set our plane equation and turn clipping on
    252254    double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
    253     glClipPlane(GL_CLIP_PLANE0, plane);
     255    //glClipPlane(GL_CLIP_PLANE0, plane);
    254256  }
    255257  else
     
    258260    // but just render it clipped so only the top is drawn.
    259261    double plane[4] = {0.0, 1.0, 0.0, waterHeight};
    260     glClipPlane(GL_CLIP_PLANE0, plane);
     262    //glClipPlane(GL_CLIP_PLANE0, plane);
    261263  }
    262264}
     
    265267void MappedWater::deactivateReflection()
    266268{
    267   glDisable(GL_CLIP_PLANE0);
    268   glCullFace(GL_BACK);
    269 
    270   mat.select();
     269  //glDisable(GL_CLIP_PLANE0);
     270  //glCullFace(GL_BACK);
     271
     272  //mat.select();
    271273  /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    272274  ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    273275  ///
    274276
    275   mat.select();
    276277  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    277278
    278279  // Create the texture and store it on the video card
    279280  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    280  
    281  
    282   ///
     281
     282
    283283  glPopMatrix();
    284284  glPopAttrib();
     
    286286
    287287void MappedWater::activateRefraction()
    288 {
     288{
     289  // save viewport matrix and change the viewport size
     290  glPushAttrib(GL_VIEWPORT_BIT);
     291  glViewport(0,0, textureSize, textureSize);
     292
     293  glMatrixMode(GL_MODELVIEW);
     294  glPushMatrix();
     295
     296  // If our camera is above the water we will render the scene flipped upside down.
     297  // In order to line up the reflection nicely with the world we have to translate
     298  // the world to the position of our reflected surface, multiplied by two.
     299  //glEnable(GL_CLIP_PLANE0);
     300  Vector pos = State::getCameraNode()->getAbsCoor();
     301  if(pos.y > waterHeight)
     302  {
     303    // Translate the world, then flip it upside down
     304    glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
     305    glScalef(1.0, -1.0, 1.0);
     306
     307    // Since the world is updside down we need to change the culling to FRONT
     308    //glCullFace(GL_FRONT);
     309
     310    // Set our plane equation and turn clipping on
     311    double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     312    //glClipPlane(GL_CLIP_PLANE0, plane);
     313  }
     314  else
     315  {
     316    // If the camera is below the water we don't want to flip the world,
     317    // but just render it clipped so only the top is drawn.
     318    double plane[4] = {0.0, 1.0, 0.0, waterHeight};
     319    //glClipPlane(GL_CLIP_PLANE0, plane);
     320  }
     321
     322/*
    289323  // To create the refraction and depth textures we do the same thing
    290324  // we did for the reflection texture, except we don't need to turn
     
    305339
    306340  // If the camera is above water, render the data below the water
    307   glEnable(GL_CLIP_PLANE0);
     341  glEnable(GL_CLIP_PLANE1);
    308342  Vector pos = State::getCameraNode()->getAbsCoor();
    309343  if(pos.y > waterHeight)
     
    311345    double plane[4] = {0.0, -1.0, 0.0, waterHeight};
    312346    glClipPlane(GL_CLIP_PLANE0, plane);
     347
    313348  }
    314349  // If the camera is below the water, only render the data above the water
     
    319354    glClipPlane(GL_CLIP_PLANE0, plane);
    320355  }
     356  PRINTF(0)("test");*/
    321357}
    322358
    323359void MappedWater::deactivateRefraction()
    324360{
    325   glDisable(GL_CLIP_PLANE0);
    326   glCullFace(GL_BACK);
    327 
    328   mat.select();
    329   //mat.renderToTexture(1, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    330   //glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
    331   //mat.renderToTexture(0, GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, textureSize, textureSize, 0);
     361  //glDisable(GL_CLIP_PLANE0);
     362  //glCullFace(GL_BACK);
     363
     364
     365  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
     366
     367  // Create the texture and store it on the video card
     368  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     369
     370  glPopMatrix();
     371  glPopAttrib();
    332372
    333373  // Bind the current scene to our refraction texture
     
    339379//  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
    340380
    341   glPopMatrix();
    342   glPopAttrib();
    343 }
     381}
Note: See TracChangeset for help on using the changeset viewer.