Changeset 2757 for GTP


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

loading textured scenes possible

Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
6 added
3 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 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.h

    r2756 r2757  
    1 #ifndef _BinaryLoader_H__ 
    2 #define _BinaryLoader_H__ 
     1#ifndef __BinaryLoader_H__ 
     2#define __BinaryLoader_H__ 
    33 
    44// note use forward declaration instead 
     
    66#include <iostream> 
    77#include <fstream> 
     8#include <map> 
     9 
    810#include "common.h" 
    911 
     
    1618class Material; 
    1719class Geometry; 
     20class Texture; 
    1821 
    1922 
     
    2629protected: 
    2730         
     31        void LoadTextures(std::ifstream &str); 
     32 
    2833        SceneEntity *LoadSceneEntity(std::ifstream &str); 
    2934        Material *LoadMaterial(std::ifstream &str); 
     
    3439        Geometry *LoadGeometry(igzstream &str); 
    3540        */ 
     41 
     42        std::map<int, Texture *> mTextureTable; 
    3643}; 
    3744 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp

    r2756 r2757  
    146146        BinaryLoader loader; 
    147147 
    148         const string filename("house_test.dem"); 
    149         //const string filename("city.dem"); 
     148        //const string filename("house_test.dem"); 
     149        const string filename("city.dem"); 
    150150 
    151151        camera = new Camera(800, 600); 
     
    166166 
    167167        SetupProjection(800, 600, 60, sceneBox); 
    168         camera->LookAtBox(sceneBox); 
    169         //camera->LookInBox(sceneBox); 
     168        //camera->LookAtBox(sceneBox); 
     169        camera->LookInBox(sceneBox); 
    170170        //camera->SetPosition(Vector3(0, 0, -3)); 
    171171        //camera->SetDirection(Vector3(0, 0, 1)); 
Note: See TracChangeset for help on using the changeset viewer.