void ObjImporter::loadData(const char* &file_path) { std::ifstream file( file_path, std::ifstream::in); if( !file ){ std::cout << "Erro ao abrir o arquivo: " << file_path << std::endl; } string tipo; while (file.good()) { tipo = "_"; file >> tipo; if (tipo == "v" ) { ///VERTICES float v1, v2, v3; file >> v1; file >> v2; file >> v3; // float x = atof (v1.c_str()); // float y = atof (v2.c_str()); // float z = atof (v3.c_str()); // x = (double)strtod( v1.c_str(), NULL ); // y = (double)strtod( v2.c_str(), NULL ); // z = (double)strtod( v3.c_str(), NULL ); // cout << "PONTOS " << x << " " << y << " " << z << endl; // cout << "PONTOS == " << v1 << " " << v2 << " " << v3 << endl; if( v1 > maxX ) maxX = v1; if( v2 > maxY ) maxY = v2; if( v3 > maxZ ) maxZ = v3; if( v1 < minX ) minX = v1; if( v2 < minY ) minY = v2; if( v3 < minZ ) minZ = v3; vertices.push_back(new Ponto(v1, v2, v3)); continue; } if (tipo == "vt" ) { ///TEXTURAS float u, v; file >> u; file >> v; //cout << "Textura == " << u << " " << v << endl; texturas.push_back(Textura(u, v, 0)); continue; }
void Textura::init(){ // alocar espaço para guardar os nomes de ficheiro das texturas Textura::filenames = (char**)malloc(sizeof(char*) * TipoTextura::texCOUNT_ENUM); for(int i=0; i<TipoTextura::texCOUNT_ENUM; i++) Textura::filenames[i] = (char*)malloc(sizeof(char) * FILENAME_MAX_SIZE); // definir os nomes de ficheiro das texturas strcpy( Textura::filenames[texMadeira], "Texturas/madeira.png" ); strcpy( Textura::filenames[texFolhas], "Texturas/folhas.png" ); strcpy( Textura::filenames[texPlanetaTerra], "Texturas/planetaTerra.jpg" ); strcpy( Textura::filenames[texLava1], "Texturas/lava1.png" ); strcpy( Textura::filenames[texSol], "Texturas/sol.jpg" ); strcpy( Textura::filenames[texErvas], "Texturas/ervas.png" ); strcpy( Textura::filenames[texRelva], "Texturas/relva.png" ); strcpy( Textura::filenames[texShinyMetal], "Texturas/shinyMetal.png" ); strcpy( Textura::filenames[texShinyBrushedMetal], "Texturas/shinyBrushedMetal.png" ); // gerar identificadores de imagem Textura::imageIds = (ILuint*)malloc(sizeof(ILuint) * texCOUNT_ENUM); ilGenImages( texCOUNT_ENUM, Textura::imageIds); // gerar identificadores de textura e definir algumas propriedades Textura::textureIds = (GLuint*)malloc(sizeof(GLuint) * texCOUNT_ENUM); glGenTextures( texCOUNT_ENUM, Textura::textureIds); // alocar espaço para os objetos Textura texturas = (Textura*)malloc(sizeof(Textura) * texCOUNT_ENUM); // criar objetos Textura (carregar imagens, criar textura a partir da imagem, ..) for(int i=0; i<texCOUNT_ENUM; i++) texturas[i] = Textura((TipoTextura)i); for(int i=0; i<texCOUNT_ENUM; i++) std::cout << "textura: " << filenames[i] << "; dim: " << texturas[i].getWidth() << "x" << texturas[i].getHeight() << "; id=" << imageIds[i] << std::endl; unsetTextura(); }