Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2006, 5:05:45 PM (19 years ago)
Author:
stefalie
Message:

branches/water: first attempt to realise reflection

File:
1 edited

Legend:

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

    r7687 r7700  
    2424
    2525MappedWater::MappedWater(const TiXmlElement* root)
     26 : texture(GL_TEXTURE_2D)
    2627{
    2728  this->setClassID(CL_MAPPED_WATER, "MappedWater");
     
    3031  if (root != NULL)
    3132    this->loadParams(root);
     33   
     34    mat.setDiffuseMap(&this->texture, 0);
    3235}
    3336
     
    5861  //glEnable(GL_LIGHTING);
    5962
    60   Material mat;
    61   mat.setDiffuseMap("pictures/ground.tga", GL_TEXTURE_2D, 0);
     63 
    6264  //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
    6365  //mat.setTransparency(1.0);
    6466  //mat.setDiffuse(1.0, 0, .1);
     67 
     68 
     69  // HACK
     70
     71  //glDisable(GL_BLEND);
     72  //glActiveTexture(GL_TEXTURE0);
     73  //glBindTexture(GL_TEXTURE_2D, this->texture);
     74
    6575  mat.select();
    6676
     
    94104}
    95105
    96 void MappedWater::activateReflection() {}
    97 void MappedWater::deactivateReflection() {}
     106void MappedWater::activateReflection()
     107{
     108  // Change the view port to be the size of the texture we will render to
     109  // HACK
     110  int textureSize = 512;
     111  glPushAttrib(GL_VIEWPORT_BIT);
     112  glViewport(0,0, textureSize, textureSize);
    98113
    99 void MappedWater::activateRefraction() {}
    100 void MappedWater::deactivateRefraction() {}
     114  // Clear the color and depth bits, reset the matrix and position our camera.
     115//  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     116//  glLoadIdentity();
     117  //g_Camera.Look();
     118
     119  // So we don't affect any other objects in the world we push on a new matrix
     120  //glPushMatrix();
     121
     122  // If our camera is above the water we will render the scene flipped upside down.
     123  // In order to line up the reflection nicely with the world we have to translate
     124  // the world to the position of our reflected surface, multiplied by two.
     125  //if(g_Camera.Position().y > waterHeight)
     126  //{
     127      // Translate the world, then flip it upside down
     128   //   glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
     129    //  glScalef(1.0, -1.0, 1.0);
     130
     131      // Since the world is updside down we need to change the culling to FRONT
     132      //glCullFace(GL_FRONT);
     133
     134      // Set our plane equation and turn clipping on
     135     // double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     136   //   glEnable(GL_CLIP_PLANE0);
     137     // glClipPlane(GL_CLIP_PLANE0, plane);
     138
     139      // Render the world upside down and clipped (only render the top flipped).
     140      // If we don't turn OFF caustics for the reflection texture we get horrible
     141      // artifacts in the water.  That is why we set bRenderCaustics to FALSE.
     142      //RenderWorld(false);
     143
     144      // Turn clipping off
     145     // glDisable(GL_CLIP_PLANE0);
     146
     147      // Restore back-face culling
     148    //  glCullFace(GL_BACK);
     149  //}
     150  /*else
     151  {
     152      // If the camera is below the water we don't want to flip the world,
     153      // but just render it clipped so only the top is drawn.
     154      double plane[4] = {0.0, 1.0, 0.0, waterHeight};
     155      glEnable(GL_CLIP_PLANE0);
     156      glClipPlane(GL_CLIP_PLANE0, plane);
     157      RenderWorld(true);
     158      glDisable(GL_CLIP_PLANE0);
     159  }*/
     160
     161  // Restore the previous matrix
     162  //glPopMatrix();
     163
     164    // Bind the current scene to our reflection texture
     165  //glBindTexture(GL_TEXTURE_2D, g_Texture[REFLECTION_ID]);
     166 
     167 
     168 
     169 glBindTexture(GL_TEXTURE_2D, texture.getTexture());
     170 // ;
     171 // mat.setDiffuseMap(&texture, 0);
     172 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     173 
     174  glPopAttrib();
     175}
     176
     177void MappedWater::deactivateReflection()
     178{
     179
     180}
     181
     182void MappedWater::activateRefraction()
     183{
     184
     185}
     186
     187void MappedWater::deactivateRefraction()
     188{
     189
     190}
Note: See TracChangeset for help on using the changeset viewer.