Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6136 in orxonox.OLD for branches


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

network: further work on the texture class. mipmap loading on the right wa

Location:
branches/network/src/lib/graphics/importer
Files:
2 edited

Legend:

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

    r6129 r6136  
    1919
    2020#include "debug.h"
     21#include "compiler.h"
     22#include <math.h>
    2123
    2224// INCLUDING SDL_Image
     
    178180 * @returns a !!new!! Surface, that is loadable by openGL.
    179181 */
    180 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
     182SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
    181183{
    182184  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
     
    238240 * @returns The ID of the texture.
    239241 */
    240 GLuint Texture::loadTexToGL (const SDL_Surface* surface)
     242GLuint Texture::loadTexToGL (const SDL_Surface* surface) const
    241243{
    242244//   if (this->texture != 0 && glIsTexture(this->texture))
     
    244246//   this->texture = 0;
    245247
    246   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
    247254
    248255  if (surface == NULL)
     
    260267  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
    261268
    262   // build the Texture
     269  /* build the Texture  OpenGL V >= 1.1 */
    263270  glTexImage2D(GL_TEXTURE_2D,
    264271               0,
     
    271278
    272279  // build the MipMaps automaticaly
    273   gluBuild2DMipmaps(GL_TEXTURE_2D,
    274                     GL_RGBA,
    275                     surface->w,
    276                     surface->h,
    277                     GL_RGBA,
    278                     GL_UNSIGNED_BYTE,
    279                     surface->pixels);
     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, mipmapHeight);
     300  glTexImage2D(GL_PROXY_TEXTURE_2D,
     301               1,
     302               GL_RGBA,
     303               mipmapWidth, mipmapHeight,
     304               0,
     305               GL_RGBA,
     306               GL_UNSIGNED_BYTE,
     307               NULL
     308               );
     309
    280310  glBindTexture(GL_TEXTURE_2D, 0);
    281311  return texture;
  • branches/network/src/lib/graphics/importer/texture.h

    r6129 r6136  
    3939
    4040      // Utility functionality:
    41       SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
    42       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:
Note: See TracChangeset for help on using the changeset viewer.