Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5858 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Dec 1, 2005, 8:03:35 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: introducing multiframe-texture

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

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/Makefile.am

    r5463 r5858  
    99                           md2Model.cc \
    1010                           material.cc \
    11                            texture.cc
     11                           texture.cc \
     12                           multi_frame_texture.cc
    1213
    1314
     
    2021                 material.h \
    2122                 texture.h \
     23                 multi_frame_texture.h \
    2224                 anorms.h \
    2325                 anormtab.h
  • trunk/src/lib/graphics/importer/multi_frame_texture.cc

    r5856 r5858  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
    1717
    18 #include "texture.h"
     18#include "multi_frame_texture.h"
    1919
    2020#include "debug.h"
    2121#include "graphics_engine.h"
     22
     23#include <stdarg.h>
    2224
    2325#ifdef HAVE_SDL_IMAGE_H
     
    3032 *  Constructor for a Texture
    3133*/
    32 Texture::Texture(const char* imageName)
     34MultiFrameTexture::MultiFrameTexture(unsigned int count, ...)
    3335{
    3436  this->setClassID(CL_TEXTURE, "Texture");
    35 
    36   this->bAlpha = false;
    37   this->texture = 0;
    38   this->image = NULL;
    39 
    40   if (imageName != NULL)
    41   {
    42     this->setName(imageName);
    43     this->loadImage(imageName);
    44   }
    45 }
    46 
    47 /**
    48  *  Destructor of a Texture
    49 
    50    Frees Data, and deletes the textures from GL
    51 */
    52 Texture::~Texture()
    53 {
    54   if (this->texture != 0)
    55     glDeleteTextures(1, &this->texture);
    56   if (this->image != NULL)
    57     SDL_FreeSurface(this->image);
    58 }
    59 
    60 
    61 /**
    62  *  loads an Image from a file to a Texture
    63  * @param imageName The image to load
    64 */
    65 bool Texture::loadImage(const char* imageName)
    66 {
    67   if (GraphicsEngine::texturesEnabled)
    68     {
    69       if (this->image != NULL)
    70         {
    71           SDL_FreeSurface(this->image);
    72           this->image = NULL;
    73         }
    74       if (this->texture != 0)
    75         {
    76           glDeleteTextures(1, &this->texture);
    77           this->texture = 0;
    78         }
    79       if (imageName != NULL)
    80         {
    81           SDL_Surface* tmpSurf;
    82           if (this->texture != 0 && glIsTexture(this->texture))
    83             glDeleteTextures(1, &this->texture);
    84           // load the new Image to memory
    85           tmpSurf = IMG_Load(imageName);
    86           if(tmpSurf != NULL)
    87           {
    88             PRINTF(4)("loading Image %s\n", imageName);
    89             if (this->prepareSurface(tmpSurf))
    90               this->texture = Texture::loadTexToGL(this->image);
    91 
    92             SDL_FreeSurface(tmpSurf);
    93             return true;
    94           }
    95           else
    96             {
    97               PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
    98               this->texture = 0;
    99               return false;
    100             }
    101         }
    102       else
    103         {
    104           PRINTF(2)("Image-Name not specified\n");
    105           return false;
    106         }
    107     }
    108   return false;
    109 }
    110 
    111 bool Texture::rebuild()
    112 {
    113   if (this->texture != 0 && glIsTexture(this->texture))
    114     {
    115       glDeleteTextures(1,&this->texture);
    116       this->texture = 0;
    117     }
    118 
    119   if (this->image != NULL)
    120     {
    121       PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());
    122       this->texture = loadTexToGL(this->image);
    123     }
    12437
    12538}
    12639
    12740/**
    128  * converts surface to a new SDL_Surface, that is loadable by openGL
    129  * @param surface the Surface to convert
    130  * @returns a !!new!! Surface, that is loadable by openGL.
    131  */
    132 bool Texture::prepareSurface(SDL_Surface* surface)
     41 *  Destructor of a MultiFrameTexture
     42
     43   Frees Data, and deletes the textures from GL
     44*/
     45MultiFrameTexture::~MultiFrameTexture()
    13346{
    134   PRINTF(4)("Loading texture to OpenGL-Environment.\n");
    135 
    136   SDL_Surface* putSurface;
    137   SDL_Rect area;
    138   Uint32 saved_flags;
    139   Uint8  saved_alpha;
    140 
    141   putSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
    142                                surface->w, surface->h,
    143                                32,
    144 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    145                                0x000000FF,
    146                                0x0000FF00,
    147                                0x00FF0000,
    148                                0xFF000000
    149 #else
    150                                0xFF000000,
    151                                0x00FF0000,
    152                                0x0000FF00,
    153                                0x000000FF
    154 #endif
    155                                );
    156   if ( putSurface == NULL )
    157   {
    158     this->setSurface(NULL);
    159     return false;
    160   }
    161 
    162   /* Save the alpha blending attributes */
    163   saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    164   saved_alpha = surface->format->alpha;
    165   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    166     SDL_SetAlpha(surface, 0, 0);
    167   }
    168 
    169   /* Copy the surface into the GL texture image */
    170   area.x = 0;
    171   area.y = 0;
    172   area.w = surface->w;
    173   area.h = surface->h;
    174   SDL_BlitSurface(surface, &area, putSurface, &area);
    175 
    176   /* Restore the alpha blending attributes */
    177   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
    178   {
    179     SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
    180     this->bAlpha = true;
    181   }
    182 
    183   return (this->setSurface(putSurface));
    184 }
    185 
    186 bool Texture::setSurface(SDL_Surface* newSurface)
    187 {
    188   if (this->image != NULL)
    189     SDL_FreeSurface(this->image);
    190 
    191   this->image = newSurface;
    192 
    193   return (this->image != NULL);
    19447}
    19548
    19649
    197 /**
    198  *  Loads a Texture to the openGL-environment.
    199  * @param surface the Image to load to openGL
    200  * @returns The ID of the texture.
    201  */
    202 GLuint Texture::loadTexToGL (const SDL_Surface* surface)
     50
     51bool MultiFrameTexture::rebuild()
    20352{
    204 //   if (this->texture != 0 && glIsTexture(this->texture))
    205 //     glDeleteTextures(1, &this->texture);
    206 //   this->texture = 0;
     53//   if (this->texture != 0 && glIsMultiFrameTexture(this->texture))
     54//     {
     55//       glDeleteMultiFrameTextures(1,&this->texture);
     56//       this->texture = 0;
     57//     }
     58//
     59//   if (this->image != NULL)
     60//     {
     61//       PRINTF(3)("Reloading MultiFrameTexture of %s '%s'\n", this->getClassName(), this->getName());
     62//       this->texture = loadTexToGL(this->image);
     63//     }
    20764
    208   GLuint texture;
    209 
    210   if (surface == NULL)
    211     return 0;
    212 
    213   /* Create an OpenGL texture for the image */
    214   glGenTextures(1, &texture);
    215   glBindTexture(GL_TEXTURE_2D, texture);
    216   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    217   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    218   // build the Texture
    219   glTexImage2D(GL_TEXTURE_2D,
    220                0,
    221                GL_RGBA,
    222                surface->w, surface->h,
    223                0,
    224                GL_RGBA,
    225                GL_UNSIGNED_BYTE,
    226                surface->pixels);
    227   // build the MipMaps
    228   gluBuild2DMipmaps(GL_TEXTURE_2D,
    229                     GL_RGBA,
    230                     surface->w,
    231                     surface->h,
    232                     GL_RGBA,
    233                     GL_UNSIGNED_BYTE,
    234                     surface->pixels);
    235   glBindTexture(GL_TEXTURE_2D, 0);
    236   return texture;
    23765}
  • trunk/src/lib/graphics/importer/multi_frame_texture.h

    r5856 r5858  
    44 */
    55
    6 #ifndef _TEXTURE_H
    7 #define _TEXTURE_H
     6#ifndef _MULTI_FRAME_TEXTURE_H
     7#define _MULTI_FRAME_TEXTURE_H
    88
    9 #include "base_object.h"
     9#include "texture.h"
    1010
    1111#include "glincl.h"
     12#include <vector>
    1213
    1314/* Forward Declaration */
    1415struct SDL_Surface;
    1516
    16 //! an enumerator for different procedural texture-types
    17 typedef enum TEXTURE_TYPE { TEXTURE_RADIAL_ALIAS,
    18   TEXTURE_NOISE };
    19 
    2017//! A Class, that reads in Textures from different fileformats.
    21   class Texture : public BaseObject
     18  class MultiFrameTexture : public Texture
    2219  {
    2320    public:
    24       Texture(const char* imageName = NULL);
     21      MultiFrameTexture(unsigned int count, ...);
    2522  //  Texture(TEXTURE_TYPE type, int resolution);
    26       ~Texture();
     23      ~MultiFrameTexture();
    2724
    28       bool loadImage(const char* imageName);
     25      bool loadImages(unsigned int cound, ...);
    2926      bool rebuild();
    3027
    3128      /** @returns The textureID of this texture.  */
    32       inline GLuint getTexture() const { return this->texture; };
    33       /** @returns true if texture has alpha, false otherwise */
    34       inline bool hasAlpha() const {return bAlpha;}
     29      inline GLuint getFrameTexture(unsigned int frameNumber);// const { return this->textures; };
    3530
    36       static GLuint loadTexToGL (const SDL_Surface* surface);
    37 
    38       const SDL_Surface* const getStoredImage() { return this->image; };
    39 
    40     protected:
    41       bool prepareSurface(SDL_Surface* input);
    42       bool setSurface(SDL_Surface* newSurface);
    43       bool setTexture(GLuint texture) { this->texture = texture; };
    44 
     31      const SDL_Surface* const getFrameImage() const {  };
    4532
    4633    private:
    47       GLuint        texture;            //!< The Texture-ID of opengl from this Texture.
    48       bool          bAlpha;             //!< if the texture has an alpha channel.
    49       SDL_Surface*  image;              //!< The SDL_Surfce that stores the Texture on it.
     34      std::vector<GLuint>          textures;            //!< The Texture-ID of opengl from this Texture.
     35      std::vector<SDL_Surface*>    images;              //!< The SDL_Surfce that stores the Texture on it.
    5036  };
    5137
    52 #endif /* _TEXTURE_H */
     38#endif /* _MULTI_FRAME_TEXTURE_H */
  • trunk/src/lib/graphics/importer/texture.cc

    r5856 r5858  
    1919
    2020#include "debug.h"
    21 #include "graphics_engine.h"
    22 
     21
     22// INCLUDING SDL_Image
    2323#ifdef HAVE_SDL_IMAGE_H
    2424#include <SDL_image.h>
     
    5858}
    5959
    60 
    6160/**
    6261 *  loads an Image from a file to a Texture
     
    6564bool Texture::loadImage(const char* imageName)
    6665{
    67   if (GraphicsEngine::texturesEnabled)
     66  if (Texture::texturesEnabled)
    6867    {
    6968      if (this->image != NULL)
     
    195194
    196195
     196bool Texture::texturesEnabled = true;
     197
     198/**
     199 * enables, disables textures
     200 * @param texturesEnabled true if the textures should be enabled
     201 */
     202void Texture::setTextureEnableState(bool texturesEnabled)
     203{
     204  Texture::texturesEnabled = texturesEnabled;
     205}
     206
     207
     208//////////////////////////////////////
     209// UTILITY FUNCTIONALITY OF TEXTURE //
     210//////////////////////////////////////
    197211/**
    198212 *  Loads a Texture to the openGL-environment.
  • trunk/src/lib/graphics/importer/texture.h

    r5857 r5858  
    1414struct SDL_Surface;
    1515
    16 //! an enumerator for different procedural texture-types
    17 typedef enum TEXTURE_TYPE { TEXTURE_RADIAL_ALIAS,
    18   TEXTURE_NOISE };
    19 
    2016//! A Class, that reads in Textures from different fileformats.
    2117  class Texture : public BaseObject
     
    2723
    2824      bool loadImage(const char* imageName);
    29       bool rebuild();
     25      virtual bool rebuild();
    3026
    3127      /** @returns The textureID of this texture.  */
     
    3329      /** @returns true if texture has alpha, false otherwise */
    3430      inline bool hasAlpha() const {return bAlpha;}
     31      /** @returns the stored image of this Texture */
     32      const SDL_Surface* const getStoredImage() const { return this->image; };
    3533
    36       static GLuint loadTexToGL (const SDL_Surface* surface);
    3734
    38       const SDL_Surface* const getStoredImage() { return this->image; };
    3935
    4036      static void setTextureEnableState(bool texturesEnabled);
    4137      /** @returns true if Textures are enabled */
    4238      inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
     39
     40      // Utility functionality:
     41      static GLuint loadTexToGL (const SDL_Surface* surface);
    4342
    4443    protected:
Note: See TracChangeset for help on using the changeset viewer.