Changeset 5955 in orxonox.OLD for branches/powerups/src/lib/graphics
- Timestamp:
- Dec 7, 2005, 1:05:10 PM (19 years ago)
- Location:
- branches/powerups/src/lib/graphics
- Files:
-
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/powerups/src/lib/graphics/graphics_engine.cc
r5819 r5955 26 26 #include "debug.h" 27 27 28 #include " ini_parser.h"28 #include "parser/ini_parser/ini_parser.h" 29 29 #include "substring.h" 30 30 #include "text.h" 31 31 32 32 #include "globals.h" 33 #include "texture.h" 33 34 34 35 #ifdef __WIN32__ 35 36 #include "class_list.h" 36 #include "texture.h"37 37 #include "list.h" 38 38 #include "model.h" … … 131 131 const char* textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0"); 132 132 if (strchr(textures, '1') || !strcasecmp(textures, "true")) 133 this->texturesEnabled = true;133 Texture::setTextureEnableState( true); 134 134 else 135 this->texturesEnabled = false;135 Texture::setTextureEnableState(false); 136 136 137 137 // searching for a usefull resolution … … 365 365 366 366 /** 367 * if Textures should be enabled368 */369 bool GraphicsEngine::texturesEnabled = true;370 371 /**372 367 * 373 368 * @param show if The mouse-cursor should be visible -
branches/powerups/src/lib/graphics/graphics_engine.h
r5366 r5955 83 83 84 84 public: 85 static bool texturesEnabled; //!< if textures should be enabled (globally)86 87 85 88 86 private: -
branches/powerups/src/lib/graphics/importer/Makefile.am
r5463 r5955 9 9 md2Model.cc \ 10 10 material.cc \ 11 texture.cc 11 texture.cc \ 12 texture_sequence.cc 12 13 13 14 … … 20 21 material.h \ 21 22 texture.h \ 23 texture_sequence.h \ 22 24 anorms.h \ 23 25 anormtab.h -
branches/powerups/src/lib/graphics/importer/material.h
r5405 r5955 51 51 static void addTexturePath(const char* pathName); 52 52 53 private:54 int illumModel; //!< The IlluminationModel is either flat or smooth.55 float diffuse [4]; //!< The diffuse color of the Material.56 float ambient [4]; //!< The ambient color of the Material.57 float specular [4]; //!< The specular color of the Material.58 float shininess; //!< The shininess of the Material.59 float transparency; //!< The transperency of the Material.53 private: 54 int illumModel; //!< The IlluminationModel is either flat or smooth. 55 float diffuse [4]; //!< The diffuse color of the Material. 56 float ambient [4]; //!< The ambient color of the Material. 57 float specular [4]; //!< The specular color of the Material. 58 float shininess; //!< The shininess of the Material. 59 float transparency; //!< The transperency of the Material. 60 60 public: 61 Texture* diffuseTexture; //!< The diffuse texture of the Material.62 Texture* ambientTexture; //!< The ambient texture of the Material.63 Texture* specularTexture; //!< The specular texture of the Material.61 Texture* diffuseTexture; //!< The diffuse texture of the Material. 62 Texture* ambientTexture; //!< The ambient texture of the Material. 63 Texture* specularTexture; //!< The specular texture of the Material. 64 64 }; 65 65 #endif -
branches/powerups/src/lib/graphics/importer/texture.cc
r5790 r5955 19 19 20 20 #include "debug.h" 21 #include "graphics_engine.h" 22 21 22 // INCLUDING SDL_Image 23 23 #ifdef HAVE_SDL_IMAGE_H 24 24 #include <SDL_image.h> … … 45 45 } 46 46 47 47 48 /** 48 49 * Destructor of a Texture … … 65 66 bool Texture::loadImage(const char* imageName) 66 67 { 67 if ( GraphicsEngine::texturesEnabled)68 if (Texture::texturesEnabled) 68 69 { 69 70 if (this->image != NULL) … … 80 81 { 81 82 SDL_Surface* tmpSurf; 82 if (this->texture )83 if (this->texture != 0 && glIsTexture(this->texture)) 83 84 glDeleteTextures(1, &this->texture); 84 85 // load the new Image to memory … … 87 88 { 88 89 PRINTF(4)("loading Image %s\n", imageName); 89 if (this->prepareSurface(tmpSurf)) 90 loadTexToGL(); 90 bool hasAlpha; 91 SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha); 92 if (newSurf != NULL) 93 { 94 this->setSurface(newSurf); 95 this->setAlpha(hasAlpha); 96 this->setTexture(Texture::loadTexToGL(newSurf)); 97 } 98 91 99 SDL_FreeSurface(tmpSurf); 92 100 return true; … … 108 116 } 109 117 118 119 /** 120 * rebuilds the texture. 121 * reloads the Texture from Memory to OpenGL. 122 */ 110 123 bool Texture::rebuild() 111 124 { 112 125 if (this->texture != 0) 113 126 { 114 glDeleteTextures(1,&this->texture); 115 this->texture = 0; 127 if (glIsTexture(this->texture)) 128 glDeleteTextures(1,&this->texture); 129 this->setTexture(0); 116 130 } 117 131 … … 119 133 { 120 134 PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName()); 121 this-> loadTexToGL();135 this->setTexture(loadTexToGL(this->image)); 122 136 } 123 124 } 125 137 } 138 139 140 /** 141 * set the surface this Texture handles 142 * @param newSurface the new Surface to set as the image for this Texture. 143 * 144 * This deletes the old version of the stored Texture, 145 * and sets the newly given Surface as current. 146 */ 147 bool Texture::setSurface(SDL_Surface* newSurface) 148 { 149 if (this->image != NULL) 150 SDL_FreeSurface(this->image); 151 152 this->image = newSurface; 153 154 return (this->image != NULL); 155 } 156 157 158 bool Texture::texturesEnabled = true; 159 160 /** 161 * enables, disables textures 162 * @param texturesEnabled true if the textures should be enabled 163 */ 164 void Texture::setTextureEnableState(bool texturesEnabled) 165 { 166 Texture::texturesEnabled = texturesEnabled; 167 } 168 169 170 ////////////////////////////////////// 171 // UTILITY FUNCTIONALITY OF TEXTURE // 172 ////////////////////////////////////// 126 173 /** 127 174 * converts surface to a new SDL_Surface, that is loadable by openGL 128 175 * @param surface the Surface to convert 176 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false. 129 177 * @returns a !!new!! Surface, that is loadable by openGL. 130 178 */ 131 bool Texture::prepareSurface(SDL_Surface* surface)179 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) 132 180 { 133 181 PRINTF(4)("Loading texture to OpenGL-Environment.\n"); 134 182 135 SDL_Surface* putSurface;183 SDL_Surface* retSurface; 136 184 SDL_Rect area; 137 185 Uint32 saved_flags; 138 186 Uint8 saved_alpha; 139 187 140 putSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 141 surface->w, surface->h, 142 32, 188 hasAlpha = false; 189 retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 190 surface->w, surface->h, 191 32, 143 192 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 144 193 0x000000FF, … … 147 196 0xFF000000 148 197 #else 149 0xFF000000,198 0xFF000000, 150 199 0x00FF0000, 151 200 0x0000FF00, 152 201 0x000000FF 153 202 #endif 154 );155 if ( putSurface == NULL )203 ); 204 if ( retSurface == NULL ) 156 205 { 157 this->setSurface(NULL); 158 return false; 206 return NULL; 159 207 } 160 208 … … 171 219 area.w = surface->w; 172 220 area.h = surface->h; 173 SDL_BlitSurface(surface, &area, putSurface, &area);221 SDL_BlitSurface(surface, &area, retSurface, &area); 174 222 175 223 /* Restore the alpha blending attributes */ … … 177 225 { 178 226 SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha); 179 this->bAlpha = true; 180 } 181 182 return (this->setSurface(putSurface)); 183 } 184 185 bool Texture::setSurface(SDL_Surface* newSurface) 186 { 187 if (this->image != NULL) 188 SDL_FreeSurface(this->image); 189 190 this->image = newSurface; 191 192 return (this->image != NULL); 227 hasAlpha = true; 228 } 229 230 return (retSurface); 193 231 } 194 232 … … 199 237 * @returns The ID of the texture. 200 238 */ 201 GLuint Texture::loadTexToGL () 202 { 203 if (this->texture != 0 && glIsTexture(this->texture)) 204 glDeleteTextures(1, &this->texture); 205 this->texture = 0; 206 207 if (this->image == NULL) 239 GLuint Texture::loadTexToGL (const SDL_Surface* surface) 240 { 241 // if (this->texture != 0 && glIsTexture(this->texture)) 242 // glDeleteTextures(1, &this->texture); 243 // this->texture = 0; 244 245 GLuint texture; 246 247 if (surface == NULL) 208 248 return 0; 209 249 210 250 /* Create an OpenGL texture for the image */ 211 glGenTextures(1, &t his->texture);212 glBindTexture(GL_TEXTURE_2D, t his->texture);251 glGenTextures(1, &texture); 252 glBindTexture(GL_TEXTURE_2D, texture); 213 253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 214 254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); … … 217 257 0, 218 258 GL_RGBA, 219 this->image->w, this->image->h,259 surface->w, surface->h, 220 260 0, 221 261 GL_RGBA, 222 262 GL_UNSIGNED_BYTE, 223 this->image->pixels);263 surface->pixels); 224 264 // build the MipMaps 225 265 gluBuild2DMipmaps(GL_TEXTURE_2D, 226 266 GL_RGBA, 227 this->image->w,228 this->image->h,267 surface->w, 268 surface->h, 229 269 GL_RGBA, 230 270 GL_UNSIGNED_BYTE, 231 this->image->pixels);271 surface->pixels); 232 272 glBindTexture(GL_TEXTURE_2D, 0); 233 return t his->texture;234 } 273 return texture; 274 } -
branches/powerups/src/lib/graphics/importer/texture.h
r5768 r5955 14 14 struct SDL_Surface; 15 15 16 //! an enumerator for different procedural texture-types17 typedef enum TEXTURE_TYPE { TEXTURE_RADIAL_ALIAS,18 TEXTURE_NOISE };19 20 16 //! A Class, that reads in Textures from different fileformats. 21 17 class Texture : public BaseObject … … 27 23 28 24 bool loadImage(const char* imageName); 29 bool rebuild();25 virtual bool rebuild(); 30 26 31 27 /** @returns The textureID of this texture. */ … … 33 29 /** @returns true if texture has alpha, false otherwise */ 34 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; }; 33 34 35 36 static void setTextureEnableState(bool texturesEnabled); 37 /** @returns true if Textures are enabled */ 38 inline static bool getTextureEnableState() { return Texture::texturesEnabled; }; 39 40 // Utility functionality: 41 static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha); 42 static GLuint loadTexToGL (const SDL_Surface* surface); 35 43 36 44 protected: 37 bool prepareSurface(SDL_Surface* input); 45 38 46 bool setSurface(SDL_Surface* newSurface); 47 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; 48 bool setTexture(GLuint texture) { this->texture = texture; }; 39 49 40 GLuint loadTexToGL ();41 50 42 51 private: 43 GLuint texture; //!< The Texture-ID of opengl from this Texture. 44 bool bAlpha; //!< if the texture has an alpha channel. 45 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it. 52 GLuint texture; //!< The Texture-ID of opengl from this Texture. 53 bool bAlpha; //!< if the texture has an alpha channel. 54 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it. 55 56 static bool texturesEnabled; //!< If the Textures are enabled. 46 57 }; 47 58 -
branches/powerups/src/lib/graphics/light.cc
r5750 r5955 22 22 #include "glincl.h" 23 23 #include "vector.h" 24 #include " tinyxml.h"24 #include "parser/tinyxml/tinyxml.h" 25 25 #include "load_param.h" 26 26 #include "factory.h" -
branches/powerups/src/lib/graphics/render2D/element_2d.cc
r5783 r5955 23 23 #include "graphics_engine.h" 24 24 #include "load_param.h" 25 #include " tinyxml.h"25 #include "parser/tinyxml/tinyxml.h" 26 26 #include "class_list.h" 27 27 -
branches/powerups/src/lib/graphics/text_engine/font.cc
r5768 r5955 181 181 this->fontTTF = NULL; 182 182 } 183 if (this->prepareSurface(surface)) 184 this->loadTexToGL( ); 183 bool hasAlpha; 184 SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha); 185 if (newSurf != NULL) 186 { 187 this->setSurface(newSurf); 188 this->setAlpha(hasAlpha); 189 this->setTexture(Texture::loadTexToGL(newSurf)); 190 } 185 191 186 192 // initializing the Glyphs. … … 491 497 492 498 if (this->setSurface(tmpSurf)) 493 loadTexToGL();499 (this->setTexture(Texture::loadTexToGL(tmpSurf))); 494 500 } 495 501 -
branches/powerups/src/lib/graphics/text_engine/text_engine.cc
r5780 r5955 64 64 { 65 65 // first remove all the remaining Texts (if any). 66 std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT);66 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 67 67 if (textList != NULL) 68 68 { … … 71 71 } 72 72 // delete all remaining fonts (There should not be Anything to do here) 73 std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT);73 const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 74 74 if (fontList != NULL) 75 75 { … … 124 124 void TextEngine::debug() const 125 125 { 126 list<BaseObject*>* textList = ClassList::getList(CL_TEXT);126 const list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 127 127 if (textList != NULL) 128 128 { … … 132 132 PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->size()); 133 133 134 list<BaseObject*>:: iterator text;134 list<BaseObject*>::const_iterator text; 135 135 for ( text = textList->begin(); text != textList->end(); text++) 136 136 dynamic_cast<Text*>(*text)->debug();
Note: See TracChangeset
for help on using the changeset viewer.