Changeset 4662 in orxonox.OLD for orxonox/trunk/src/lib/graphics/importer
- Timestamp:
- Jun 23, 2005, 2:09:07 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/importer/texture.cc
r4370 r4662 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 21 21 #include "graphics_engine.h" 22 22 23 #ifdef HAVE_SDL_IMAGE_H 23 24 #include <SDL_image.h> 25 #else 26 #include <SDL/SDL_image.h> 27 #endif 24 28 25 29 /** … … 32 36 if (imageName) 33 37 this->loadImage(imageName); 34 } 38 } 35 39 36 40 /** 37 41 \brief Destructor of a Texture 38 42 39 43 Frees Data, and deletes the textures from GL 40 44 */ … … 62 66 Uint32 saved_flags; 63 67 Uint8 saved_alpha; 64 68 65 69 w = surface->w; 66 70 h = surface->h; 67 71 68 72 image = SDL_CreateRGBSurface(SDL_SWSURFACE, 69 w, h,70 32,73 w, h, 74 32, 71 75 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 72 0x000000FF, 73 0x0000FF00, 74 0x00FF0000, 75 0xFF00000076 0x000000FF, 77 0x0000FF00, 78 0x00FF0000, 79 0xFF000000 76 80 #else 77 0xFF000000,78 0x00FF0000, 79 0x0000FF00, 80 0x000000FF81 0xFF000000, 82 0x00FF0000, 83 0x0000FF00, 84 0x000000FF 81 85 #endif 82 );86 ); 83 87 if ( image == NULL ) { 84 return 0;88 return 0; 85 89 } 86 90 87 91 /* Save the alpha blending attributes */ 88 92 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); 89 93 saved_alpha = surface->format->alpha; 90 94 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 91 SDL_SetAlpha(surface, 0, 0);95 SDL_SetAlpha(surface, 0, 0); 92 96 } 93 97 94 98 /* Copy the surface into the GL texture image */ 95 99 area.x = 0; … … 98 102 area.h = surface->h; 99 103 SDL_BlitSurface(surface, &area, image, &area); 100 104 101 105 /* Restore the alpha blending attributes */ 102 106 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 103 SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);104 this->bAlpha = true;107 SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha); 108 this->bAlpha = true; 105 109 } 106 110 107 111 /* Create an OpenGL texture for the image */ 108 112 glGenTextures(1, &texture); … … 112 116 // build the Texture 113 117 glTexImage2D(GL_TEXTURE_2D, 114 0,115 GL_RGBA,116 w, h,117 0,118 GL_RGBA,119 GL_UNSIGNED_BYTE,120 image->pixels);118 0, 119 GL_RGBA, 120 w, h, 121 0, 122 GL_RGBA, 123 GL_UNSIGNED_BYTE, 124 image->pixels); 121 125 // build the MipMaps 122 126 gluBuild2DMipmaps(GL_TEXTURE_2D, 123 GL_RGBA,124 w,125 h,126 GL_RGBA,127 GL_UNSIGNED_BYTE,128 image->pixels);129 127 GL_RGBA, 128 w, 129 h, 130 GL_RGBA, 131 GL_UNSIGNED_BYTE, 132 image->pixels); 133 130 134 SDL_FreeSurface(image); /* No longer needed */ 131 135 132 136 return texture; 133 137 } … … 143 147 { 144 148 if (imageName) 145 {146 SDL_Surface* tmpSurf;147 if (this->texture)148 glDeleteTextures(1, &this->texture);149 // load the new Image to memory150 tmpSurf = IMG_Load(imageName);151 if(!tmpSurf)152 {153 PRINTF(1)("IMG_Load: %s\n", IMG_GetError());154 return false;155 }149 { 150 SDL_Surface* tmpSurf; 151 if (this->texture) 152 glDeleteTextures(1, &this->texture); 153 // load the new Image to memory 154 tmpSurf = IMG_Load(imageName); 155 if(!tmpSurf) 156 { 157 PRINTF(1)("IMG_Load: %s\n", IMG_GetError()); 158 return false; 159 } 156 160 157 GLubyte* pixels = (GLubyte*)tmpSurf->pixels;161 GLubyte* pixels = (GLubyte*)tmpSurf->pixels; 158 162 159 PRINTF(3)("loading Image %s\n", imageName);160 if (tmpSurf)161 this->texture = loadTexToGL(tmpSurf);163 PRINTF(3)("loading Image %s\n", imageName); 164 if (tmpSurf) 165 this->texture = loadTexToGL(tmpSurf); 162 166 163 164 SDL_FreeSurface(tmpSurf);165 return true;166 }167 168 SDL_FreeSurface(tmpSurf); 169 return true; 170 } 167 171 else 168 {169 PRINTF(2)("Image not Found: %s\n", imageName);170 return false;171 }172 { 173 PRINTF(2)("Image not Found: %s\n", imageName); 174 return false; 175 } 172 176 } 173 177 }
Note: See TracChangeset
for help on using the changeset viewer.










