Changeset 8037 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- May 31, 2006, 4:52:34 PM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/environments/mapped_water.cc
r7796 r8037 18 18 #include "util/loading/factory.h" 19 19 #include "util/loading/resource_manager.h" 20 #include "state.h" 20 21 21 22 … … 26 27 27 28 MappedWater::MappedWater(const TiXmlElement* root) 28 : texture(GL_TEXTURE_2D)29 29 { 30 30 this->setClassID(CL_MAPPED_WATER, "MappedWater"); … … 34 34 this->loadParams(root); 35 35 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 38 40 // set up refleciton texture 39 //mat.setDiffuseMap( &this->texture, 0);41 //mat.setDiffuseMap(this->texture, 0); 40 42 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);*/45 43 // load refraction texture 46 //mat.setDiffuseMap(&this->refractionTexture, 1);44 mat.setDiffuseMap("pictures/error_texture.png", GL_TEXTURE_2D, 1); 47 45 // load normal map 48 46 //mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2); … … 50 48 //mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3); 51 49 // 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 54 56 // 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.60 57 this->textureSize = 512; 61 58 unsigned int channels = 32; 62 59 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)); 65 64 // Register the texture with OpenGL and bind it to the texture ID 66 65 mat.select(); 67 66 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 68 printf("========= CREATE %d\n", this->texture.getTexture());69 67 70 68 // 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); 72 76 73 77 // Set the texture quality … … 78 82 79 83 // 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();*/ 83 117 } 84 118 … … 86 120 { 87 121 //delete shader; 122 //delete cam_uni; 88 123 } 89 124 … … 93 128 94 129 LoadParam(root, "waterHeight", this, MappedWater, setHeight); 130 LoadParam(root, "lightPos", this, MappedWater, setLightPosition); 95 131 } 96 132 … … 101 137 glTranslatef(0,this->waterHeight,0); 102 138 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(); 117 140 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); 164 147 165 148 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); 194 180 glEnd(); 195 //this->shader->deactivateShader(); 181 182 ///this->shader->deactivateShader(); 183 184 mat.unselect(); 196 185 197 186 glPopMatrix(); … … 200 189 void MappedWater::tick(float dt) 201 190 { 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; 202 196 } 203 197 … … 209 203 void MappedWater::activateReflection() 210 204 { 205 // save viewport matrix and change the viewport size 211 206 glPushAttrib(GL_VIEWPORT_BIT); 212 // glPushMatrix();213 214 //glLoadIdentity();215 207 glViewport(0,0, textureSize, textureSize); 216 208 217 218 // Clear the color and depth bits, reset the matrix and position our camera. 219 220 //g_Camera.Look(); 221 209 glPushMatrix(); 222 210 223 211 // If our camera is above the water we will render the scene flipped upside down. 224 212 // In order to line up the reflection nicely with the world we have to translate 225 213 // 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) 252 217 { 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 } 261 236 } 262 237 … … 264 239 void MappedWater::deactivateReflection() 265 240 { 266 // glBindTexture(GL_TEXTURE_2D, texture.getTexture()); //is done by mat.select();267 gl BindTexture(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(); 274 249 glPopAttrib(); 275 // glPopMatrix();276 250 } 277 251 278 252 void MappedWater::activateRefraction() 279 253 { 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 } 280 285 } 281 286 282 287 void MappedWater::deactivateRefraction() 283 288 { 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 10 10 #include "world_entity.h" 11 11 #include "material.h" 12 #include "texture.h"13 12 #include "shader.h" 14 13 … … 20 19 21 20 void loadParams(const TiXmlElement* root); 21 22 22 23 23 void activateReflection(); … … 31 31 32 32 private: 33 void setLightPosition(float x, float y, float z) { this->lightPos = Vector(x,y,z); }; 33 34 void setHeight(float height); 34 35 35 36 private: 36 float waterHeight; //!< y-coord of the Water 37 Material mat; 37 float waterHeight; //!< y-coord of the Water 38 38 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 42 52 43 53 }; -
trunk/src/world_entities/skybox.cc
r7954 r8037 74 74 this->setClassID(CL_SKYBOX, "SkyBox"); 75 75 this->toList(OM_BACKGROUND); 76 this->toReflectionList(); 76 77 //this->size = 100.0; 77 78 this->textureSize = 1024.0f; -
trunk/src/world_entities/terrain.cc
r7954 r8037 106 106 this->setClassID(CL_TERRAIN, "Terrain"); 107 107 this->toList(OM_ENVIRON_NOTICK); 108 this->toReflectionList(); 108 109 109 110 this->objectList = 0; -
trunk/src/world_entities/world_entity.cc
r7954 r8037 270 270 } 271 271 272 272 void WorldEntity::toReflectionList() 273 { 274 State::getObjectManager()->toReflectionList( this ); 275 } 276 277 void removeFromReflectionList() 278 { 279 /// TODO 280 /// State::getObject 281 } 273 282 274 283 /** -
trunk/src/world_entities/world_entity.h
r7954 r8037 80 80 /* --- Object Manager Block --- */ 81 81 void toList(OM_LIST list); 82 83 void toReflectionList(); 84 void removeFromReflectionList(); 85 82 86 /** @returns a Reference to the objectListNumber to set. */ 83 87 OM_LIST& getOMListNumber() { return this->objectListNumber; }
Note: See TracChangeset
for help on using the changeset viewer.