Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7781 in orxonox.OLD for branches


Ignore:
Timestamp:
May 24, 2006, 12:31:03 AM (19 years ago)
Author:
bensch
Message:

orxonox/water: MAPPING IS PERFORMED CORRECTLY :)

File:
1 edited

Legend:

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

    r7780 r7781  
    1717#include "util/loading/load_param.h"
    1818#include "util/loading/factory.h"
     19#include "util/loading/resource_manager.h"
    1920
    2021
     
    2526
    2627MappedWater::MappedWater(const TiXmlElement* root)
    27  : texture(GL_TEXTURE_2D)
     28    : texture(GL_TEXTURE_2D)
    2829{
    2930  this->setClassID(CL_MAPPED_WATER, "MappedWater");
     
    3839  //mat.setDiffuseMap(&this->texture, 0);
    3940  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0);
    40   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
     41/*  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
    4142  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 2);
    4243  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 3);
    43   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);
     44  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);*/
    4445  // load refraction texture
    4546  //mat.setDiffuseMap(&this->refractionTexture, 1);
     
    5051  // set up depth texture
    5152  //mat.setDiffuseMap(&this->depthTexture, 4);
    52  
     53
    5354  // 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.
    5460  this->textureSize = 512;
    55 
    56   shader = new Shader("/home/lieni/orxonox/data/trunk/shaders/water.vert", "/home/lieni/orxonox/data/trunk/shaders/mapped_water.frag");
     61  unsigned int channels = 32;
     62  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));
     65  // Register the texture with OpenGL and bind it to the texture ID
     66  mat.select();
     67  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
     68  printf("========= CREATE %d\n", this->texture.getTexture());
     69
     70  // 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);
     72
     73  // Set the texture quality
     74  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     75  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     76  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     77  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     78
     79  // 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");
    5783}
    5884
    5985MappedWater::~MappedWater()
    6086{
    61   delete shader;
     87  //delete shader;
    6288}
    6389
     
    90116
    91117  mat.select();
     118  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
     119
    92120  // Shader init
    93   this->shader->activateShader();
     121  //this->shader->activateShader();
    94122  GLint uniform;
    95  
     123
    96124  // Set the variable "reflection" to correspond to the first texture unit
    97   uniform = glGetUniformLocationARB(shader->getProgram(), "reflection"); 
     125  uniform = glGetUniformLocationARB(shader->getProgram(), "reflection");
    98126  glUniform1iARB(uniform, 0); //second paramter is the texture unit
    99127
     
    108136
    109137  // Set the variable "dudvMap" to correspond to the fourth texture unit
    110   uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap"); 
     138  uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");
    111139  glUniform1iARB(uniform, 3);
    112140
    113141  // Set the variable "depthMap" to correspond to the fifth texture unit
    114142  //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");
    115   //glUniform1iARB(uniform, 4); 
     143  //glUniform1iARB(uniform, 4);
    116144  // FIXME we dont have a depthMap yet :-(
    117145
    118146  // Give the variable "waterColor" a blue color
    119147  uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");
    120   glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f); 
     148  glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);
    121149
    122150  // FIXME set camera and light information
     
    129157  // Give the variable "lightPos" our hard coded light position
    130158  uniform = glGetUniformLocationARB(shader->getProgram(), "lightPos");
    131   glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f); 
     159  glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f);
    132160
    133161  // Give the variable "cameraPos" our camera position
    134162  uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos");
    135   glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f); 
     163  glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f);
    136164
    137165  glBegin(GL_QUADS);
    138     glNormal3f(0,1,0);
    139     glMultiTexCoord2f(GL_TEXTURE0, 0,0);
    140     glMultiTexCoord2f(GL_TEXTURE1, 0,0);
    141     glMultiTexCoord2f(GL_TEXTURE2, 0,0);
    142     glMultiTexCoord2f(GL_TEXTURE3, 0,0);
    143     glMultiTexCoord2f(GL_TEXTURE4, 0,0);
    144     glVertex3f(0,0,0);
    145 
    146     glMultiTexCoord2f(GL_TEXTURE0, 1,0);
    147     glMultiTexCoord2f(GL_TEXTURE1, 1,0);
    148     glMultiTexCoord2f(GL_TEXTURE2, 1,0);
    149     glMultiTexCoord2f(GL_TEXTURE3, 1,0);
    150     glMultiTexCoord2f(GL_TEXTURE4, 1,0);
    151     glVertex3f(100,0,0);
    152 
    153     glMultiTexCoord2f(GL_TEXTURE0, 1,1);
    154     glMultiTexCoord2f(GL_TEXTURE1, 1,1);
    155     glMultiTexCoord2f(GL_TEXTURE2, 1,1);
    156     glMultiTexCoord2f(GL_TEXTURE3, 1,1);
    157     glMultiTexCoord2f(GL_TEXTURE4, 1,1);
    158     glVertex3f(100,0,-100);
    159 
    160     glMultiTexCoord2f(GL_TEXTURE0, 0,1);
    161     glMultiTexCoord2f(GL_TEXTURE1, 0,1);
    162     glMultiTexCoord2f(GL_TEXTURE2, 0,1);
    163     glMultiTexCoord2f(GL_TEXTURE3, 0,1);
    164     glMultiTexCoord2f(GL_TEXTURE4, 0,1);
    165     glVertex3f(0,0,-100);
     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);
    166194  glEnd();
    167   this->shader->deactivateShader();
     195  //this->shader->deactivateShader();
    168196
    169197  glPopMatrix();
     
    172200void MappedWater::tick(float dt)
    173201{
    174 
    175202}
    176203
     
    183210{
    184211  glPushAttrib(GL_VIEWPORT_BIT);
    185 //   glPushMatrix();
     212  //   glPushMatrix();
    186213
    187214  //glLoadIdentity();
     
    199226  //if(g_Camera.Position().y > waterHeight)
    200227  //{
    201       // Translate the world, then flip it upside down
    202    //   glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
    203     //  glScalef(1.0, -1.0, 1.0);
    204 
    205       // Since the world is updside down we need to change the culling to FRONT
    206       //glCullFace(GL_FRONT);
    207 
    208       // Set our plane equation and turn clipping on
    209      // double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
    210    //   glEnable(GL_CLIP_PLANE0);
    211      // glClipPlane(GL_CLIP_PLANE0, plane);
    212 
    213       // Render the world upside down and clipped (only render the top flipped).
    214       // If we don't turn OFF caustics for the reflection texture we get horrible
    215       // artifacts in the water.  That is why we set bRenderCaustics to FALSE.
    216       //RenderWorld(false);
    217 
    218       // Turn clipping off
    219      // glDisable(GL_CLIP_PLANE0);
    220 
    221       // Restore back-face culling
    222     //  glCullFace(GL_BACK);
     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);
    223250  //}
    224251  /*else
     
    237264void MappedWater::deactivateReflection()
    238265{
    239   //glBindTexture(GL_TEXTURE_2D, texture.getTexture()); is done by mat.select();
     266//  glBindTexture(GL_TEXTURE_2D, texture.getTexture()); //is done by mat.select();
     267  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    240268
    241269  //mat.setDiffuseMap(&texture, 0);
    242  
    243   //mat.select();
    244   //glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     270  // mat.select();
     271  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    245272
    246273
    247274  glPopAttrib();
    248 //   glPopMatrix();
     275  //   glPopMatrix();
    249276}
    250277
    251278void MappedWater::activateRefraction()
    252279{
    253 
    254280}
    255281
    256282void MappedWater::deactivateRefraction()
    257283{
    258 
    259 }
     284}
Note: See TracChangeset for help on using the changeset viewer.