Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4157 in orxonox.OLD


Ignore:
Timestamp:
May 11, 2005, 12:14:54 AM (19 years ago)
Author:
patrick
Message:

orxonox/branches/md2_loader: modified the texture loader to use the sdl-image libraries, this will use material/texture classes from orxonox later

Location:
orxonox/branches/md2_loader/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/md2_loader/src/lib/graphics/importer/abstract_model.h

    r4156 r4157  
    2626#include <vector>
    2727#include <math.h>
     28#include <SDL_image.h>
    2829
    2930using namespace std;
     
    184185{
    185186
    186 static createTexture(UINT textureArray[], LPSTR strFileName, int textureID)
    187 {
    188         AUX_RGBImageRec *pBitmap = NULL;
     187 public:
     188 
     189  static void createTexture(unsigned int textureArray[], char* strFileName, int textureID)
     190    {
     191      SDL_Surface *image = NULL;
     192     
     193      if(!strFileName)                                                         
     194        return;
     195
     196      image = IMG_Load(strFileName);
     197      if( !image)
     198        PRINTF(0)("IMG_Load: %s\n", IMG_GetError());
    189199       
    190         if(!strFileName)                                                                        // Return from the function if no file name was passed in
    191                 return;
    192 
    193         pBitmap = auxDIBImageLoad(strFileName);                         // Load the bitmap and store the data
    194        
    195         if(pBitmap == NULL)                                                                     // If we can't load the file, quit!
    196                 exit(0);
    197 
    198         // Generate a texture with the associative texture ID stored in the array
    199         glGenTextures(1, &textureArray[textureID]);
    200 
    201         // This sets the alignment requirements for the start of each pixel row in memory.
    202         glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
    203 
    204         // Bind the texture to the texture arrays index and init the texture
    205         glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
    206 
    207         // Build Mipmaps (builds different versions of the picture for distances - looks better)
    208         gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
    209 
    210         // Lastly, we need to tell OpenGL the quality of our texture map.  GL_LINEAR_MIPMAP_LINEAR
    211         // is the smoothest.  GL_LINEAR_MIPMAP_NEAREST is faster than GL_LINEAR_MIPMAP_LINEAR,
    212         // but looks blochy and pixilated.  Good for slower computers though. 
    213                
    214         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    215         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    216 
    217         // Now we need to free the bitmap data that we loaded since openGL stored it as a texture
    218 
    219         if (pBitmap)                                                                            // If we loaded the bitmap
    220         {
    221                 if (pBitmap->data)                                                              // If there is texture data
    222                 {
    223                         free(pBitmap->data);                                            // Free the texture data, we don't need it anymore
    224                 }
    225 
    226                 free(pBitmap);                                                                  // Free the bitmap structure
    227         }
    228 }
     200      glGenTextures(1, &textureArray[textureID]);
     201      glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
     202      glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
     203      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
     204      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
     205      gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);       
     206
     207      SDL_FreeSurface(image);
     208    }
    229209
    230210};
  • orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc

    r4150 r4157  
    146146  return true;
    147147}
     148
    148149
    149150/**
     
    191192}
    192193
     194
    193195/**
    194196   \brief this function fills in the animation list for each animation by name and frame
     
    239241    }
    240242}
     243
    241244
    242245/**
  • orxonox/branches/md2_loader/src/world_entities/test_entity.cc

    r4155 r4157  
    2828TestEntity::TestEntity () : WorldEntity()
    2929{
    30  //This is for md2 test purposes only! if this is seen in the trunk: hit me :)
     30  this->textureArray = new unsigned int[100];
     31  memset(this->textureArray, 0, 100*sizeof(unsigned int));
     32 
    3133  MD2Loader* md2loader = new MD2Loader();
    3234  this->model = new t3DModel;
    3335  this->md2Model = new MD2Model();
    3436
    35   md2loader->importMD2(model, "../data/models/tris.md2", "test.bmp");
     37  md2loader->importMD2(this->model, "../data/models/tris.md2", "../data/models/tris.pcx");
     38
     39  for(int i = 0; i < this->model->numOfMaterials; i++)
     40    {
     41      if( strlen(this->model->materialList[i].strFile) > 0)
     42        {
     43          Helper::createTexture(textureArray, this->model->materialList[i].strFile, i);
     44        }
     45      this->model->materialList[i].texureId = i;
     46    }
    3647}
    3748
  • orxonox/branches/md2_loader/src/world_entities/test_entity.h

    r4152 r4157  
    2727  t3DModel* model;
    2828  MD2Model* md2Model;
     29
     30  unsigned int* textureArray;
     31
    2932};
    3033
Note: See TracChangeset for help on using the changeset viewer.