Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8037 in orxonox.OLD


Ignore:
Timestamp:
May 31, 2006, 4:52:34 PM (18 years ago)
Author:
bensch
Message:

trunk: merged the water back
merged with command
svn merge -r7798:HEAD https://svn.orxonox.net/orxonox/branches/water .

conflicts are all resolved

Location:
trunk/src
Files:
13 edited

Legend:

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

    r7922 r8037  
    108108      return true;
    109109
     110/// !!  HACK !!! FIX THIS IN MODEL ///
     111  else if (likely(Material::selectedMaterial != NULL))
     112  {
     113  Material::unselect();
     114//     for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
     115//     {
     116//         glActiveTexture(Material::glTextureArbs[i]);
     117//         glBindTexture(GL_TEXTURE_2D, 0);
     118//         glDisable(GL_TEXTURE_2D);
     119//     }
     120  }
     121
    110122  if (likely(Material::selectedMaterial != NULL))
    111123  {
     
    146158    glShadeModel(GL_SMOOTH);
    147159
    148 
    149160  for(unsigned int i = 0; i < this->textures.size(); ++i)
    150161  {
     
    160171}
    161172
     173void Material::unselect()
     174{
     175  Material::selectedMaterial = NULL;
     176    for(unsigned int i = 0; i < 8; ++i)
     177    {
     178        glActiveTexture(Material::glTextureArbs[i]);
     179        glBindTexture(GL_TEXTURE_2D, 0);
     180        glDisable(GL_TEXTURE_2D);
     181    }
     182}
     183
    162184/**
    163185 *  Sets the Material Illumination Model.
     
    366388}
    367389
     390/**
     391 * @brief renders viewport buffer (?? or another buffer ;-)) to a texture
     392 * @param textureNumber select the texture unit that will be overwritten
     393*/
     394void Material::renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
     395{
     396  assert(textureNumber < Material::getMaxTextureUnits());
     397  assert(textureNumber < this->textures.size());
     398
     399  glActiveTexture(0);
     400   glEnable(GL_TEXTURE_2D);
     401   glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
     402  glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
     403
     404}
    368405
    369406/**
    370407 * @brief Sets the Materials Ambient Map
    371  * @param aMap the Name of the Image to Use
    372    @todo implement this
     408 * @todo implement this
    373409*/
    374410void Material::setAmbientMap(const std::string& aMap, GLenum target)
  • trunk/src/lib/graphics/importer/material.h

    r7919 r8037  
    3030
    3131    bool select () const;
     32    bool activateTextureUnit(unsigned int textureNumber);
     33    static void unselect();
    3234
    3335    void setIllum (int illum);
     
    5557    void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    5658    void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
     59    void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
    5760
    5861    void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
  • trunk/src/lib/graphics/shader.cc

    r7221 r8037  
    2020#include "stdlibincl.h"
    2121#include "compiler.h"
    22 #include <stdio.h>
     22//#include <stdio.h>
     23#include <fstream>
     24
    2325#include "debug.h"
    2426
     
    2628
    2729
    28 #ifndef PARSELINELENGHT
    29 #define PARSELINELENGHT     512       //!< how many chars to read at once
     30#ifndef PARSELINELENGTH
     31#define PARSELINELENGTH     512       //!< how many chars to read at once
    3032#endif
    3133
     
    4042   this->setClassID(CL_SHADER, "Shader");
    4143
    42    this->fragmentShaderFile = "";
    43    this->vertexShaderFile = "";
    4444   this->shaderProgram = 0;
    4545   this->vertexShader = 0;
     
    4848   if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
    4949     {
    50        GLint status = 0;
    51 
    5250       this->shaderProgram = glCreateProgramObjectARB();
    5351
    5452       if (!vertexShaderFile.empty())
    55          this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
     53         this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
    5654       if (!fragmentShaderFile.empty())
    57          this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
    58        glLinkProgramARB(this->shaderProgram);
    59        // link error checking
    60        glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
    61        if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
    62          this->printError(this->shaderProgram);
     55         this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
     56
     57       this->linkShaderProgram();
     58
    6359    }
    6460   else
     
    7874
    7975  // delete what has to be deleted here
    80   this->deleteProgram(SHADER_VERTEX);
    81   this->deleteProgram(SHADER_FRAGMENT);
     76  this->deleteProgram(Shader::Vertex);
     77  this->deleteProgram(Shader::Fragment);
    8278
    8379  if (this->fragmentShader != 0)
     
    116112
    117113
    118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName)
     114bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName)
    119115{
    120116  GLhandleARB shader = 0;
    121117
    122   if (type != SHADER_VERTEX && type != SHADER_FRAGMENT)
     118  if (type != Shader::Vertex && type != Shader::Fragment)
    123119    return false;
    124120  this->deleteProgram(type);
    125121
    126122
    127   std::vector<char*>* program = fileReadArray(fileName);
    128 
    129   if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
     123  std::string program;
     124  if (!readShader(fileName, program))
     125    return false;
     126
     127  if (type == Shader::Vertex && GLEW_ARB_vertex_shader)
    130128  {
    131129    this->vertexShaderFile = fileName;
     
    134132  }
    135133
    136   if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader)
     134  if (type == Shader::Fragment && GLEW_ARB_fragment_shader)
    137135  {
    138136    this->fragmentShaderFile = fileName;
     
    144142  {
    145143    GLint status = 0;
    146     /// FIXME do it back
    147     //    glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL);
     144    const char* prog = program.c_str();
     145
     146    glShaderSourceARB(shader, 1, &prog, NULL);
    148147    glCompileShaderARB(shader);
    149148    // checking on error.
     
    154153      glAttachObjectARB(this->shaderProgram, shader);
    155154  }
    156   for (unsigned int i=0; i< program->size(); i++)
    157     delete[] (*program)[i];
    158   delete program;
    159 }
    160 
    161 char* Shader::fileRead(const std::string& fileName)
    162 {
    163   FILE* fileHandle;
    164   char* content = NULL;
    165 
    166   int count = 0;
    167 
    168   if (fileName.empty())
    169     return NULL;
    170 
    171   fileHandle = fopen(fileName.c_str(), "rt");
    172 
    173   if (fileHandle == NULL)
    174     return NULL;
    175   fseek(fileHandle, 0, SEEK_END);
    176   count = ftell(fileHandle);
    177   rewind(fileHandle);
    178   if (count > 0) {
    179      content = new char[count+1];
    180      count = fread(content, sizeof(char), count, fileHandle);
    181      content[count] = '\0';
    182    }
    183    fclose(fileHandle);
    184  return content;
    185 }
    186 
    187 
    188 std::vector<char*>* Shader::fileReadArray(const std::string& fileName)
    189 {
    190   FILE*    stream;           //< The stream we use to read the file.
    191 
    192   if( (stream = fopen (fileName.c_str(), "rt")) == NULL)
    193   {
    194     PRINTF(1)("Shader could not open %s\n", fileName.c_str());
    195     return NULL;
    196   }
    197   std::vector<char*>* file = new std::vector<char*>;
    198 
    199   char lineBuffer[PARSELINELENGHT];
    200   char* addString;
    201   while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL)
    202   {
    203     addString = new char[strlen(lineBuffer)+1];
    204     strcpy(addString, lineBuffer);
    205     file->push_back(addString);
    206   }
    207   fclose(stream);
    208   return file;
     155}
     156
     157
     158void Shader::linkShaderProgram()
     159{
     160  GLint status = 0;
     161
     162  glLinkProgramARB(this->shaderProgram);
     163       // link error checking
     164  glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
     165  if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
     166    this->printError(this->shaderProgram);
     167}
     168
     169
     170bool Shader::readShader(const std::string& fileName, std::string& output)
     171{
     172  char lineBuffer[PARSELINELENGTH];
     173
     174  std::ifstream shader;
     175  shader.open(fileName.c_str());
     176  if (!shader.is_open())
     177    return false;
     178
     179
     180  while (!shader.eof())
     181  {
     182    shader.getline(lineBuffer, PARSELINELENGTH);
     183    output += lineBuffer;
     184    output += "\n";
     185  }
     186
     187
     188  shader.close();
     189  return true;
    209190}
    210191
     
    228209
    229210
    230 void Shader::deleteProgram(SHADER_TYPE type)
     211void Shader::deleteProgram(Shader::Type type)
    231212{
    232213  GLint status = 0;
    233   if (type == SHADER_VERTEX && this->vertexShader != 0)
     214  if (type == Shader::Vertex && this->vertexShader != 0)
    234215  {
    235216    this->vertexShaderFile = "";
     
    241222    this->vertexShader = 0;
    242223  }
    243   else if (type == SHADER_FRAGMENT && this->fragmentShader != 0)
     224  else if (type == Shader::Fragment && this->fragmentShader != 0)
    244225  {
    245226    this->fragmentShaderFile = "";
  • trunk/src/lib/graphics/shader.h

    r7785 r8037  
    1212
    1313
    14 typedef enum
    15 {
    16   SHADER_NONE       = 0,
    17   SHADER_FRAGMENT   = 1,
    18   SHADER_VERTEX     = 0,
    19 
    20 } SHADER_TYPE;
    21 
    2214// FORWARD DECLARATION
    2315
    2416
     17
    2518//! A class for ...
    26 class Shader : public BaseObject {
     19class Shader : public BaseObject
     20{
     21public:
     22  class Uniform
     23  {
     24  public:
     25    Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }
     26    Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
     27    Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
    2728
    28   public:
     29    void set(float v0) const { glUniform1f(this->uniform, v0); }
     30    void set(float v0, float v1) const { glUniform2f(this->uniform, v0, v1); }
     31    void set(float v0, float v1, float v2) const { glUniform3f(this->uniform, v0, v1, v2); }
     32    void set(float v0, float v1, float v2, float v3) const { glUniform4f(this->uniform, v0, v1, v2, v3); }
     33
     34    void set(int v0) const { glUniform1i(this->uniform, v0); }
     35    void set(int v0, int v1) const { glUniform2i(this->uniform, v0, v1); }
     36    void set(int v0, int v1, int v2) const { glUniform3i(this->uniform, v0, v1, v2); }
     37    void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); }
     38
     39    void setV(unsigned int count, float* vv) const
     40    {
     41      switch (count)
     42      {
     43        case 1:
     44          glUniform1fv(this->uniform, 1, vv);
     45          break;
     46        case 2:
     47          glUniform2fv(this->uniform, 2, vv);
     48          break;
     49        case 3:
     50          glUniform3fv(this->uniform, 3, vv);
     51          break;
     52        case 4:
     53          glUniform4fv(this->uniform, 4, vv);
     54          break;
     55      }
     56    }
     57    void setV(unsigned int count, int* vv) const
     58    {
     59      switch (count)
     60      {
     61        case 1:
     62          glUniform1iv(this->uniform, 1, vv);
     63          break;
     64        case 2:
     65          glUniform2iv(this->uniform, 2, vv);
     66          break;
     67        case 3:
     68          glUniform3iv(this->uniform, 3, vv);
     69          break;
     70        case 4:
     71          glUniform4iv(this->uniform, 4, vv);
     72          break;
     73      }
     74    }
     75    private:
     76    GLint uniform;
     77  };
     78
     79  typedef enum
     80  {
     81    None       = 0,
     82    Fragment   = 1,
     83    Vertex     = 2,
     84
     85    Program    = 4,
     86  }
     87  Type;
     88
     89public:
    2990  Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
    3091  virtual ~Shader();
     
    3293  static bool unload(Shader* shader);
    3394
    34   bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName);
     95
     96  static bool checkShaderAbility();
    3597  void activateShader();
    3698  static void deactivateShader();
    37   void deleteProgram(SHADER_TYPE type);
    3899
    39   char* fileRead(const std::string& fileName);
    40   std::vector<char*>* fileReadArray(const std::string& fileName);
     100  Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
    41101
    42   static bool checkShaderAbility();
     102  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
     103  void deleteProgram(Shader::Type type);
    43104
    44   inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
     105  void linkShaderProgram();
     106
     107
     108  bool readShader(const std::string& fileName, std::string& output);
     109
     110
     111inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
    45112  inline static Shader* getActiveShader() { return Shader::storedShader; };
    46113  inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
    47114  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
    48115
    49   GLhandleARB getProgram() { return this->shaderProgram; }
    50   GLhandleARB getVertexS() { return this->vertexShader; }
    51   GLhandleARB getFragmentS() { return this->fragmentShader; }
    52116
    53   void printError(GLhandleARB program);
     117
     118
     119  GLhandleARB getProgram() const { return this->shaderProgram; }
     120  GLhandleARB getVertexS() const { return this->vertexShader; }
     121  GLhandleARB getFragmentS() const { return this->fragmentShader; }
     122
    54123  void debug() const;
    55124
    56   private:
     125  static void printError(GLhandleARB program);
    57126
    58  private:
    59    std::string            fragmentShaderFile;
    60    std::string            vertexShaderFile;
    61    GLhandleARB            shaderProgram;
    62    GLhandleARB            vertexShader;
    63    GLhandleARB            fragmentShader;
    64127
    65    static Shader*         storedShader;
     128private:
     129  std::string            fragmentShaderFile;
     130  std::string            vertexShaderFile;
     131
     132  GLhandleARB            shaderProgram;
     133
     134  GLhandleARB            vertexShader;
     135  GLhandleARB            fragmentShader;
     136
     137
     138  static Shader*         storedShader;
    66139};
    67140
  • trunk/src/lib/graphics/text_engine/text.cc

    r7919 r8037  
    225225  // setting the Blending effects
    226226  glColor4f(this->color.x, this->color.y, this->color.z, this->blending);
     227
     228
     229  glActiveTexture(GL_TEXTURE0);
     230
    227231  glEnable(GL_BLEND);
    228232  glEnable(GL_TEXTURE_2D);
  • trunk/src/story_entities/game_world.cc

    r7919 r8037  
    496496      LightManager::getInstance()->draw();
    497497      // draw everything to be included in the reflection
    498       for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i)
    499         this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
     498      this->drawEntityList(State::getObjectManager()->getReflectionList());
     499//       for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i)
     500//         this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
    500501
    501502      // clean up from reflection rendering
     
    511512 */
    512513void GameWorld::renderPassRefraction()
    513 {}
     514{
     515
     516    // clear buffer
     517  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     518  glLoadIdentity();
     519
     520  const std::list<BaseObject*>* reflectedWaters;
     521  MappedWater* mw;
     522
     523  if( (reflectedWaters = ClassList::getList(CL_MAPPED_WATER)) != NULL)
     524  {
     525    std::list<BaseObject*>::const_iterator it;
     526    for (it = reflectedWaters->begin(); it != reflectedWaters->end(); it++)
     527    {
     528      mw =  dynamic_cast<MappedWater*>(*it);
     529
     530      // prepare for reflection rendering
     531      mw->activateRefraction();
     532
     533      //camera and light
     534      this->dataTank->localCamera->apply ();
     535      this->dataTank->localCamera->project ();
     536      LightManager::getInstance()->draw();
     537      // draw everything to be included in the reflection
     538      this->drawEntityList(State::getObjectManager()->getReflectionList());
     539//       for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i)
     540//         this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
     541
     542      // clean up from reflection rendering
     543      mw->deactivateRefraction();
     544    }
     545  }
     546}
    514547
    515548
  • trunk/src/util/object_manager.cc

    r7836 r8037  
    6565      delete this->objectLists[i].front();
    6666
    67   // delete reflectin list
    68   while( !this->reflectionList.empty())
    69     delete this->reflectionList.front();
     67  // delete reflection list
     68  this->reflectionList.clear();
    7069}
    7170
  • trunk/src/world_entities/environments/mapped_water.cc

    r7796 r8037  
    1818#include "util/loading/factory.h"
    1919#include "util/loading/resource_manager.h"
     20#include "state.h"
    2021
    2122
     
    2627
    2728MappedWater::MappedWater(const TiXmlElement* root)
    28     : texture(GL_TEXTURE_2D)
    2929{
    3030  this->setClassID(CL_MAPPED_WATER, "MappedWater");
     
    3434    this->loadParams(root);
    3535
    36   //! HACK FIXME HACK FIXME HACK FIXME HACK FIXME
    37   //! todo: rename texture to reflection texture
     36  PRINTF(0)("MaxTextureUnits: %i\n", Material::getMaxTextureUnits());
     37
     38  // TODO rename texture to reflection texture
     39  /// loads the textures
    3840  // set up refleciton texture
    39   //mat.setDiffuseMap(&this->texture, 0);
     41  //mat.setDiffuseMap(this->texture, 0);
    4042  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0);
    41 /*  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
    42   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 2);
    43   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 3);
    44   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);*/
    4543  // load refraction texture
    46   //mat.setDiffuseMap(&this->refractionTexture, 1);
     44  mat.setDiffuseMap("pictures/error_texture.png", GL_TEXTURE_2D, 1);
    4745  // load normal map
    4846  //mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
     
    5048  //mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
    5149  // set up depth texture
    52   //mat.setDiffuseMap(&this->depthTexture, 4);
    53 
     50  //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);
     51
     52
     53
     54  /// MAKE THE MAPPING TEXTURE.
     55  // THIS IS A HACK AND SHOULD BE IN TEXTURE SOMEWHERE
    5456  // set the size of the refraction and reflection textures
    55 
    56 
    57 
    58   /// MAKE THE MAPPING TEXTURE.
    59   // THIS IS A HACK AND SHOULD BE IN TEXTURE SOMEWHERE.
    6057  this->textureSize = 512;
    6158  unsigned int channels = 32;
    6259  GLenum type = GL_RGBA;
    63   unsigned int* pTexture = new unsigned int [this->textureSize * this->textureSize * channels];
    64   memset(pTexture, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
     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));
    6564  // Register the texture with OpenGL and bind it to the texture ID
    6665  mat.select();
    6766  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    68   printf("========= CREATE %d\n", this->texture.getTexture());
    6967
    7068  // Create the texture and store it on the video card
    71   glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTexture);
     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);
    7276
    7377  // Set the texture quality
     
    7882
    7983  // Since we stored the texture space with OpenGL, we can delete the image data
    80   delete [] pTexture;
    81 
    82   //  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
     84  delete [] pTextureReflection;
     85  delete [] pTextureRefraction;
     86
     87
     88  /// initialization of the texture coords, speeds etc...
     89  this->move = 0.0f;
     90  this->g_WaterUV = 35.0f;
     91  this->kNormalMapScale = 0.25f;
     92  this->g_WaterFlow = 0.0015f;
     93
     94  /// initialization of the shaders
     95  // load shader files
     96/*  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
     97
     98  this->shader->activateShader();
     99  // Set the variable "reflection" to correspond to the first texture unit
     100  Shader::Uniform(shader, "reflection").set(0);
     101  // Set the variable "refraction" to correspond to the second texture unit
     102  Shader::Uniform(shader, "refraction").set(1);
     103  // Set the variable "normalMap" to correspond to the third texture unit
     104  Shader::Uniform(shader, "normalMap").set(2);
     105  // Set the variable "dudvMap" to correspond to the fourth texture unit
     106  Shader::Uniform(shader, "dudvMap").set(3);
     107  // Set the variable "depthMap" to correspond to the fifth texture unit
     108  Shader::Uniform(shader, "depthMap").set(4);
     109  // Give the variable "waterColor" a blue color
     110  Shader::Uniform(shader, "waterColor").set(0.1f, 0.2f, 0.4f, 1.0f);
     111  // Give the variable "lightPos" our hard coded light position
     112  Shader::Uniform(shader, "lightPos").set(lightPos.x, lightPos.y, lightPos.z, 1.0f);
     113  // uniform for the camera position
     114  cam_uni = new Shader::Uniform(shader, "cameraPos");
     115
     116  this->shader->deactivateShader();*/
    83117}
    84118
     
    86120{
    87121  //delete shader;
     122  //delete cam_uni;
    88123}
    89124
     
    93128
    94129  LoadParam(root, "waterHeight", this, MappedWater, setHeight);
     130  LoadParam(root, "lightPos", this, MappedWater, setLightPosition);
    95131}
    96132
     
    101137  glTranslatef(0,this->waterHeight,0);
    102138
    103   //glEnable(GL_LIGHTING);
    104 
    105 
    106   //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
    107   //mat.setTransparency(1.0);
    108   //mat.setDiffuse(1.0, 0, .1);
    109 
    110 
    111   // HACK
    112 
    113   //glDisable(GL_BLEND);
    114   //glActiveTexture(GL_TEXTURE0);
    115   //glBindTexture(GL_TEXTURE_2D, this->texture);
    116 
     139  mat.unselect();
    117140  mat.select();
    118   glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    119 
    120   // Shader init
    121   //this->shader->activateShader();
    122   GLint uniform;
    123 
    124   // 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
    127 
    128   // 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);
    132 
    133   // Set the variable "normalMap" to correspond to the third texture unit
    134   //uniform = glGetUniformLocationARB(shader->getProgram(), "normalMap");
    135   //glUniform1iARB(uniform, 2);
    136 
    137   // Set the variable "dudvMap" to correspond to the fourth texture unit
    138   uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");
    139   glUniform1iARB(uniform, 3);
    140 
    141   // Set the variable "depthMap" to correspond to the fifth texture unit
    142   //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");
    143   //glUniform1iARB(uniform, 4);
    144   // FIXME we dont have a depthMap yet :-(
    145 
    146   // Give the variable "waterColor" a blue color
    147   uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");
    148   glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);
    149 
    150   // FIXME set camera and light information
    151   Vector lightPos(100.0f, 150.0f, 100.0f);
    152 
    153   // Store the camera position in a variable
    154   //CVector3 vPosition = g_Camera.Position();
    155   Vector vPosition(50.0f, 50.0f, 50.0f);
    156 
    157   // 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);
    160 
    161   // Give the variable "cameraPos" our camera position
    162   uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos");
    163   glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f);
     141
     142  ///this->shader->activateShader();
     143
     144  // reset the camera uniform to the current cam position
     145  Vector pos = State::getCameraNode()->getAbsCoor();
     146  ///cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
    164147
    165148  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(100,0,0);
    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(100,0,-100);
    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(0,0,-100);
     149  // 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
     152  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2);     // Normal map texture
     153  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
     154  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                       // Depth texture
     155  glVertex3f(0.0f, waterHeight, 0.0f);
     156
     157  // 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
     160  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2);          // Normal map texture
     161  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
     162  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
     163  glVertex3f(0.0f, waterHeight, 1000.0f);
     164
     165  // 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
     168  glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2);      // Normal map texture
     169  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
     170  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
     171  glVertex3f(1000.0f, waterHeight, 1000.0f);
     172
     173  // 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
     176  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
     177  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
     178  glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
     179  glVertex3f(1000.0f, waterHeight, 0.0f);
    194180  glEnd();
    195   //this->shader->deactivateShader();
     181
     182  ///this->shader->deactivateShader();
     183
     184  mat.unselect();
    196185
    197186  glPopMatrix();
     
    200189void MappedWater::tick(float dt)
    201190{
     191  // makes the water flow
     192  this->move += this->g_WaterFlow;
     193  this->move2 = this->move * this->kNormalMapScale;
     194  this->refrUV = this->g_WaterUV;
     195  this->normalUV = this->g_WaterUV * this->kNormalMapScale;
    202196}
    203197
     
    209203void MappedWater::activateReflection()
    210204{
     205  // save viewport matrix and change the viewport size
    211206  glPushAttrib(GL_VIEWPORT_BIT);
    212   //   glPushMatrix();
    213 
    214   //glLoadIdentity();
    215207  glViewport(0,0, textureSize, textureSize);
    216208
    217 
    218   // Clear the color and depth bits, reset the matrix and position our camera.
    219 
    220   //g_Camera.Look();
    221 
     209  glPushMatrix();
    222210
    223211  // If our camera is above the water we will render the scene flipped upside down.
    224212  // In order to line up the reflection nicely with the world we have to translate
    225213  // the world to the position of our reflected surface, multiplied by two.
    226   //if(g_Camera.Position().y > waterHeight)
    227   //{
    228   // Translate the world, then flip it upside down
    229   //   glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
    230   //  glScalef(1.0, -1.0, 1.0);
    231 
    232   // Since the world is updside down we need to change the culling to FRONT
    233   //glCullFace(GL_FRONT);
    234 
    235   // Set our plane equation and turn clipping on
    236   // double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
    237   //   glEnable(GL_CLIP_PLANE0);
    238   // glClipPlane(GL_CLIP_PLANE0, plane);
    239 
    240   // Render the world upside down and clipped (only render the top flipped).
    241   // If we don't turn OFF caustics for the reflection texture we get horrible
    242   // artifacts in the water.  That is why we set bRenderCaustics to FALSE.
    243   //RenderWorld(false);
    244 
    245   // Turn clipping off
    246   // glDisable(GL_CLIP_PLANE0);
    247 
    248   // Restore back-face culling
    249   //  glCullFace(GL_BACK);
    250   //}
    251   /*else
     214  glEnable(GL_CLIP_PLANE0);
     215  Vector pos = State::getCameraNode()->getAbsCoor();
     216  if(pos.y > waterHeight)
    252217  {
    253       // If the camera is below the water we don't want to flip the world,
    254       // but just render it clipped so only the top is drawn.
    255       double plane[4] = {0.0, 1.0, 0.0, waterHeight};
    256       glEnable(GL_CLIP_PLANE0);
    257       glClipPlane(GL_CLIP_PLANE0, plane);
    258       RenderWorld(true);
    259       glDisable(GL_CLIP_PLANE0);
    260   }*/
     218    // Translate the world, then flip it upside down
     219    glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
     220    glScalef(1.0, -1.0, 1.0);
     221
     222    // Since the world is updside down we need to change the culling to FRONT
     223    glCullFace(GL_FRONT);
     224
     225    // Set our plane equation and turn clipping on
     226    double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     227    glClipPlane(GL_CLIP_PLANE0, plane);
     228  }
     229  else
     230  {
     231    // If the camera is below the water we don't want to flip the world,
     232    // but just render it clipped so only the top is drawn.
     233    double plane[4] = {0.0, 1.0, 0.0, waterHeight};
     234    glClipPlane(GL_CLIP_PLANE0, plane);
     235  }
    261236}
    262237
     
    264239void MappedWater::deactivateReflection()
    265240{
    266 //  glBindTexture(GL_TEXTURE_2D, texture.getTexture()); //is done by mat.select();
    267   glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    268 
    269   //mat.setDiffuseMap(&texture, 0);
    270   // mat.select();
    271   glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    272 
    273 
     241  glDisable(GL_CLIP_PLANE0);
     242  glCullFace(GL_BACK);
     243
     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);
     247
     248  glPopMatrix();
    274249  glPopAttrib();
    275   //   glPopMatrix();
    276250}
    277251
    278252void MappedWater::activateRefraction()
    279253{
     254  // To create the refraction and depth textures we do the same thing
     255  // we did for the reflection texture, except we don't need to turn
     256  // the world upside down.  We want to find the depth of the water,
     257  // not the depth of the sky and above water terrain.
     258
     259  // save viewport matrix and change the viewport size
     260  glPushAttrib(GL_VIEWPORT_BIT);
     261  glViewport(0,0, textureSize, textureSize);
     262
     263  glPushMatrix();
     264
     265  // If our camera is above the water we will render only the parts that
     266  // are under the water.  If the camera is below the water we render
     267  // only the stuff above the water.  Like the reflection texture, we
     268  // incorporate clipping planes to only render what we need.
     269
     270  // If the camera is above water, render the data below the water
     271  glEnable(GL_CLIP_PLANE0);
     272  Vector pos = State::getCameraNode()->getAbsCoor();
     273  if(pos.y > waterHeight)
     274  {
     275    double plane[4] = {0.0, -1.0, 0.0, waterHeight};
     276    glClipPlane(GL_CLIP_PLANE0, plane);
     277  }
     278  // If the camera is below the water, only render the data above the water
     279  else
     280  {
     281    glCullFace(GL_FRONT);
     282    double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     283    glClipPlane(GL_CLIP_PLANE0, plane);
     284  }
    280285}
    281286
    282287void MappedWater::deactivateRefraction()
    283288{
    284 }
     289  glDisable(GL_CLIP_PLANE0);
     290  glCullFace(GL_BACK);
     291
     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);
     296
     297  // Bind the current scene to our refraction texture
     298//  glBindTexture(GL_TEXTURE_2D, g_Texture[REFRACTION_ID]);
     299//  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     300
     301  // Bind the current scene to our depth texture
     302//  glBindTexture(GL_TEXTURE_2D, g_Texture[DEPTH_ID]);
     303//  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
     304
     305  glPopMatrix();
     306  glPopAttrib();
     307}
  • trunk/src/world_entities/environments/mapped_water.h

    r7796 r8037  
    1010#include "world_entity.h"
    1111#include "material.h"
    12 #include "texture.h"
    1312#include "shader.h"
    1413
     
    2019
    2120    void loadParams(const TiXmlElement* root);
     21
    2222
    2323    void activateReflection();
     
    3131
    3232  private:
     33    void setLightPosition(float x, float y, float z) { this->lightPos = Vector(x,y,z); };
    3334    void setHeight(float height);
    3435
    3536  private:
    36     float           waterHeight;       //!< y-coord of the Water
    37     Material        mat;
     37    float               waterHeight;                //!< y-coord of the Water
    3838
    39     Texture         texture;
    40     int             textureSize;       //!< size of the texture
    41     Shader*         shader;
     39    float               move;                       //!< textures coords, speeds, positions for the shaded textures....
     40    float               move2;                      //!<
     41    float               g_WaterUV;                  //!<
     42    float               g_WaterFlow;                //!<
     43    float               refrUV;                     //!<
     44    float               normalUV;                   //!<
     45    float               kNormalMapScale;            //!<
     46
     47    int                 textureSize;                //!< size of the texture
     48    Vector              lightPos;
     49    Material            mat;
     50    Shader*             shader;
     51    Shader::Uniform*    cam_uni;                        //!< uniform that is used for the camera position
    4252
    4353};
  • trunk/src/world_entities/skybox.cc

    r7954 r8037  
    7474  this->setClassID(CL_SKYBOX, "SkyBox");
    7575  this->toList(OM_BACKGROUND);
     76  this->toReflectionList();
    7677  //this->size = 100.0;
    7778  this->textureSize = 1024.0f;
  • trunk/src/world_entities/terrain.cc

    r7954 r8037  
    106106  this->setClassID(CL_TERRAIN, "Terrain");
    107107  this->toList(OM_ENVIRON_NOTICK);
     108  this->toReflectionList();
    108109
    109110  this->objectList = 0;
  • trunk/src/world_entities/world_entity.cc

    r7954 r8037  
    270270}
    271271
    272 
     272void WorldEntity::toReflectionList()
     273{
     274  State::getObjectManager()->toReflectionList( this );
     275}
     276
     277void removeFromReflectionList()
     278{
     279/// TODO
     280///  State::getObject
     281}
    273282
    274283/**
  • trunk/src/world_entities/world_entity.h

    r7954 r8037  
    8080  /* --- Object Manager Block --- */
    8181  void toList(OM_LIST list);
     82
     83  void toReflectionList();
     84  void removeFromReflectionList();
     85
    8286  /** @returns a Reference to the objectListNumber to set. */
    8387  OM_LIST& getOMListNumber() { return this->objectListNumber; }
Note: See TracChangeset for help on using the changeset viewer.