Changeset 8249 in orxonox.OLD for branches/water/src/world_entities
- Timestamp:
- Jun 8, 2006, 2:59:09 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/world_entities/environments/mapped_water.cc
r8241 r8249 81 81 //mat.select(); 82 82 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 83 glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);84 83 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 85 84 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 86 85 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 87 86 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 88 87 glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection); 88 89 89 90 unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels]; 90 91 memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int)); 91 92 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1)); 92 93 94 // Set the texture quality95 93 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 96 94 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 97 95 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 98 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 99 101 100 102 // Since we stored the texture space with OpenGL, we can delete the image data … … 238 240 // In order to line up the reflection nicely with the world we have to translate 239 241 // the world to the position of our reflected surface, multiplied by two. 240 glEnable(GL_CLIP_PLANE0);242 //glEnable(GL_CLIP_PLANE0); 241 243 Vector pos = State::getCameraNode()->getAbsCoor(); 242 244 if(pos.y > waterHeight) … … 247 249 248 250 // Since the world is updside down we need to change the culling to FRONT 249 glCullFace(GL_FRONT);251 //glCullFace(GL_FRONT); 250 252 251 253 // Set our plane equation and turn clipping on 252 254 double plane[4] = {0.0, 1.0, 0.0, -waterHeight}; 253 glClipPlane(GL_CLIP_PLANE0, plane);255 //glClipPlane(GL_CLIP_PLANE0, plane); 254 256 } 255 257 else … … 258 260 // but just render it clipped so only the top is drawn. 259 261 double plane[4] = {0.0, 1.0, 0.0, waterHeight}; 260 glClipPlane(GL_CLIP_PLANE0, plane);262 //glClipPlane(GL_CLIP_PLANE0, plane); 261 263 } 262 264 } … … 265 267 void MappedWater::deactivateReflection() 266 268 { 267 glDisable(GL_CLIP_PLANE0);268 glCullFace(GL_BACK);269 270 mat.select();269 //glDisable(GL_CLIP_PLANE0); 270 //glCullFace(GL_BACK); 271 272 //mat.select(); 271 273 /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 272 274 ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 273 275 /// 274 276 275 mat.select();276 277 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 277 278 278 279 // Create the texture and store it on the video card 279 280 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 280 281 282 /// 281 282 283 283 glPopMatrix(); 284 284 glPopAttrib(); … … 286 286 287 287 void MappedWater::activateRefraction() 288 { 288 { 289 // save viewport matrix and change the viewport size 290 glPushAttrib(GL_VIEWPORT_BIT); 291 glViewport(0,0, textureSize, textureSize); 292 293 glMatrixMode(GL_MODELVIEW); 294 glPushMatrix(); 295 296 // If our camera is above the water we will render the scene flipped upside down. 297 // In order to line up the reflection nicely with the world we have to translate 298 // the world to the position of our reflected surface, multiplied by two. 299 //glEnable(GL_CLIP_PLANE0); 300 Vector pos = State::getCameraNode()->getAbsCoor(); 301 if(pos.y > waterHeight) 302 { 303 // Translate the world, then flip it upside down 304 glTranslatef(0.0f, waterHeight*2.0f, 0.0f); 305 glScalef(1.0, -1.0, 1.0); 306 307 // Since the world is updside down we need to change the culling to FRONT 308 //glCullFace(GL_FRONT); 309 310 // Set our plane equation and turn clipping on 311 double plane[4] = {0.0, 1.0, 0.0, -waterHeight}; 312 //glClipPlane(GL_CLIP_PLANE0, plane); 313 } 314 else 315 { 316 // If the camera is below the water we don't want to flip the world, 317 // but just render it clipped so only the top is drawn. 318 double plane[4] = {0.0, 1.0, 0.0, waterHeight}; 319 //glClipPlane(GL_CLIP_PLANE0, plane); 320 } 321 322 /* 289 323 // To create the refraction and depth textures we do the same thing 290 324 // we did for the reflection texture, except we don't need to turn … … 305 339 306 340 // If the camera is above water, render the data below the water 307 glEnable(GL_CLIP_PLANE 0);341 glEnable(GL_CLIP_PLANE1); 308 342 Vector pos = State::getCameraNode()->getAbsCoor(); 309 343 if(pos.y > waterHeight) … … 311 345 double plane[4] = {0.0, -1.0, 0.0, waterHeight}; 312 346 glClipPlane(GL_CLIP_PLANE0, plane); 347 313 348 } 314 349 // If the camera is below the water, only render the data above the water … … 319 354 glClipPlane(GL_CLIP_PLANE0, plane); 320 355 } 356 PRINTF(0)("test");*/ 321 357 } 322 358 323 359 void MappedWater::deactivateRefraction() 324 360 { 325 glDisable(GL_CLIP_PLANE0); 326 glCullFace(GL_BACK); 327 328 mat.select(); 329 //mat.renderToTexture(1, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 330 //glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0); 331 //mat.renderToTexture(0, GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, textureSize, textureSize, 0); 361 //glDisable(GL_CLIP_PLANE0); 362 //glCullFace(GL_BACK); 363 364 365 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1)); 366 367 // Create the texture and store it on the video card 368 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 369 370 glPopMatrix(); 371 glPopAttrib(); 332 372 333 373 // Bind the current scene to our refraction texture … … 339 379 // glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0); 340 380 341 glPopMatrix(); 342 glPopAttrib(); 343 } 381 }
Note: See TracChangeset
for help on using the changeset viewer.