Changeset 7785 in orxonox.OLD for trunk/src/lib
- Timestamp:
- May 24, 2006, 3:17:19 AM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/material.cc
r7676 r7785 45 45 this->setTransparency(1.0); 46 46 47 this->diffuseTexture = NULL;48 47 this->ambientTexture = NULL; 49 48 this->specularTexture = NULL; … … 61 60 PRINTF(5)("delete Material %s.\n", this->getName()); 62 61 63 if (this->diffuseTexture != NULL) 64 { 65 ResourceManager::getInstance()->unload(this->diffuseTexture); 66 } 62 while(!this->textures.empty()) 63 { 64 if (this->textures.back() != NULL) 65 ResourceManager::getInstance()->unload(this->textures.back()); 66 this->textures.pop_back(); 67 } 68 67 69 if (this->ambientTexture != NULL) 68 70 ResourceManager::getInstance()->unload(this->ambientTexture); 69 71 if (this->specularTexture != NULL) 70 72 ResourceManager::getInstance()->unload(this->specularTexture); 71 } 72 73 Material& Material::operator=(const Material& m) 74 { 75 this->setIllum(m.illumModel); 76 this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]); 77 this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]); 78 this->setSpecular(m.specular[0],m.specular[1],m.specular[2]); 79 this->setShininess(m.shininess); 80 this->setTransparency(m.transparency); 81 82 if (this->diffuseTexture != NULL) 83 ResourceManager::getInstance()->unload(this->diffuseTexture); 84 if (m.diffuseTexture != NULL) 85 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture); 86 this->ambientTexture = NULL; /// FIXME 87 this->specularTexture = NULL; /// FIXME 88 89 this->setName(m.getName()); 90 } 73 74 if (this == Material::selectedMaterial) 75 Material::selectedMaterial = NULL; 76 } 77 78 79 const Material* Material::selectedMaterial = NULL; 80 81 const GLenum Material::glTextureArbs[] = 82 { 83 GL_TEXTURE0, 84 GL_TEXTURE1, 85 GL_TEXTURE2, 86 GL_TEXTURE3, 87 GL_TEXTURE4, 88 GL_TEXTURE5, 89 GL_TEXTURE6, 90 GL_TEXTURE7 91 }; 92 93 94 /// TODO FIX THIS 95 // Material& Material::operator=(const Material& m) 96 // { 97 // this->setIllum(m.illumModel); 98 // this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]); 99 // this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]); 100 // this->setSpecular(m.specular[0],m.specular[1],m.specular[2]); 101 // this->setShininess(m.shininess); 102 // this->setTransparency(m.transparency); 103 // 104 // if (this->diffuseTexture != NULL) 105 // ResourceManager::getInstance()->unload(this->diffuseTexture); 106 // if (m.diffuseTexture != NULL) 107 // this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture); 108 // this->ambientTexture = NULL; /// FIXME 109 // this->specularTexture = NULL; /// FIXME 110 // 111 // this->setName(m.getName()); 112 // } 113 91 114 92 115 … … 94 117 * sets the material with which the following Faces will be painted 95 118 */ 96 bool Material::select () const 97 { 119 bool Material::select() const 120 { 121 if (unlikely(this == Material::selectedMaterial)) 122 return true; 123 124 98 125 // setting diffuse color 99 126 glColor4f (diffuse[0], diffuse[1], diffuse[2], this->transparency); 100 // glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);101 102 127 // setting ambient color 103 128 glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient); 104 105 129 // setting up Sprecular 106 130 glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular); 107 108 131 // setting up Shininess 109 132 glMaterialf(GL_FRONT, GL_SHININESS, this->shininess); 110 133 134 111 135 // setting the transparency 112 136 if (this->transparency < 1.0 || /* This allows alpha blending of 2D textures with the scene */ 113 ( this->diffuseTexture && this->diffuseTexture->hasAlpha()))137 (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha())) 114 138 { 115 139 glEnable(GL_BLEND); … … 117 141 } 118 142 else 119 { 120 glDisable(GL_BLEND); 121 //glColor4f(*(this->diffuse), *(this->diffuse+1), *(this->diffuse+2), 1); 122 } 143 { 144 glDisable(GL_BLEND); 145 } 123 146 124 147 … … 129 152 glShadeModel(GL_SMOOTH); 130 153 131 if (this->diffuseTexture != NULL) 154 if (likely(Material::selectedMaterial != NULL)) 155 { 156 for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i) 132 157 { 158 glActiveTexture(Material::glTextureArbs[i]); 159 glBindTexture(GL_TEXTURE_2D, 0); 160 glDisable(GL_TEXTURE_2D); 161 } 162 } 163 164 for(unsigned int i = 0; i < this->textures.size(); ++i) 165 { 166 if (likely(this->textures[i] != NULL)) 167 { 168 glActiveTexture(Material::glTextureArbs[i]); 133 169 glEnable(GL_TEXTURE_2D); 134 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 170 if(this->textures[i]->hasAlpha()) 171 { 172 glEnable(GL_BLEND); 173 } 174 glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture()); 135 175 } 136 else 137 { 138 glDisable(GL_TEXTURE_2D); 139 glBindTexture(GL_TEXTURE_2D, 0); 140 } 176 } 177 Material::selectedMaterial = this; 178 179 /* if (this->diffuseTexture != NULL) 180 { 181 glEnable(GL_TEXTURE_2D); 182 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 183 } 184 else 185 { 186 glDisable(GL_TEXTURE_2D); 187 glBindTexture(GL_TEXTURE_2D, 0); 188 }*/ 141 189 } 142 190 … … 162 210 /** 163 211 * Sets the Material Diffuse Color. 164 * @param r Red Color Channel. 212 * @param r Red Color Channel.a 165 213 * @param g Green Color Channel. 166 214 * @param b Blue Color Channel. … … 226 274 this->specular[2] = b; 227 275 this->specular[3] = 1.0; 228 276 } 229 277 230 278 /** … … 285 333 // MAPPING // 286 334 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 352 * @param dMap the Name of the Image to Use 353 */ 354 void Material::setDiffuseMap(const std::string& dMap, GLenum target, unsigned int textureNumber) 355 { 356 assert(textureNumber < Material::getMaxTextureUnits()); 357 358 PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str()); 359 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 360 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 361 362 if (this->textures.size() <= textureNumber) 363 this->textures.resize(textureNumber+1, NULL); 364 365 //! @todo check if RESOURCE MANAGER is availiable 366 if (!dMap.empty()) 367 { 368 369 this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 370 } 371 else 372 { 373 this->textures[textureNumber] = NULL; 374 } 375 } 376 287 377 /** 288 378 * Sets the Materials Diffuse Map 289 * @param dMap the Name of the Image to Use 290 */ 291 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 292 { 293 PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str()); 294 if (this->diffuseTexture != NULL) 295 ResourceManager::getInstance()->unload(this->diffuseTexture); 296 297 //! @todo check if RESOURCE MANAGER is availiable 298 //! @todo Textures from .mtl-file need special care. 299 if (!dMap.empty()) 300 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 379 * @param surface pointer to SDL_Surface which shall be used as texture 380 */ 381 void Material::setSDLDiffuseMap(SDL_Surface *surface, GLenum target, unsigned int textureNumber) 382 { 383 assert(textureNumber < Material::getMaxTextureUnits()); 384 385 386 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 387 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 388 389 if (this->textures.size() <= textureNumber) 390 this->textures.resize(textureNumber+1, NULL); 391 392 if(surface != NULL) 393 { 394 this->textures[textureNumber] = new Texture(surface, GL_TEXTURE_2D); 395 } 301 396 else 302 this->diffuseTexture = NULL; 303 } 397 { 398 this->textures[textureNumber] = NULL; 399 } 400 401 } 402 304 403 305 404 /** … … 332 431 void Material::setBump(const std::string& bump) 333 432 { 334 335 } 433 } 434 435 436 437 int Material::getMaxTextureUnits() 438 { 439 int maxTexUnits = 0; 440 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits); 441 return maxTexUnits; 442 } -
trunk/src/lib/graphics/importer/material.h
r7221 r7785 1 1 /*! 2 \file material.h3 \brief Contains the Material Class that handles Material for 3D-Objects.4 @todo free SDL-surface when deleting Material.5 @todo delete imgNameWithPath after use creation.6 */2 * @file material.h 3 * @brief Contains the Material Class that handles Material for 3D-Objects. 4 * @todo free SDL-surface when deleting Material. 5 * @todo delete imgNameWithPath after use creation. 6 */ 7 7 8 8 #ifndef _MATERIAL_H … … 10 10 #include "base_object.h" 11 11 12 12 13 #if HAVE_CONFIG_H 13 14 #include <config.h> 14 15 #endif /* HAVE_CONFIG_H */ 15 16 16 #ifndef NULL 17 #define NULL 0 //!< a pointer to NULL 18 #endif 17 #include <vector> 18 #include "SDL_image.h" 19 19 20 20 #include "texture.h" … … 25 25 class Material : public BaseObject 26 26 { 27 public:28 Material (const std::string& mtlName = "");29 virtual ~Material ();27 public: 28 Material (const std::string& mtlName = ""); 29 virtual ~Material (); 30 30 31 Material& operator=(const Material& material);31 Material& operator=(const Material& material); 32 32 33 bool select () const;33 bool select () const; 34 34 35 void setIllum (int illum); 36 void setIllum (char* illum); 37 int getIllumModel() const { return this->illumModel; }; 38 void setDiffuse (float r, float g, float b); 39 void setDiffuse (char* rgb); 40 void setAmbient (float r, float g, float b); 41 void setAmbient (char* rgb); 42 void setSpecular (float r, float g, float b); 43 void setSpecular (char* rgb); 44 void setShininess (float shini); 45 void setShininess (char* shini); 46 void setTransparency (float trans); 47 void setTransparency (char* trans); 48 void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; 35 void setIllum (int illum); 36 int getIllumModel() const { return this->illumModel; }; 37 void setDiffuse (float r, float g, float b); 38 void setAmbient (float r, float g, float b); 39 void setSpecular (float r, float g, float b); 40 void setShininess (float shini); 41 void setTransparency (float trans); 42 void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; 49 43 50 // MAPPING //51 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D);52 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);53 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);54 void setBump(const std::string& bump);55 GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; };56 44 57 static void addTexturePath(const std::string& pathName); 45 // TODO Move them out of here 46 void setIllum (char* illum); 47 void setDiffuse (char* rgb); 48 void setAmbient (char* rgb); 49 void setSpecular (char* rgb); 50 void setShininess (char* shini); 51 void setTransparency (char* trans); 52 53 54 // MAPPING // 55 void setDiffuseMap(Texture* texture, unsigned int textureNumber = 0); 56 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 57 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 58 59 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 60 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 61 void setBump(const std::string& bump); 62 GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i]->getTexture() : 0; }; 63 64 static void addTexturePath(const std::string& pathName); 65 66 public: 67 static const GLenum glTextureArbs[]; //!< The Texture ARB's 68 69 static int getMaxTextureUnits(); 58 70 59 71 private: 60 int illumModel; //!< The IlluminationModel is either flat or smooth. 61 float diffuse [4]; //!< The diffuse color of the Material. 62 float ambient [4]; //!< The ambient color of the Material. 63 float specular [4]; //!< The specular color of the Material. 64 float shininess; //!< The shininess of the Material. 65 float transparency; //!< The transperency of the Material. 66 GLenum sFactor; 67 GLenum tFactor; 72 static const Material* selectedMaterial; //!< The currently selected material. 68 73 69 Texture* diffuseTexture; //!< The diffuse texture of the Material. 70 Texture* ambientTexture; //!< The ambient texture of the Material. 71 Texture* specularTexture; //!< The specular texture of the Material. 74 int illumModel; //!< The IlluminationModel is either flat or smooth. 75 float diffuse [4]; //!< The diffuse color of the Material. 76 float ambient [4]; //!< The ambient color of the Material. 77 float specular [4]; //!< The specular color of the Material. 78 float shininess; //!< The shininess of the Material. 79 float transparency; //!< The transperency of the Material. 80 GLenum sFactor; 81 GLenum tFactor; 82 83 std::vector<Texture*> textures; //!< An Array of Textures. 84 85 Texture* ambientTexture; //!< The ambient texture of the Material. 86 Texture* specularTexture; //!< The specular texture of the Material. 87 88 72 89 }; 73 90 #endif -
trunk/src/lib/graphics/importer/texture.cc
r7751 r7785 20 20 #include "debug.h" 21 21 #include "compiler.h" 22 #include <math.h>23 22 24 23 // INCLUDING SDL_Image … … 29 28 #endif 30 29 31 /** 32 * @brief Constructor for a Texture 33 */ 34 Texture::Texture(const std::string& imageName, GLenum target) 35 { 36 this->setClassID(CL_TEXTURE, "Texture"); 37 30 31 TextureData::TextureData() 32 { 38 33 this->bAlpha = false; 39 34 this->texture = 0; 40 35 this->image = NULL; 41 this->priority = 0.5;42 43 if (!imageName.empty())44 {45 this->setName(imageName);46 this->loadImage(imageName, target);47 }48 36 } 49 37 … … 52 40 * @brief Destructor of a Texture 53 41 * 54 * Frees Data, and deletes the textures from GL55 */ 56 Texture ::~Texture()42 * Frees Data, and deletes the textures from GL 43 */ 44 TextureData::~TextureData() 57 45 { 58 46 if (this->texture != 0) … … 64 52 65 53 /** 54 * @brief Loads an SDL_Surface. 55 */ 56 bool TextureData::loadSurface(SDL_Surface* surface, GLenum target) 57 { 58 if (Texture::getTextureEnableState()) 59 { 60 SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha); 61 if (newSurf != NULL) 62 { 63 this->setSurface(newSurf); 64 this->setTexture(Texture::loadTexToGL(newSurf, target)); 65 return true; 66 } 67 } 68 return false; 69 } 70 71 72 73 /** 74 * @brief set the surface this Texture handles 75 * @param newSurface the new Surface to set as the image for this Texture. 76 * 77 * This deletes the old version of the stored Texture, 78 * and sets the newly given Surface as current. 79 */ 80 bool TextureData::setSurface(SDL_Surface* newSurface) 81 { 82 if (this->image != NULL) 83 SDL_FreeSurface(this->image); 84 85 this->image = newSurface; 86 87 return (this->image != NULL); 88 } 89 90 91 92 bool TextureData::setTexture(GLuint texture) 93 { 94 // unload the old Texture. 95 if (this->texture != 0 && glIsTexture(this->getTexture())) 96 { 97 glDeleteTextures(1, &this->texture); 98 } 99 this->texture = texture; 100 return (texture != 0); 101 } 102 103 104 105 106 107 Texture::Texture(GLenum target) 108 { 109 this->init(); 110 GLuint texture; 111 this->generateTexture(texture, target); 112 this->data->setTexture(texture); 113 } 114 115 /** 116 * Constructor for a Texture 117 */ 118 Texture::Texture(const std::string& imageName, GLenum target) 119 { 120 this->init(); 121 122 if (!imageName.empty()) 123 { 124 this->setName(imageName); 125 this->loadImage(imageName, target); 126 } 127 } 128 129 130 131 Texture::Texture(SDL_Surface* surface, GLenum target) 132 { 133 this->init(); 134 135 if(surface != NULL) 136 { 137 this->data->loadSurface(surface, target); 138 } 139 } 140 141 void Texture::init() 142 { 143 this->setClassID(CL_TEXTURE, "Texture"); 144 145 this->data = CountPointer<TextureData>(new TextureData()); 146 147 this->priority = 0.5; 148 } 149 150 /** 151 * @brief Destructor of a Texture 152 * 153 * Frees Data, and deletes the textures from GL 154 */ 155 Texture::~Texture() 156 { 157 } 158 159 160 /** 66 161 * @brief loads an Image from a file to a Texture 67 162 * @param imageName The image to load … … 71 166 if (Texture::texturesEnabled) 72 167 { 73 if (this->image != NULL)74 {75 SDL_FreeSurface(this->image);76 this->image = NULL;77 }78 if (this->texture != 0)79 {80 glDeleteTextures(1, &this->texture);81 this->texture = 0;82 }83 168 if (!imageName.empty()) 84 169 { 85 170 SDL_Surface* tmpSurf; 86 if (this->texture != 0 && glIsTexture(this->texture)) 87 glDeleteTextures(1, &this->texture); 171 88 172 // load the new Image to memory 89 173 tmpSurf = IMG_Load(imageName.c_str()); 90 174 if(tmpSurf != NULL) 91 175 { 92 PRINTF(4)("loading Image %s\n", imageName.c_str()); 93 bool hasAlpha; 94 SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha); 95 if (newSurf != NULL) 96 { 97 this->setSurface(newSurf); 98 this->setAlpha(hasAlpha); 99 this->setTexture(Texture::loadTexToGL(newSurf, target)); 100 } 101 176 this->data->loadSurface(tmpSurf, target); 102 177 SDL_FreeSurface(tmpSurf); 103 178 return true; … … 106 181 { 107 182 PRINTF(1)("IMG_Load: %s\n", IMG_GetError()); 108 this-> texture = 0;183 this->setTexture(0); 109 184 return false; 110 185 } … … 119 194 } 120 195 121 122 196 /** 123 197 * @brief rebuilds the texture. … … 127 201 bool Texture::rebuild() 128 202 { 129 if (this->texture != 0) 130 { 131 if (glIsTexture(this->texture)) 132 glDeleteTextures(1,&this->texture); 133 this->setTexture(0); 134 } 135 136 if (this->image != NULL) 203 this->data->setTexture(0); 204 205 if (this->data->getStoredImage() != NULL) 137 206 { 138 207 PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName()); 139 this->setTexture(loadTexToGL(this->image)); 140 } 141 } 142 143 144 /** 145 * @brief set the surface this Texture handles 146 * @param newSurface the new Surface to set as the image for this Texture. 147 * 148 * This deletes the old version of the stored Texture, 149 * and sets the newly given Surface as current. 150 */ 151 bool Texture::setSurface(SDL_Surface* newSurface) 152 { 153 if (this->image != NULL) 154 SDL_FreeSurface(this->image); 155 156 this->image = newSurface; 157 158 return (this->image != NULL); 159 } 160 208 this->setTexture(Texture::loadTexToGL(this->data->getStoredImage())); 209 } 210 } 161 211 162 212 bool Texture::texturesEnabled = true; … … 181 231 * @returns a !!new!! Surface, that is loadable by openGL. 182 232 */ 183 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const233 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) 184 234 { 185 235 assert(surface != NULL); … … 222 272 return NULL; 223 273 224 /* Copy the surface into the GL texture image*/274 /* Copy the surface into the GL texture this->data->getStoredImage() */ 225 275 area.x = 0; 226 276 area.y = 0; … … 245 295 * @returns The ID of the texture. 246 296 */ 247 GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target) const248 { 249 // if (this-> texture != 0 && glIsTexture(this->texture))250 // glDeleteTextures(1, &this-> texture);251 // this-> texture= 0;297 GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target) 298 { 299 // if (this->data->getTexture() != 0 && glIsTexture(this->data->getTexture())) 300 // glDeleteTextures(1, &this->data->getTexture()); 301 // this->data->getTexture() = 0; 252 302 assert(surface != NULL); 253 303 254 304 int errorCode = 0; //!< the error code for the texture loading functions 255 GLuint texture ;//!< the OpenGL texture handle305 GLuint texture = 0; //!< the OpenGL texture handle 256 306 int mipmapLevel = 0; //!< the maximum mipmap level for this texture 257 307 int mipmapWidth = 0; //!< the width of the mipmap 258 308 int mipmapHight = 0; //!< the height of the mipmap 259 309 GLenum format = GL_RGB; 260 if ( this->bAlpha)310 if (surface->format->BitsPerPixel == 32) 261 311 { 262 312 format = GL_RGBA; … … 268 318 } 269 319 270 /* Create an OpenGL texture for the image */ 271 glGenTextures(1, &texture); 272 glBindTexture(target, texture); 320 /* Create an OpenGL texture for the this->data->getStoredImage() */ 321 Texture::generateTexture(texture, target); 273 322 274 323 // glTexImage2D(target, 0, format, … … 277 326 // surface->pixels); 278 327 279 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 280 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 281 282 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/); 283 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 284 285 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority); 286 287 288 /* control the mipmap levels */ 289 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); 290 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 328 /// glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 329 /// glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 330 331 /// TODO CHECK THIS BACK in 332 //glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority); 291 333 292 334 /* build the Texture OpenGL V >= 1.1 */ … … 306 348 } 307 349 350 void Texture::generateTexture(GLuint& texture, GLenum target) 351 { 352 if (texture == 0 && !glIsTexture(texture)) 353 { 354 glGenTextures(1, &texture); 355 } 356 glBindTexture(target, texture); 357 358 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 359 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 360 361 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 362 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 363 364 /* control the mipmap levels */ 365 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); 366 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 367 } -
trunk/src/lib/graphics/importer/texture.h
r7727 r7785 10 10 11 11 #include "glincl.h" 12 #include "count_pointer.h" 12 13 13 14 /* Forward Declaration */ 14 15 struct SDL_Surface; 15 16 16 //! A Class, that reads in Textures from different fileformats.17 class Texture : public BaseObject18 {19 public:20 Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D);21 // Texture(TEXTURE_TYPE type, int resolution);22 virtual ~Texture();23 17 24 bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 25 virtual bool rebuild(); 18 class TextureData 19 { 20 public: 21 TextureData(); 22 ~TextureData(); 26 23 27 /** @returns The textureID of this texture. */ 28 inline GLuint getTexture() const { return this->texture; }; 29 /** @returns true if texture has alpha, false otherwise */ 30 inline bool hasAlpha() const {return bAlpha;} 31 /** @returns the stored image of this Texture */ 32 const SDL_Surface* const getStoredImage() const { return this->image; }; 24 inline GLuint getTexture() const { return this->texture; }; 25 /** @returns true if texture has alpha, false otherwise */ 26 inline bool hasAlpha() const {return this->bAlpha; } 27 /** @returns the stored image of this Texture */ 28 const SDL_Surface* const getStoredImage() const { return this->image; }; 29 30 bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 33 31 34 32 35 33 36 static void setTextureEnableState(bool texturesEnabled); 37 /** @returns true if Textures are enabled */ 38 inline static bool getTextureEnableState() { return Texture::texturesEnabled; }; 34 bool rebuild(); 39 35 40 // Utility functionality:41 SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha) const;42 GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D) const;36 bool setSurface(SDL_Surface* newSurface); 37 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; 38 bool setTexture(GLuint texture); 43 39 44 protected: 45 bool setSurface(SDL_Surface* newSurface); 46 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; 47 bool setTexture(GLuint texture) { this->texture = texture; }; 40 private: 41 GLuint texture; //!< The Texture-ID of opengl from this Texture. 42 bool bAlpha; //!< if the texture has an alpha channel. 43 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it. 44 }; 48 45 49 private:50 GLuint texture; //!< The Texture-ID of opengl from this Texture.51 bool bAlpha; //!< if the texture has an alpha channel.52 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it.53 GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem)54 46 55 static bool texturesEnabled; //!< If the Textures are enabled. 56 }; 47 //! A Class, that reads in Textures from different fileformats. 48 class Texture : public BaseObject 49 { 50 public: 51 52 public: 53 Texture(GLenum target = GL_TEXTURE_2D); 54 Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 55 Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 56 57 virtual ~Texture(); 58 59 bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 60 bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 61 virtual bool rebuild(); 62 63 /** @returns The textureID of this texture. */ 64 inline GLuint getTexture() const { return this->data->getTexture(); }; 65 /** @returns true if texture has alpha, false otherwise */ 66 inline bool hasAlpha() const { return this->data->hasAlpha(); } 67 /** @returns the stored image of this Texture */ 68 const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); }; 69 70 71 72 static void setTextureEnableState(bool texturesEnabled); 73 /** @returns true if Textures are enabled */ 74 inline static bool getTextureEnableState() { return Texture::texturesEnabled; }; 75 // Utility functionality: 76 static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha); 77 static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 78 79 protected: 80 bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); }; 81 bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); }; 82 bool setTexture(GLuint texture) { return this->data->setTexture(texture); }; 83 84 private: 85 void init(); 86 static void generateTexture(GLuint& texture, GLenum target); 87 88 private: 89 CountPointer<TextureData> data; //!< The TextureData 90 GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem) 91 92 static bool texturesEnabled; //!< If the Textures are enabled. 93 }; 57 94 58 95 #endif /* _TEXTURE_H */ -
trunk/src/lib/graphics/shader.h
r7221 r7785 47 47 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 48 48 49 GLhandleARB getProgram() { return this->shaderProgram; } 50 GLhandleARB getVertexS() { return this->vertexShader; } 51 GLhandleARB getFragmentS() { return this->fragmentShader; } 49 52 50 53 void printError(GLhandleARB program); -
trunk/src/lib/util/executor/functor_list.h
r7711 r7785 141 141 FUNCTOR_LIST(3)(l_STRING, l_FLOAT, l_UINT); 142 142 FUNCTOR_LIST(4)(l_STRING, l_FLOAT, l_UINT, l_UINT); 143 FUNCTOR_LIST(3)(l_STRING, l_INT, l_UINT); 144 FUNCTOR_LIST(3)(l_STRING, l_UINT, l_UINT); 143 145 144 146 #endif /* FUNCTOR_LIST */
Note: See TracChangeset
for help on using the changeset viewer.