Ignore:
Timestamp:
06/14/08 01:11:58 (16 years ago)
Author:
mattausch
Message:

loading textured scenes possible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp

    r2756 r2757  
    8181 
    8282 
     83void BinaryLoader::LoadTextures(ifstream &str) 
     84{ 
     85        int numTextures; 
     86        str.read(reinterpret_cast<char *>(&numTextures), sizeof(int)); 
     87 
     88        for (int i = 0; i < numTextures; ++ i) 
     89        { 
     90                // texture 
     91                int texnameSize; 
     92                int id; 
     93 
     94                str.read(reinterpret_cast<char *>(&id), sizeof(int)); 
     95                str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int)); 
     96 
     97                char *texname = new char[texnameSize]; 
     98                str.read(texname, sizeof(char) * texnameSize); 
     99 
     100                cout << "loading texture " << texname << " with len " << texnameSize << " id: " << id << endl; 
     101 
     102                Texture *tex = new Texture(texname); 
     103 
     104                mTextureTable[id] = tex; 
     105        } 
     106} 
     107 
     108 
    83109//Appearance *BinaryLoader::LoadMaterial(igzstream &str) 
    84110Material *BinaryLoader::LoadMaterial(ifstream &str) 
     
    88114         
    89115        // texture 
    90         int texnameSize; 
    91  
    92         str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int)); 
    93  
    94         if (texnameSize) 
    95         { 
    96                 char *texname = new char[texnameSize]; 
    97                 str.read(texname, sizeof(char) *texnameSize); 
    98  
    99  
    100                 cout << "loading texture " << texname << " with len " << texnameSize << endl; 
    101                 Texture *tex = new Texture(texname); 
    102                  
    103                 mat->SetTexture(tex); 
    104         } 
    105         else 
    106                 cout << "no texture " << texnameSize << endl; 
     116        int texId; 
     117 
     118        str.read(reinterpret_cast<char *>(&texId), sizeof(int)); 
     119        //cout << "texid: " << texId << endl; 
     120 
     121        if (texId >= 0) 
     122        { 
     123                mat->SetTexture(mTextureTable[texId]); 
     124        } 
    107125 
    108126        // material 
     
    158176                return NULL; 
    159177 
    160         cout << "vertexcount: " << vertexCount << endl; 
     178        //cout << "vertexcount: " << vertexCount << endl; 
    161179 
    162180        vertices = new Vector3[vertexCount]; 
     
    171189        if (texCoordCount) 
    172190        { 
    173                 cout << "loading texcoords of size " << texCoordCount << endl; 
     191                //cout << "loading texcoords of size " << texCoordCount << endl; 
    174192                texcoords = new float[texCoordCount * 2]; 
    175193                str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2); 
     
    201219        if (!istr.is_open()) 
    202220                return false; 
     221 
     222        // load the texture table 
     223        LoadTextures(istr); 
    203224 
    204225        // #shapes 
Note: See TracChangeset for help on using the changeset viewer.