Changeset 8312 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jun 11, 2006, 12:49:25 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/environments/mapped_water.cc
r8037 r8312 40 40 // set up refleciton texture 41 41 //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); 43 43 // load refraction texture 44 mat.setDiffuseMap("pictures/ error_texture.png", GL_TEXTURE_2D, 1);44 mat.setDiffuseMap("pictures/refr.bmp", GL_TEXTURE_2D, 1); 45 45 // load normal map 46 //mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);46 mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2); 47 47 // load dudv map 48 //mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);48 mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3); 49 49 // set up depth texture 50 50 //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4); … … 56 56 // set the size of the refraction and reflection textures 57 57 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 58 77 unsigned int channels = 32; 59 78 GLenum type = GL_RGBA; 60 79 unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels]; 61 80 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(); 66 82 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 67 68 // Create the texture and store it on the video card69 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 refraction74 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 quality78 83 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 79 84 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 80 85 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 81 86 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 82 101 83 102 // 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; 86 105 87 106 … … 94 113 /// initialization of the shaders 95 114 // 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"); 97 116 98 117 this->shader->activateShader(); … … 106 125 Shader::Uniform(shader, "dudvMap").set(3); 107 126 // 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); 109 128 // Give the variable "waterColor" a blue color 110 129 Shader::Uniform(shader, "waterColor").set(0.1f, 0.2f, 0.4f, 1.0f); … … 114 133 cam_uni = new Shader::Uniform(shader, "cameraPos"); 115 134 116 this->shader->deactivateShader(); */135 this->shader->deactivateShader(); 117 136 } 118 137 … … 134 153 void MappedWater::draw() const 135 154 { 155 glMatrixMode(GL_MODELVIEW); 156 136 157 glPushMatrix(); 137 158 glTranslatef(0,this->waterHeight,0); … … 140 161 mat.select(); 141 162 142 ///this->shader->activateShader();163 this->shader->activateShader(); 143 164 144 165 // reset the camera uniform to the current cam position 145 166 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); 147 170 148 171 glBegin(GL_QUADS); 149 172 // 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 152 177 glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2); // Normal map texture 153 178 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 154 glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture179 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 155 180 glVertex3f(0.0f, waterHeight, 0.0f); 156 181 157 182 // 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 160 187 glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2); // Normal map texture 161 188 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 162 glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture189 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 163 190 glVertex3f(0.0f, waterHeight, 1000.0f); 164 191 165 192 // 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 168 197 glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2); // Normal map texture 169 198 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 170 glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture199 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 171 200 glVertex3f(1000.0f, waterHeight, 1000.0f); 172 201 173 202 // 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 176 207 glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2); // Normal map texture 177 208 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 178 glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture209 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 179 210 glVertex3f(1000.0f, waterHeight, 0.0f); 180 211 glEnd(); 181 212 182 ///this->shader->deactivateShader();213 this->shader->deactivateShader(); 183 214 184 215 mat.unselect(); … … 207 238 glViewport(0,0, textureSize, textureSize); 208 239 240 glMatrixMode(GL_MODELVIEW); 209 241 glPushMatrix(); 210 242 … … 214 246 glEnable(GL_CLIP_PLANE0); 215 247 Vector pos = State::getCameraNode()->getAbsCoor(); 248 //pos.debug(); 249 //PRINTF(0)("waterheight: %f\n", waterHeight); 216 250 if(pos.y > waterHeight) 217 251 { … … 242 276 glCullFace(GL_BACK); 243 277 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 247 288 248 289 glPopMatrix(); … … 251 292 252 293 void 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 254 331 // To create the refraction and depth textures we do the same thing 255 332 // we did for the reflection texture, except we don't need to turn … … 261 338 glViewport(0,0, textureSize, textureSize); 262 339 340 glMatrixMode(GL_MODELVIEW); 263 341 glPushMatrix(); 264 342 … … 275 353 double plane[4] = {0.0, -1.0, 0.0, waterHeight}; 276 354 glClipPlane(GL_CLIP_PLANE0, plane); 355 277 356 } 278 357 // If the camera is below the water, only render the data above the water … … 290 369 glCullFace(GL_BACK); 291 370 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(); 296 379 297 380 // Bind the current scene to our refraction texture … … 303 386 // glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0); 304 387 305 glPopMatrix(); 306 glPopAttrib(); 307 } 388 }
Note: See TracChangeset
for help on using the changeset viewer.