Changeset 7781 in orxonox.OLD for branches/water/src/world_entities
- Timestamp:
- May 24, 2006, 12:31:03 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/world_entities/environments/mapped_water.cc
r7780 r7781 17 17 #include "util/loading/load_param.h" 18 18 #include "util/loading/factory.h" 19 #include "util/loading/resource_manager.h" 19 20 20 21 … … 25 26 26 27 MappedWater::MappedWater(const TiXmlElement* root) 27 : texture(GL_TEXTURE_2D)28 : texture(GL_TEXTURE_2D) 28 29 { 29 30 this->setClassID(CL_MAPPED_WATER, "MappedWater"); … … 38 39 //mat.setDiffuseMap(&this->texture, 0); 39 40 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); 41 42 mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 2); 42 43 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);*/ 44 45 // load refraction texture 45 46 //mat.setDiffuseMap(&this->refractionTexture, 1); … … 50 51 // set up depth texture 51 52 //mat.setDiffuseMap(&this->depthTexture, 4); 52 53 53 54 // 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. 54 60 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"); 57 83 } 58 84 59 85 MappedWater::~MappedWater() 60 86 { 61 delete shader;87 //delete shader; 62 88 } 63 89 … … 90 116 91 117 mat.select(); 118 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 119 92 120 // Shader init 93 this->shader->activateShader();121 //this->shader->activateShader(); 94 122 GLint uniform; 95 123 96 124 // Set the variable "reflection" to correspond to the first texture unit 97 uniform = glGetUniformLocationARB(shader->getProgram(), "reflection"); 125 uniform = glGetUniformLocationARB(shader->getProgram(), "reflection"); 98 126 glUniform1iARB(uniform, 0); //second paramter is the texture unit 99 127 … … 108 136 109 137 // Set the variable "dudvMap" to correspond to the fourth texture unit 110 uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap"); 138 uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap"); 111 139 glUniform1iARB(uniform, 3); 112 140 113 141 // Set the variable "depthMap" to correspond to the fifth texture unit 114 142 //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap"); 115 //glUniform1iARB(uniform, 4); 143 //glUniform1iARB(uniform, 4); 116 144 // FIXME we dont have a depthMap yet :-( 117 145 118 146 // Give the variable "waterColor" a blue color 119 147 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); 121 149 122 150 // FIXME set camera and light information … … 129 157 // Give the variable "lightPos" our hard coded light position 130 158 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); 132 160 133 161 // Give the variable "cameraPos" our camera position 134 162 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); 136 164 137 165 glBegin(GL_QUADS); 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 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); 166 194 glEnd(); 167 this->shader->deactivateShader();195 //this->shader->deactivateShader(); 168 196 169 197 glPopMatrix(); … … 172 200 void MappedWater::tick(float dt) 173 201 { 174 175 202 } 176 203 … … 183 210 { 184 211 glPushAttrib(GL_VIEWPORT_BIT); 185 // glPushMatrix();212 // glPushMatrix(); 186 213 187 214 //glLoadIdentity(); … … 199 226 //if(g_Camera.Position().y > waterHeight) 200 227 //{ 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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); 223 250 //} 224 251 /*else … … 237 264 void MappedWater::deactivateReflection() 238 265 { 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)); 240 268 241 269 //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); 245 272 246 273 247 274 glPopAttrib(); 248 // glPopMatrix();275 // glPopMatrix(); 249 276 } 250 277 251 278 void MappedWater::activateRefraction() 252 279 { 253 254 280 } 255 281 256 282 void MappedWater::deactivateRefraction() 257 283 { 258 259 } 284 }
Note: See TracChangeset
for help on using the changeset viewer.