Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8312 in orxonox.OLD


Ignore:
Timestamp:
Jun 11, 2006, 12:49:25 PM (18 years ago)
Author:
bensch
Message:

trunk: merged the water-branche back here
removed the HACK in GameWorld in the Process (hope it is not needed anymore…

merged with command:
svn merge https://svn.orxonox.net/orxonoanches/water/src/lib/gui/gl_gui src/lib/gui/gl/ -r8063:HEAD

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/material.cc

    r8037 r8312  
    103103 * @brief sets the material with which the following Faces will be painted
    104104 */
    105 bool Material::select() const
     105  bool Material::select() const
    106106{
    107107  if (unlikely(this == Material::selectedMaterial))
     
    397397  assert(textureNumber < this->textures.size());
    398398
    399   glActiveTexture(0);
     399  // HACK
     400  glActiveTexture(textureNumber);
    400401   glEnable(GL_TEXTURE_2D);
    401402   glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
  • trunk/src/lib/graphics/importer/texture.cc

    r8293 r8312  
    151151
    152152
    153 Texture::Texture(GLenum target)
     153Texture::Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type)
    154154{
    155155  this->init();
    156   GLuint texture;
     156  GLuint texture = 0;
    157157  Texture::generateTexture(texture, target);
     158
     159  glBindTexture(target, texture);
     160
     161  unsigned int* pixels = new unsigned int[width * height * channels];
     162  memset(pixels, 0, width * height * channels * sizeof(unsigned int));
     163 
     164 
     165  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     166  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     167  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     168  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     169
     170  glTexImage2D(target, 0, channels, width, height, 0, type, GL_UNSIGNED_INT, pixels);
     171 
     172 
     173 
     174  delete[] pixels;
     175
    158176  this->data->setTexture(texture);
    159177}
     
    374392  //  printf("%s, w:%d h:%d, 0x%x\n", this->getName(), surface->w, surface->h, target);
    375393
     394  /* control the mipmap levels */
     395  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
     396  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
     397
    376398  // build the MipMaps automaticaly
    377399  errorCode = gluBuild2DMipmaps(target, format,
     
    400422  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    401423
    402   /* control the mipmap levels */
    403   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
    404   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
    405 }
     424}
  • trunk/src/lib/graphics/importer/texture.h

    r8145 r8312  
    5050  Texture();
    5151  Texture(const Texture& texture);
    52   Texture(GLenum target);
     52  Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type);
    5353  Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
    5454  Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
  • trunk/src/lib/gui/gl/glgui_cursor.cc

    r8309 r8312  
    3333    this->init();
    3434
    35     this->subscribeEvent(ES_MENU,  EV_MOUSE_MOTION);
    36     this->subscribeEvent(ES_MENU, EV_WINDOW_FOCUS);
     35    this->subscribeEvent(ES_ALL,  EV_MOUSE_MOTION);
     36    this->subscribeEvent(ES_ALL, EV_WINDOW_FOCUS);
    3737
    3838
  • trunk/src/lib/gui/gl/glgui_handler.cc

    r8145 r8312  
    4040
    4141
    42     EventHandler::getInstance()->withUNICODE(ES_MENU, true );
     42    EventHandler::getInstance()->withUNICODE(ES_ALL, true );
    4343
    4444    this->cursor = NULL;
    4545    for (unsigned int i = 0; i < EV_NUMBER; i++)
    4646    {
    47       this->subscribeEvent(ES_MENU, i);
     47      this->subscribeEvent(ES_ALL, i);
    4848    }
    4949  }
  • trunk/src/lib/gui/gl/glgui_widget.cc

    r8145 r8312  
    234234
    235235
     236
    236237  void GLGuiWidget::hide()
    237238  {
  • trunk/src/lib/gui/gl/glgui_widget.h

    r8148 r8312  
    5353    void show();
    5454    void hide();
    55 
    5655
    5756    void setParentWidget(GLGuiWidget* parent);
  • trunk/src/story_entities/game_world.cc

    r8271 r8312  
    407407    if( likely(this->dataTank->gameRule != NULL))
    408408      this->dataTank->gameRule->tick(this->dtS);
     409     
    409410  }
    410411}
     
    514515      mw =  dynamic_cast<MappedWater*>(*it);
    515516
    516       // prepare for reflection rendering
    517       mw->activateReflection();
    518 
    519517      //camera and light
    520518      this->dataTank->localCamera->apply ();
    521519      this->dataTank->localCamera->project ();
     520
     521      LightManager::getInstance()->draw();
     522
     523
     524      // prepare for reflection rendering
     525      mw->activateReflection();
     526
     527      // draw everything to be included in the reflection
     528      this->drawEntityList(State::getObjectManager()->getReflectionList());
     529//       for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i)
     530//         this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
     531
     532      // clean up from reflection rendering
     533      mw->deactivateReflection();
     534    }
     535  }
     536
     537}
     538
     539
     540/**
     541 *  refraction rendering for water surfaces
     542 */
     543void GameWorld::renderPassRefraction()
     544{
     545    // clear buffer
     546  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     547  glLoadIdentity();
     548
     549  const std::list<BaseObject*>* reflectedWaters;
     550  MappedWater* mw;
     551
     552  if( (reflectedWaters = ClassList::getList(CL_MAPPED_WATER)) != NULL)
     553  {
     554    std::list<BaseObject*>::const_iterator it;
     555    for (it = reflectedWaters->begin(); it != reflectedWaters->end(); it++)
     556    {
     557      mw =  dynamic_cast<MappedWater*>(*it);
     558
     559      //camera and light
     560      this->dataTank->localCamera->apply ();
     561      this->dataTank->localCamera->project ();
     562      // prepare for reflection rendering
     563      mw->activateRefraction();
     564
     565
    522566      LightManager::getInstance()->draw();
    523567      // draw everything to be included in the reflection
     
    527571
    528572      // clean up from reflection rendering
    529       mw->deactivateReflection();
    530     }
    531   }
    532 
    533 }
    534 
    535 
    536 /**
    537  *  refraction rendering for water surfaces
    538  */
    539 void GameWorld::renderPassRefraction()
    540 {
    541 
    542     // clear buffer
    543   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    544   glLoadIdentity();
    545 
    546   const std::list<BaseObject*>* reflectedWaters;
    547   MappedWater* mw;
    548 
    549   if( (reflectedWaters = ClassList::getList(CL_MAPPED_WATER)) != NULL)
    550   {
    551     std::list<BaseObject*>::const_iterator it;
    552     for (it = reflectedWaters->begin(); it != reflectedWaters->end(); it++)
    553     {
    554       mw =  dynamic_cast<MappedWater*>(*it);
    555 
    556       // prepare for reflection rendering
    557       mw->activateRefraction();
    558 
    559       //camera and light
    560       this->dataTank->localCamera->apply ();
    561       this->dataTank->localCamera->project ();
    562       LightManager::getInstance()->draw();
    563       // draw everything to be included in the reflection
    564       this->drawEntityList(State::getObjectManager()->getReflectionList());
    565 //       for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i)
    566 //         this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
    567 
    568       // clean up from reflection rendering
    569573      mw->deactivateRefraction();
    570574    }
     
    583587
    584588
    585   //glEnable(GL_DEPTH_TEST);
    586   //glEnable(GL_LIGHTING);
     589  glEnable(GL_DEPTH_TEST);
     590  glEnable(GL_LIGHTING);
    587591
    588592  // set camera
  • trunk/src/world_entities/environments/mapped_water.cc

    r8037 r8312  
    4040  // set up refleciton texture
    4141  //mat.setDiffuseMap(this->texture, 0);
    42   mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0);
     42  mat.setDiffuseMap("pictures/refl.bmp", GL_TEXTURE_2D, 0);
    4343  // load refraction texture
    44   mat.setDiffuseMap("pictures/error_texture.png", GL_TEXTURE_2D, 1);
     44  mat.setDiffuseMap("pictures/refr.bmp", GL_TEXTURE_2D, 1);
    4545  // load normal map
    46   //mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
     46  mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
    4747  // load dudv map
    48   //mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
     48  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
    4949  // set up depth texture
    5050  //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);
     
    5656  // set the size of the refraction and reflection textures
    5757  this->textureSize = 512;
     58  //unsigned int channels = 32;
     59  //GLenum type = GL_RGBA;
     60  //unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
     61  //memset(pTextureReflection, 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));
     64  // Register the texture with OpenGL and bind it to the texture ID
     65  //mat.select();
     66  //glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
     67
     68  // Create the texture and store it on the video card
     69  //glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
     70
     71  //gluBuild2DMipmaps(GL_TEXTURE_2D, channels, this->textureSize, this->textureSize, type,  GL_UNSIGNED_INT, pTexture);
     72
     73  //the same for the refraction
     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);
     76
    5877  unsigned int channels = 32;
    5978  GLenum type = GL_RGBA;
    6079  unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
    6180  memset(pTextureReflection, 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));
    64   // Register the texture with OpenGL and bind it to the texture ID
    65   mat.select();
     81  //mat.select();
    6682  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    67 
    68   // Create the texture and store it on the video card
    69   glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
    70 
    71   //gluBuild2DMipmaps(GL_TEXTURE_2D, channels, this->textureSize, this->textureSize, type,  GL_UNSIGNED_INT, pTexture);
    72 
    73   //the same for the refraction
    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);
    76 
    77   // Set the texture quality
    7883  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    7984  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    8085  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    8186  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     87  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
     88
     89
     90  unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
     91  memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
     92  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
     93  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     94  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     95  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     96  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
    82101
    83102  // Since we stored the texture space with OpenGL, we can delete the image data
    84   delete [] pTextureReflection;
    85   delete [] pTextureRefraction;
     103  //delete [] pTextureReflection;
     104  //delete [] pTextureRefraction;
    86105
    87106
     
    94113  /// initialization of the shaders
    95114  // load shader files
    96 /*  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
     115  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
    97116
    98117  this->shader->activateShader();
     
    106125  Shader::Uniform(shader, "dudvMap").set(3);
    107126  // Set the variable "depthMap" to correspond to the fifth texture unit
    108   Shader::Uniform(shader, "depthMap").set(4);
     127  Shader::Uniform(shader, "depthMap").set(2);
    109128  // Give the variable "waterColor" a blue color
    110129  Shader::Uniform(shader, "waterColor").set(0.1f, 0.2f, 0.4f, 1.0f);
     
    114133  cam_uni = new Shader::Uniform(shader, "cameraPos");
    115134
    116   this->shader->deactivateShader();*/
     135  this->shader->deactivateShader();
    117136}
    118137
     
    134153void MappedWater::draw() const
    135154{
     155  glMatrixMode(GL_MODELVIEW);
     156
    136157  glPushMatrix();
    137158  glTranslatef(0,this->waterHeight,0);
     
    140161  mat.select();
    141162
    142   ///this->shader->activateShader();
     163  this->shader->activateShader();
    143164
    144165  // reset the camera uniform to the current cam position
    145166  Vector pos = State::getCameraNode()->getAbsCoor();
    146   ///cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
     167  cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
     168
     169  //glDisable(GL_BLEND);
    147170
    148171  glBegin(GL_QUADS);
    149172  // The back left vertice for the water
    150   glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0);//g_WaterUV);            // Reflection texture
    151   glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0);//refrUV - move);        // Refraction texture
     173 // glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0);//g_WaterUV);            // Reflection texture
     174 // glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0);//refrUV - move);        // Refraction texture
     175  glMultiTexCoord2f(GL_TEXTURE0, 0.0f, g_WaterUV);            // Reflection texture
     176  glMultiTexCoord2f(GL_TEXTURE1, 0.0f, refrUV - move);        // Refraction texture
    152177  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2);     // Normal map texture
    153178  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
    154   glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                       // Depth texture
     179  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                       // Depth texture
    155180  glVertex3f(0.0f, waterHeight, 0.0f);
    156181
    157182  // The front left vertice for the water
    158   glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1);//0.0f);                  // Reflection texture
    159   glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1);//0.0f - move);           // Refraction texture
     183 // glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1);//0.0f);                  // Reflection texture
     184 // glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1);//0.0f - move);           // Refraction texture
     185  glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);                  // Reflection texture
     186  glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f - move);           // Refraction texture
    160187  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2);          // Normal map texture
    161188  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    162   glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
     189  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    163190  glVertex3f(0.0f, waterHeight, 1000.0f);
    164191
    165192  // The front right vertice for the water
    166   glMultiTexCoord2f(GL_TEXTURE0, 1,1); //g_WaterUV, 0.0f);             // Reflection texture
    167   glMultiTexCoord2f(GL_TEXTURE1, 1,1);//refrUV, 0.0f - move);         // Refraction texture
     193//  glMultiTexCoord2f(GL_TEXTURE0, 1,1); //g_WaterUV, 0.0f);             // Reflection texture
     194 // glMultiTexCoord2f(GL_TEXTURE1, 1,1);//refrUV, 0.0f - move);         // Refraction texture
     195  glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, 0.0f);             // Reflection texture
     196  glMultiTexCoord2f(GL_TEXTURE1, refrUV, 0.0f - move);         // Refraction texture
    168197  glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2);      // Normal map texture
    169198  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    170   glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
     199  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    171200  glVertex3f(1000.0f, waterHeight, 1000.0f);
    172201
    173202  // The back right vertice for the water
    174   glMultiTexCoord2f(GL_TEXTURE0, 1,0);//g_WaterUV, g_WaterUV);        // Reflection texture
    175   glMultiTexCoord2f(GL_TEXTURE1, 1,0);//refrUV, refrUV - move);       // Refraction texture
     203 // glMultiTexCoord2f(GL_TEXTURE0, 1,0);//g_WaterUV, g_WaterUV);        // Reflection texture
     204 // glMultiTexCoord2f(GL_TEXTURE1, 1,0);//refrUV, refrUV - move);       // Refraction texture
     205  glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, g_WaterUV);        // Reflection texture
     206  glMultiTexCoord2f(GL_TEXTURE1, refrUV, refrUV - move);       // Refraction texture
    176207  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
    177208  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    178   glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
     209  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    179210  glVertex3f(1000.0f, waterHeight, 0.0f);
    180211  glEnd();
    181212
    182   ///this->shader->deactivateShader();
     213  this->shader->deactivateShader();
    183214
    184215  mat.unselect();
     
    207238  glViewport(0,0, textureSize, textureSize);
    208239
     240  glMatrixMode(GL_MODELVIEW);
    209241  glPushMatrix();
    210242
     
    214246  glEnable(GL_CLIP_PLANE0);
    215247  Vector pos = State::getCameraNode()->getAbsCoor();
     248  //pos.debug();
     249  //PRINTF(0)("waterheight: %f\n", waterHeight);
    216250  if(pos.y > waterHeight)
    217251  {
     
    242276  glCullFace(GL_BACK);
    243277
    244   mat.select();
    245   //glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    246   mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     278  //mat.select();
     279  /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     280  ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     281  ///
     282
     283  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
     284
     285  // Create the texture and store it on the video card
     286  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     287
    247288
    248289  glPopMatrix();
     
    251292
    252293void MappedWater::activateRefraction()
    253 {
     294{/*
     295  // save viewport matrix and change the viewport size
     296  glPushAttrib(GL_VIEWPORT_BIT);
     297  glViewport(0,0, textureSize, textureSize);
     298
     299  glMatrixMode(GL_MODELVIEW);
     300  glPushMatrix();
     301
     302  // If our camera is above the water we will render the scene flipped upside down.
     303  // In order to line up the reflection nicely with the world we have to translate
     304  // the world to the position of our reflected surface, multiplied by two.
     305  glEnable(GL_CLIP_PLANE0);
     306  Vector pos = State::getCameraNode()->getAbsCoor();
     307  //pos.debug();
     308  //PRINTF(0)("waterheight: %f\n", waterHeight);
     309  if(pos.y > waterHeight)
     310  {
     311    // Translate the world, then flip it upside down
     312    glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
     313    glScalef(1.0, -1.0, 1.0);
     314
     315    // Since the world is updside down we need to change the culling to FRONT
     316    glCullFace(GL_FRONT);
     317
     318    // Set our plane equation and turn clipping on
     319    double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     320    glClipPlane(GL_CLIP_PLANE0, plane);
     321  }
     322  else
     323  {
     324    // If the camera is below the water we don't want to flip the world,
     325    // but just render it clipped so only the top is drawn.
     326    double plane[4] = {0.0, 1.0, 0.0, waterHeight};
     327    glClipPlane(GL_CLIP_PLANE0, plane);
     328  }
     329*/
     330
    254331  // To create the refraction and depth textures we do the same thing
    255332  // we did for the reflection texture, except we don't need to turn
     
    261338  glViewport(0,0, textureSize, textureSize);
    262339
     340  glMatrixMode(GL_MODELVIEW);
    263341  glPushMatrix();
    264342
     
    275353    double plane[4] = {0.0, -1.0, 0.0, waterHeight};
    276354    glClipPlane(GL_CLIP_PLANE0, plane);
     355
    277356  }
    278357  // If the camera is below the water, only render the data above the water
     
    290369  glCullFace(GL_BACK);
    291370
    292   mat.select();
    293   mat.renderToTexture(1, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    294   //glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
    295   //mat.renderToTexture(0, GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, textureSize, textureSize, 0);
     371
     372  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
     373
     374  // Create the texture and store it on the video card
     375  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     376
     377  glPopMatrix();
     378  glPopAttrib();
    296379
    297380  // Bind the current scene to our refraction texture
     
    303386//  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
    304387
    305   glPopMatrix();
    306   glPopAttrib();
    307 }
     388}
Note: See TracChangeset for help on using the changeset viewer.