Changeset 6139 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Dec 16, 2005, 6:45:32 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/texture.cc
r5863 r6139 19 19 20 20 #include "debug.h" 21 #include "compiler.h" 22 #include <math.h> 21 23 22 24 // INCLUDING SDL_Image … … 37 39 this->texture = 0; 38 40 this->image = NULL; 41 this->priority = 0.5; 39 42 40 43 if (imageName != NULL) … … 177 180 * @returns a !!new!! Surface, that is loadable by openGL. 178 181 */ 179 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) 182 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const 180 183 { 181 184 PRINTF(4)("Loading texture to OpenGL-Environment.\n"); … … 237 240 * @returns The ID of the texture. 238 241 */ 239 GLuint Texture::loadTexToGL (const SDL_Surface* surface) 242 GLuint Texture::loadTexToGL (const SDL_Surface* surface) const 240 243 { 241 244 // if (this->texture != 0 && glIsTexture(this->texture)) … … 243 246 // this->texture = 0; 244 247 245 GLuint texture; 248 int errorCode = 0; //!< the error code for the texture loading functions 249 GLuint texture; //!< the OpenGL texture handle 250 int mipmapLevel = 0; //!< the maximum mipmap level for this texture 251 int mipmapWidth = 0; //!< the width of the mipmap 252 int mipmapHight = 0; //!< the height of the mipmap 253 246 254 247 255 if (surface == NULL) … … 251 259 glGenTextures(1, &texture); 252 260 glBindTexture(GL_TEXTURE_2D, texture); 253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 255 // build the Texture 261 262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, /*GL_LINEAR*/ GL_LINEAR_MIPMAP_LINEAR); 263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, /*GL_LINEAR*/ GL_LINEAR); 264 /* control the mipmap levels */ 265 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, -100); 266 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 267 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority); 268 269 /* build the Texture OpenGL V >= 1.1 */ 256 270 glTexImage2D(GL_TEXTURE_2D, 257 271 0, … … 262 276 GL_UNSIGNED_BYTE, 263 277 surface->pixels); 264 // build the MipMaps 265 gluBuild2DMipmaps(GL_TEXTURE_2D, 266 GL_RGBA, 267 surface->w, 268 surface->h, 269 GL_RGBA, 270 GL_UNSIGNED_BYTE, 271 surface->pixels); 278 279 // build the MipMaps automaticaly 280 errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D, 281 GL_RGBA, 282 surface->w, 283 surface->h, 284 GL_RGBA, 285 GL_UNSIGNED_BYTE, 286 surface->pixels 287 ); 288 if(unlikely(errorCode != 0)) 289 PRINTF(1)("Error while loading texture, gluBuild2DMipmaps returned %i\n", errorCode); 290 291 #define max(a,b) (a>b)?a:b 292 mipmapLevel = (int)(log2f(max(surface->w, surface->h))); 293 #undef max 294 PRINTF(5)("Built the texture mipmpaps, got: %i levels of detail\n", mipmapLevel); 295 296 /* now actualy load the mipmaps into the graphics memory */ 297 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &mipmapWidth); 298 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &mipmapHight); 299 PRINTF(5)(" Mipmap at level %i has a %ix%i resolution\n", 1, mipmapWidth, mipmapHight); 300 glTexImage2D(GL_PROXY_TEXTURE_2D, 301 1, 302 GL_RGBA, 303 mipmapWidth, mipmapHight, 304 0, 305 GL_RGBA, 306 GL_UNSIGNED_BYTE, 307 NULL 308 ); 309 272 310 glBindTexture(GL_TEXTURE_2D, 0); 273 311 return texture; 274 312 } 313 -
trunk/src/lib/graphics/importer/texture.h
r5859 r6139 39 39 40 40 // Utility functionality: 41 static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);42 static GLuint loadTexToGL (const SDL_Surface* surface);41 SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha) const; 42 GLuint loadTexToGL (const SDL_Surface* surface) const; 43 43 44 44 protected: … … 53 53 bool bAlpha; //!< if the texture has an alpha channel. 54 54 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it. 55 GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem) 55 56 56 57 static bool texturesEnabled; //!< If the Textures are enabled.
Note: See TracChangeset
for help on using the changeset viewer.