Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3344 in orxonox.OLD for orxonox/branches/parenting


Ignore:
Timestamp:
Jan 5, 2005, 5:50:07 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: importer: modularity improvement. Now Textures handle the texture-ID themselves and can be retrieved with the getTexture()-function

Location:
orxonox/branches/parenting/src/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/parenting/src/importer/material.cc

    r3340 r3344  
    5050  if (this->name)
    5151    delete []this->name;
    52   if (this->diffuseTextureSet)
    53     glDeleteTextures (1, &this->diffuseTexture);
     52  if (this->diffuseTexture)
     53    this->diffuseTexture;
    5454  if (this->nextMat)
    5555    delete this->nextMat;
     
    8989  this->setTransparency(0.0);
    9090
     91
     92  this->diffuseTexture = NULL;
     93  this->ambientTexture = NULL;
     94  this->specularTexture = NULL;
    9195
    9296  this->diffuseTextureSet = false;
     
    145149
    146150  if (this->diffuseTextureSet)
    147     glBindTexture(GL_TEXTURE_2D, this->diffuseTexture);
     151    glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
    148152  else
    149153    glBindTexture(GL_TEXTURE_2D, 0);
     
    318322{
    319323  PRINTF(3)("setting Diffuse Map %s\n", dMap);
    320   Texture* tmp = new Texture();
    321   this->diffuseTextureSet = tmp->loadImage(dMap, &this->diffuseTexture);
     324  diffuseTexture = new Texture();
     325  this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
    322326
    323327}
  • orxonox/branches/parenting/src/importer/material.h

    r3340 r3344  
    7070  float transparency;//!< The transperency of the Material.
    7171
    72   GLuint diffuseTexture; //!< The diffuse texture of the Material.
    73   GLuint ambientTexture; //!< The ambient texture of the Material.
    74   GLuint specularTexture;//!< The specular texture of the Material.
     72  Texture* diffuseTexture; //!< The diffuse texture of the Material.
     73  Texture* ambientTexture; //!< The ambient texture of the Material.
     74  Texture* specularTexture;//!< The specular texture of the Material.
    7575 
    7676  bool diffuseTextureSet; //!< Chekcs if the diffuse texture is Set.
  • orxonox/branches/parenting/src/importer/texture.cc

    r3343 r3344  
    113113}
    114114
     115
     116
     117/**
     118   \brief Constructor for a Texture
     119*/
     120Texture::Texture(void)
     121{
     122  this->pImage = new Image;
     123  this->pImage->data = NULL;
     124  this->texture = 0;
     125}
     126
     127/**
     128   \brief Destructor of a Texture
     129   
     130   Frees Data, and deletes the textures from GL
     131*/
     132Texture::~Texture(void)
     133{
     134  if (this->pImage->data)
     135    delete []this->pImage->data;
     136  delete pImage;
     137  if (this->texture)
     138    glDeleteTextures(1, &this->texture);
     139}
     140
     141/**
     142   \returns The Texture-identifier number.
     143*/
     144GLuint Texture::getTexture(void)
     145{
     146    return this->texture;
     147}
    115148
    116149/**
     
    147180}
    148181
     182/**
     183   \brief a Simple function that switches two char values
     184   \param a The first value
     185   \param b The second value
     186*/
    149187inline void Texture::swap (unsigned char &a, unsigned char &b)
    150188{
     
    161199   \param texture The Texture to apply it to.
    162200*/
    163 bool Texture::loadTexToGL (Image* pImage, GLuint* texture)
     201bool Texture::loadTexToGL (Image* pImage)
    164202{
    165203  PRINTF(2)("Loading texture to OpenGL-Environment.\n");
    166   glGenTextures(1, texture);
    167   glBindTexture(GL_TEXTURE_2D, *texture);
     204  glGenTextures(1, &this->texture);
     205  glBindTexture(GL_TEXTURE_2D, this->texture);
    168206  /* not Working, and not needed.
    169207  glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
     
    179217
    180218#ifdef HAVE_SDL_SDL_IMAGE_H
    181 bool Texture::loadImage(char* imageName, GLuint* texture)
     219bool Texture::loadImage(char* imageName)
    182220{
    183221  char* imgNameWithPath = searchTextureInPaths(imageName);
     
    185223    {
    186224      SDL_Surface* map;
    187       Image* pImage = new Image;
    188225      map=IMG_Load(imgNameWithPath);
    189226      if(!map)
     
    209246            swap( pImage->data[ (i * pImage->width * pImage->bpp) + j + k], pImage->data[ ( (pImage->height - i - 1) * pImage->width * pImage->bpp ) + j + k]);
    210247 
    211       this->loadTexToGL (pImage, texture);
     248      this->loadTexToGL (this->pImage);
    212249    }
    213250  else
     
    225262   2. ToDO: Checks where to find the Image
    226263*/
    227 bool Texture::loadImage(char* imageName, GLuint* texture)
     264bool Texture::loadImage(char* imageName)
    228265{
    229266  char* imgNameWithPath = searchTextureInPaths(imageName);
     
    233270        {
    234271          PRINTF(3)("Requested bmp-image. Trying to Import.\n");
    235           return this->loadBMP(imgNameWithPath, texture);
     272          return this->loadBMP(imgNameWithPath);
    236273        }
    237274     
     
    239276        {
    240277          PRINTF(3)("Requested jpeg-image. Trying to Import\n");
    241           return this->loadJPG(imgNameWithPath, texture);
     278          return this->loadJPG(imgNameWithPath);
    242279        }
    243280      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))
    244281        {
    245282          PRINTF(3)("Requested tga-image. Trying to Import\n");
    246           return this->loadTGA(imgNameWithPath, texture);
     283          return this->loadTGA(imgNameWithPath);
    247284        }
    248285      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
    249286        {
    250287          PRINTF(3)("Requested png-image. Trying to Import\n");
    251           return this->loadPNG(imgNameWithPath, texture);
     288          return this->loadPNG(imgNameWithPath);
    252289        }
    253290      else
     
    269306   \param texture A pointer to the Texture which should be read to.
    270307*/
    271 bool Texture::loadBMP (char* bmpName, GLuint* texture)
    272 {
    273   Image* pImage = new Image;
     308bool Texture::loadBMP (char* bmpName)
     309{
    274310  FILE *file;
    275311  unsigned long size;                 // size of the image in bytes.
     
    353389      pImage->data[i+2] = temp;
    354390    }
    355   this->loadTexToGL (pImage, texture);
     391  this->loadTexToGL (pImage);
    356392 
    357393
     
    374410   \param texture a reference to the Texture to write the image to
    375411*/
    376 bool Texture::loadJPG (char* jpgName, GLuint* texture)
     412bool Texture::loadJPG (char* jpgName)
    377413{
    378414#ifdef HAVE_JPEGLIB_H
     
    451487    exit(0);
    452488 
    453   this->loadTexToGL (pImage, texture);
     489  this->loadTexToGL (pImage);
    454490  if (pImage)
    455491    {
     
    474510   \param texture a reference to the Texture to write the image to
    475511*/
    476 bool Texture::loadTGA(const char * tgaName, GLuint* texture)
     512bool Texture::loadTGA(const char * tgaName)
    477513{
    478514  typedef struct
     
    505541  if(memcmp(uTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
    506542    {
    507       loadUncompressedTGA(tgaName, fTGA, texture);
     543      loadUncompressedTGA(tgaName, fTGA);
    508544      if (fTGA)
    509545        fclose (fTGA);
     
    511547  else if(memcmp(cTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
    512548    {
    513       loadCompressedTGA(tgaName, fTGA, texture);
     549      loadCompressedTGA(tgaName, fTGA);
    514550        if (fTGA)
    515551          fclose (fTGA);
     
    531567   \param texture a reference to the Texture to write the image to
    532568*/
    533 bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA, GLuint* texture)
     569bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA)
    534570{
    535571  GLubyte header[6];      // First 6 Useful Bytes From The Header
     
    542578  GLuint  Bpp;            // Bits Per Pixel
    543579
    544   Image* pImage = new Image;
    545580  GLuint cswap;
    546581  if(fread(header, sizeof(header), 1, fTGA) == 0)
     
    595630    }
    596631 
    597   this->loadTexToGL (pImage, texture);
     632  this->loadTexToGL (pImage);
    598633
    599634  return true;
     
    606641   \param texture a reference to the Texture to write the image to
    607642*/
    608 bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture)
     643bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA)
    609644{
    610645  GLubyte header[6];      // First 6 Useful Bytes From The Header
     
    617652  GLuint  Bpp;            // Bits Per Pixel
    618653
    619   Image* pImage = new Image;
    620 
    621  
    622654  if(fread(header, sizeof(header), 1, fTGA) == 0)
    623655    {
     
    778810  while(currentpixel < pixelcount);     // Loop while there are still pixels left
    779811
    780   this->loadTexToGL (pImage, texture);
     812  this->loadTexToGL (pImage);
    781813
    782814  return true;
     
    796828   \param texture a reference to the Texture to write the image to
    797829*/
    798 bool Texture::loadPNG(const char* pngName, GLuint* texture)
     830bool Texture::loadPNG(const char* pngName)
    799831{
    800832#ifdef HAVE_PNG_H
    801   Image* pImage = new Image;
    802833
    803834  FILE *PNG_file = fopen(pngName, "rb");
     
    912943    }
    913944  */
    914   this->loadTexToGL (pImage, texture); 
     945  this->loadTexToGL (pImage); 
    915946 
    916947  free(pImage->data);
  • orxonox/branches/parenting/src/importer/texture.h

    r3343 r3344  
    6464    GLubyte *data;  //!< The Image Data comes here! DANGER: uncompressed data.
    6565  };
     66  Image* pImage;
     67  GLuint texture;
    6668  char* searchTextureInPaths(char* texName) const;
    6769  inline void swap(unsigned char &a, unsigned char &b);
    6870 public:
     71  Texture(void);
     72  ~Texture(void);
    6973
    70   bool loadTexToGL (Image* pImage, GLuint* texture);
     74  GLuint getTexture(void);
     75  bool loadTexToGL (Image* pImage);
    7176
    72   bool loadImage(char* imageName, GLuint* texture);
     77  bool loadImage(char* imageName);
    7378#ifndef HAVE_SDL_SDL_IMAGE_H
    7479
    75   bool loadBMP (char* bmpName, GLuint* texture);
     80  bool loadBMP (char* bmpName);
    7681
    77   bool loadJPG (char* jpgName, GLuint* texture);
     82  bool loadJPG (char* jpgName);
    7883
    7984  /// TGA ///
    8085
    81   bool loadTGA(const char * tgaName, GLuint* texture);
    82   bool loadUncompressedTGA(const char * filename, FILE * fTGA, GLuint* texture);
    83   bool loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture);
     86  bool loadTGA(const char * tgaName);
     87  bool loadUncompressedTGA(const char * filename, FILE * fTGA);
     88  bool loadCompressedTGA(const char * filename, FILE * fTGA);
    8489
    8590  bool loadPNG(const char* pngName, GLuint* texture);
Note: See TracChangeset for help on using the changeset viewer.