- Timestamp:
- May 18, 2006, 5:05:45 PM (19 years ago)
- Location:
- branches/water/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/lib/graphics/importer/material.cc
r7687 r7700 333 333 // MAPPING // 334 334 335 /** 336 * Sets the Materials Diffuse Map 335 void Material::setDiffuseMap(Texture* texture, unsigned int textureNumber) 336 { 337 assert(textureNumber < Material::getMaxTextureUnits()); 338 339 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 340 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 341 342 if (this->textures.size() <= textureNumber) 343 this->textures.resize(textureNumber+1, NULL); 344 345 //! @todo check if RESOURCE MANAGER is availiable 346 this->textures[textureNumber] = texture; 347 } 348 349 350 /** 351 * @brief Sets the Materials Diffuse Map 337 352 * @param dMap the Name of the Image to Use 338 353 */ -
branches/water/src/lib/graphics/importer/material.h
r7687 r7700 53 53 54 54 // MAPPING // 55 void setDiffuseMap(Texture* texture, unsigned int textureNumber = 0); 55 56 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 56 57 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); -
branches/water/src/lib/graphics/importer/texture.cc
r7687 r7700 29 29 #endif 30 30 31 32 33 34 Texture::Texture(GLenum target) 35 { 36 this->init(); 37 this->generateTexture(texture, target); 38 } 39 31 40 /** 32 41 * Constructor for a Texture … … 42 51 } 43 52 } 53 54 44 55 45 56 Texture::Texture(SDL_Surface* surface, GLenum target) … … 150 161 151 162 /** 152 * rebuilds the texture.163 * @brief rebuilds the texture. 153 164 * reloads the Texture from Memory to OpenGL. 154 165 */ … … 171 182 172 183 /** 173 * set the surface this Texture handles184 * @brief set the surface this Texture handles 174 185 * @param newSurface the new Surface to set as the image for this Texture. 175 186 * … … 191 202 192 203 /** 193 * enables, disables textures204 * @brief enables, disables textures 194 205 * @param texturesEnabled true if the textures should be enabled 195 206 */ … … 204 215 ////////////////////////////////////// 205 216 /** 206 * converts surface to a new SDL_Surface, that is loadable by openGL217 * @brief converts surface to a new SDL_Surface, that is loadable by openGL 207 218 * @param surface the Surface to convert 208 219 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false. … … 266 277 267 278 /** 268 * Loads a Texture to the openGL-environment.279 * @brief Loads a Texture to the openGL-environment. 269 280 * @param surface the Image to load to openGL 270 281 * @returns The ID of the texture. … … 277 288 278 289 int errorCode = 0; //!< the error code for the texture loading functions 279 GLuint texture ;//!< the OpenGL texture handle290 GLuint texture = 0; //!< the OpenGL texture handle 280 291 int mipmapLevel = 0; //!< the maximum mipmap level for this texture 281 292 int mipmapWidth = 0; //!< the width of the mipmap … … 287 298 288 299 /* Create an OpenGL texture for the image */ 289 glGenTextures(1, &texture); 290 glBindTexture(target, texture); 291 292 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 293 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 294 295 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 296 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 297 300 this->generateTexture(texture, target); 298 301 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority); 299 300 301 /* control the mipmap levels */302 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);303 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);304 302 305 303 /* build the Texture OpenGL V >= 1.1 */ … … 330 328 } 331 329 330 void Texture::generateTexture(GLuint& texture, GLenum target) 331 { 332 if (!glIsTexture(texture)) 333 { 334 glGenTextures(1, &texture); 335 } 336 glBindTexture(target, texture); 337 338 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 339 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 340 341 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 342 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 343 344 /* control the mipmap levels */ 345 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); 346 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 347 } 348 -
branches/water/src/lib/graphics/importer/texture.h
r7687 r7700 18 18 { 19 19 public: 20 Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D); 20 Texture(GLenum target = GL_TEXTURE_2D); 21 Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 21 22 Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 22 23 virtual ~Texture(); … … 50 51 private: 51 52 void init(); 53 static void generateTexture(GLuint& texture, GLenum target); 52 54 53 55 private: -
branches/water/src/world_entities/environments/mapped_water.cc
r7687 r7700 24 24 25 25 MappedWater::MappedWater(const TiXmlElement* root) 26 : texture(GL_TEXTURE_2D) 26 27 { 27 28 this->setClassID(CL_MAPPED_WATER, "MappedWater"); … … 30 31 if (root != NULL) 31 32 this->loadParams(root); 33 34 mat.setDiffuseMap(&this->texture, 0); 32 35 } 33 36 … … 58 61 //glEnable(GL_LIGHTING); 59 62 60 Material mat; 61 mat.setDiffuseMap("pictures/ground.tga", GL_TEXTURE_2D, 0); 63 62 64 //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1); 63 65 //mat.setTransparency(1.0); 64 66 //mat.setDiffuse(1.0, 0, .1); 67 68 69 // HACK 70 71 //glDisable(GL_BLEND); 72 //glActiveTexture(GL_TEXTURE0); 73 //glBindTexture(GL_TEXTURE_2D, this->texture); 74 65 75 mat.select(); 66 76 … … 94 104 } 95 105 96 void MappedWater::activateReflection() {} 97 void MappedWater::deactivateReflection() {} 106 void MappedWater::activateReflection() 107 { 108 // Change the view port to be the size of the texture we will render to 109 // HACK 110 int textureSize = 512; 111 glPushAttrib(GL_VIEWPORT_BIT); 112 glViewport(0,0, textureSize, textureSize); 98 113 99 void MappedWater::activateRefraction() {} 100 void MappedWater::deactivateRefraction() {} 114 // Clear the color and depth bits, reset the matrix and position our camera. 115 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 116 // glLoadIdentity(); 117 //g_Camera.Look(); 118 119 // So we don't affect any other objects in the world we push on a new matrix 120 //glPushMatrix(); 121 122 // If our camera is above the water we will render the scene flipped upside down. 123 // In order to line up the reflection nicely with the world we have to translate 124 // the world to the position of our reflected surface, multiplied by two. 125 //if(g_Camera.Position().y > waterHeight) 126 //{ 127 // Translate the world, then flip it upside down 128 // glTranslatef(0.0f, waterHeight*2.0f, 0.0f); 129 // glScalef(1.0, -1.0, 1.0); 130 131 // Since the world is updside down we need to change the culling to FRONT 132 //glCullFace(GL_FRONT); 133 134 // Set our plane equation and turn clipping on 135 // double plane[4] = {0.0, 1.0, 0.0, -waterHeight}; 136 // glEnable(GL_CLIP_PLANE0); 137 // glClipPlane(GL_CLIP_PLANE0, plane); 138 139 // Render the world upside down and clipped (only render the top flipped). 140 // If we don't turn OFF caustics for the reflection texture we get horrible 141 // artifacts in the water. That is why we set bRenderCaustics to FALSE. 142 //RenderWorld(false); 143 144 // Turn clipping off 145 // glDisable(GL_CLIP_PLANE0); 146 147 // Restore back-face culling 148 // glCullFace(GL_BACK); 149 //} 150 /*else 151 { 152 // If the camera is below the water we don't want to flip the world, 153 // but just render it clipped so only the top is drawn. 154 double plane[4] = {0.0, 1.0, 0.0, waterHeight}; 155 glEnable(GL_CLIP_PLANE0); 156 glClipPlane(GL_CLIP_PLANE0, plane); 157 RenderWorld(true); 158 glDisable(GL_CLIP_PLANE0); 159 }*/ 160 161 // Restore the previous matrix 162 //glPopMatrix(); 163 164 // Bind the current scene to our reflection texture 165 //glBindTexture(GL_TEXTURE_2D, g_Texture[REFLECTION_ID]); 166 167 168 169 glBindTexture(GL_TEXTURE_2D, texture.getTexture()); 170 // ; 171 // mat.setDiffuseMap(&texture, 0); 172 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 173 174 glPopAttrib(); 175 } 176 177 void MappedWater::deactivateReflection() 178 { 179 180 } 181 182 void MappedWater::activateRefraction() 183 { 184 185 } 186 187 void MappedWater::deactivateRefraction() 188 { 189 190 } -
branches/water/src/world_entities/environments/mapped_water.h
r7687 r7700 10 10 #include "world_entity.h" 11 11 #include "material.h" 12 #include "texture.h" 12 13 13 14 … … 34 35 private: 35 36 float waterHeight; //!< y-coord of the Water 37 Material mat; 38 39 Texture texture; 36 40 37 41 };
Note: See TracChangeset
for help on using the changeset viewer.