bool CStaticMesh::ExtractTexture(FILE* modelFile, std::vector<CTexture*>& textVector) { assert(modelFile); uint16 length = 0; char* path; std::string sPath = ""; //Read Length of the texture path fread(&length, sizeof(uint16), 1, modelFile); path = new char[length]; memset(path, 0, length); //Read Path fread(path, 1, length, modelFile); sPath = std::string(path); CHECKED_DELETE(path); std::string texName = m_MeshName + "_" + sPath; CTexture* texture = CORE->GetTextureManager()->GetResource(texName); if(texture == NULL) { texture = new CTexture(); texture->SetName(texName); if(!texture->Load(sPath)) { CHECKED_DELETE(texture); texture = CORE->GetTextureManager()->GetNoTexture(); std::string err = "CStaticMesh::ExtractTexture->No se ha podido crear la textura: " + sPath; LOGGER->AddNewLog(ELL_WARNING, err.c_str() ); } } textVector.push_back(texture); return true; }
CTexture * CRenderManager::LoadTexture(char const * _szFileName, D3DCOLOR const _ColorKey) { if(NULL == _szFileName) { MessageBox(0, "Filename was invalid.", "LoadTexture", MB_OK); return NULL; } // Look if the texture has already been loaded list<CTexture*>::iterator IterText = m_arrTextures.begin(); for( ; IterText != m_arrTextures.end(); ++IterText) { if(0 == strcmp((*IterText)->GetName().c_str(), _szFileName)) return (*IterText); } // Look for the first available slot where the struct is NULL for(IterText = m_arrTextures.begin(); IterText != m_arrTextures.end(); ++IterText) { if(NULL == (*IterText)) { IDirect3DTexture9 * pTexture = NULL; // Set the texture if(FAILED(D3DXCreateTextureFromFileEx(m_pDevice, _szFileName, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, _ColorKey, 0, 0, &pTexture))) { MessageBox(0, "Failed to create texture.", "LoadTexture", MB_OK); return NULL; } CTexture * pNew = new CTexture(); std::string szName = _szFileName; pNew->SetName(szName); pNew->SetTexture(pTexture); pNew->SetColor(_ColorKey); D3DSURFACE_DESC description; pTexture->GetLevelDesc(0, &description); pNew->SetWidth(description.Width); pNew->SetHeight(description.Height); pNew->SetTexture(pTexture); (*IterText) = pNew; return (*IterText); } } IDirect3DTexture9 * pTexture = NULL; // Set the texture if(FAILED(D3DXCreateTextureFromFileEx(m_pDevice, _szFileName, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, _ColorKey, 0, 0, &pTexture))) { MessageBox(0, "Failed to create texture.", "LoadTexture", MB_OK); return NULL; } CTexture * pNew = new CTexture(); std::string szName = _szFileName; pNew->SetName(szName); pNew->SetTexture(pTexture); pNew->SetColor(_ColorKey); D3DSURFACE_DESC description; pTexture->GetLevelDesc(0, &description); pNew->SetWidth(description.Width); pNew->SetHeight(description.Height); pNew->SetTexture(pTexture); m_arrTextures.push_back(pNew); return pNew; }