Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6139 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
Dec 16, 2005, 6:45:32 PM (18 years ago)
Author:
patrick
Message:

trunk: merged branche network with trunk using command: svn merge -r5999:HEAD, conflicts resolved in favor of the trunk bla

Location:
trunk/src/lib/graphics/importer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/texture.cc

    r5863 r6139  
    1919
    2020#include "debug.h"
     21#include "compiler.h"
     22#include <math.h>
    2123
    2224// INCLUDING SDL_Image
     
    3739  this->texture = 0;
    3840  this->image = NULL;
     41  this->priority = 0.5;
    3942
    4043  if (imageName != NULL)
     
    177180 * @returns a !!new!! Surface, that is loadable by openGL.
    178181 */
    179 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
     182SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
    180183{
    181184  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
     
    237240 * @returns The ID of the texture.
    238241 */
    239 GLuint Texture::loadTexToGL (const SDL_Surface* surface)
     242GLuint Texture::loadTexToGL (const SDL_Surface* surface) const
    240243{
    241244//   if (this->texture != 0 && glIsTexture(this->texture))
     
    243246//   this->texture = 0;
    244247
    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
    246254
    247255  if (surface == NULL)
     
    251259  glGenTextures(1, &texture);
    252260  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 */
    256270  glTexImage2D(GL_TEXTURE_2D,
    257271               0,
     
    262276               GL_UNSIGNED_BYTE,
    263277               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
    272310  glBindTexture(GL_TEXTURE_2D, 0);
    273311  return texture;
    274312}
     313
  • trunk/src/lib/graphics/importer/texture.h

    r5859 r6139  
    3939
    4040      // 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;
    4343
    4444    protected:
     
    5353      bool             bAlpha;             //!< if the texture has an alpha channel.
    5454      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)
    5556
    5657      static bool      texturesEnabled;    //!< If the Textures are enabled.
Note: See TracChangeset for help on using the changeset viewer.