Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7727 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
May 19, 2006, 2:25:15 PM (19 years ago)
Author:
bensch
Message:

trunk: some GL-properties for the Textures

Location:
trunk/src/lib/graphics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/graphics_engine.cc

    r7661 r7727  
    210210
    211211  // setting the Video Flags.
    212   this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_GL_DOUBLEBUFFER;
     212  this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE ;
    213213
    214214  /* query SDL for information about our video hardware */
     
    281281  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
    282282  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
     283
     284  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);      //Use at least 5 bits of Red
     285  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);    //Use at least 5 bits of Green
     286  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);     //Use at least 5 bits of Blue
     287  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);   //Use at least 16 bits for the depth buffer
     288  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);  //Enable double buffering
    283289}
    284290
  • trunk/src/lib/graphics/importer/texture.cc

    r7676 r7727  
    3030
    3131/**
    32  * Constructor for a Texture
     32 * @brief Constructor for a Texture
    3333*/
    3434Texture::Texture(const std::string& imageName, GLenum target)
     
    5050
    5151/**
    52  * Destructor of a Texture
    53 
    54    Frees Data, and deletes the textures from GL
    55 */
     52 * @brief Destructor of a Texture
     53 *
     54 * Frees Data, and deletes the textures from GL
     55 */
    5656Texture::~Texture()
    5757{
     
    6464
    6565/**
    66  * loads an Image from a file to a Texture
     66 * @brief loads an Image from a file to a Texture
    6767 * @param imageName The image to load
    6868*/
     
    121121
    122122/**
    123  * rebuilds the texture.
     123 * @brief rebuilds the texture.
     124 *
    124125 * reloads the Texture from Memory to OpenGL.
    125126 */
     
    142143
    143144/**
    144  * set the surface this Texture handles
     145 * @brief set the surface this Texture handles
    145146 * @param newSurface the new Surface to set as the image for this Texture.
    146147 *
     
    162163
    163164/**
    164  * enables, disables textures
     165 * @brief enables, disables textures
    165166 * @param texturesEnabled true if the textures should be enabled
    166167 */
     
    175176//////////////////////////////////////
    176177/**
    177  * converts surface to a new SDL_Surface, that is loadable by openGL
     178 * @brief converts surface to a new SDL_Surface, that is loadable by openGL
    178179 * @param surface the Surface to convert
    179180 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false.
     
    182183SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
    183184{
     185  assert(surface != NULL);
    184186  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
    185187
     
    190192
    191193  hasAlpha = false;
    192   retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
     194  int pixelDepth = 24;
     195
     196  /* Save the alpha blending attributes */
     197  saved_flags = surface->flags&(SDL_SRCALPHA | SDL_RLEACCELOK);
     198  saved_alpha = surface->format->alpha;
     199  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
     200  {
     201    SDL_SetAlpha(surface, 0, 0);
     202    hasAlpha = true;
     203    pixelDepth = 32;
     204  }
     205
     206  retSurface = SDL_CreateRGBSurface(SDL_HWSURFACE,
    193207                                    surface->w, surface->h,
    194                                     32,
     208                                    pixelDepth,
    195209#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    196210                                    0x000000FF,
     
    206220                                   );
    207221  if ( retSurface == NULL )
    208   {
    209222    return NULL;
    210   }
    211 
    212   /* Save the alpha blending attributes */
    213   saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    214   saved_alpha = surface->format->alpha;
    215   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
    216   {
    217     SDL_SetAlpha(surface, 0, 0);
    218   }
    219223
    220224  /* Copy the surface into the GL texture image */
     
    237241
    238242/**
    239  * Loads a Texture to the openGL-environment.
     243 * @brief Loads a Texture to the openGL-environment.
    240244 * @param surface the Image to load to openGL
    241245 * @returns The ID of the texture.
     
    246250  //     glDeleteTextures(1, &this->texture);
    247251  //   this->texture = 0;
     252  assert(surface != NULL);
    248253
    249254  int      errorCode = 0;           //!< the error code for the texture loading functions
     
    252257  int      mipmapWidth = 0;         //!< the width of the mipmap
    253258  int      mipmapHight = 0;         //!< the height of the mipmap
    254 
    255 
    256   if (surface == NULL)
    257     return 0;
     259  GLenum   format = GL_RGB;
     260  if (this->bAlpha)
     261  {
     262    format = GL_RGBA;
     263    assert(surface->format->BitsPerPixel == 32);
     264  }
     265  else
     266  {
     267    assert(surface->format->BitsPerPixel == 24);
     268  }
    258269
    259270  /* Create an OpenGL texture for the image */
     
    261272  glBindTexture(target, texture);
    262273
     274//   glTexImage2D(target,  0,  format,
     275//                surface->w,  surface->h,
     276//                0, format,  GL_UNSIGNED_BYTE,
     277//                surface->pixels);
     278
    263279  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
    264280  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
     
    275291
    276292  /* build the Texture  OpenGL V >= 1.1 */
    277   glTexImage2D(target,
    278                0,
    279                GL_RGBA,
    280                surface->w,
    281                surface->h,
    282                0,
    283                GL_RGBA,
    284                GL_UNSIGNED_BYTE,
    285                surface->pixels);
     293
    286294  //  printf("%s, w:%d h:%d, 0x%x\n", this->getName(), surface->w, surface->h, target);
    287295
    288296  // build the MipMaps automaticaly
    289   errorCode = gluBuild2DMipmaps(target,
    290                                 GL_RGBA,
    291                                 surface->w,
    292                                 surface->h,
    293                                 GL_RGBA,
    294                                 GL_UNSIGNED_BYTE,
     297  errorCode = gluBuild2DMipmaps(target, format,
     298                                surface->w,  surface->h,
     299                                format,  GL_UNSIGNED_BYTE,
    295300                                surface->pixels
    296301                               );
  • trunk/src/lib/graphics/importer/texture.h

    r7221 r7727  
    4343
    4444    protected:
    45 
    4645      bool setSurface(SDL_Surface* newSurface);
    4746      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
    4847      bool setTexture(GLuint texture) { this->texture = texture; };
    49 
    5048
    5149    private:
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r7342 r7727  
    123123  if (this->toDirection != NULL)
    124124    delete this->toDirection;
     125  if (this->toSize != NULL)
     126    delete this->toSize;
    125127
    126128  if (this == Element2D::nullElement)
  • trunk/src/lib/graphics/text_engine/font.cc

    r7450 r7727  
    427427  // Surface definition.
    428428  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
    429   SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_SWSURFACE,
     429  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_HWSURFACE,
    430430                          rectSize, rectSize,
    431431                          32,
     
    494494//       sprintf( outName, "%s-glyphs.bmp", this->getName());
    495495//       SDL_SaveBMP(tmpSurf, outName);
    496 
     496  this->setAlpha(true);
    497497  if (this->setSurface(tmpSurf))
    498498    (this->setTexture(Texture::loadTexToGL(tmpSurf)));
     
    500500
    501501/**
    502  * stores Glyph Metrics in an Array.
     502 * @brief stores Glyph Metrics in an Array.
    503503 * @param from The Glyph to start from.
    504504 * @param count The number of Glyphs to start From.
     
    535535/**
    536536 * @returns the optimal size to use as the texture size
    537 
    538    @todo: this algorithm can be a lot faster, althought it does
    539    not really matter within the init-context, and 128 glyphs.
    540 
    541    This function searches for a 2^n sizes texture-size, this is for
    542    openGL-version < 1.2 compatibility ( and because it is realy easy like this :))
     537 *
     538 * @todo: this algorithm can be a lot faster, althought it does
     539 * not really matter within the init-context, and 128 glyphs.
     540 *
     541 * This function searches for a 2^n sizes texture-size, this is for
     542 * openGL-version < 1.2 compatibility ( and because it is realy easy like this :))
    543543 */
    544544int Font::findOptimalFastTextureSize()
Note: See TracChangeset for help on using the changeset viewer.