|
#include "..\include\TextureMappingTable.h"
#include "..\..\OpenGL\include\Texture\OAGTextureLoader.h"
oag::TextureMappingTable::TextureMappingTable(void)
{
}
oag::TextureMappingTable::~TextureMappingTable(void)
{
if( m_ListTexture.size() > 0 )
{
for( vector <int>::size_type i=0; i < m_ListTexture.size(); i++ )
{
if( m_ListTexture[i] )
{
delete m_ListTexture[i];
m_ListTexture[i] = NULL;
}
}
}
}
void oag::TextureMappingTable::AddTexture(oag::OAGTexture* pTexture)
{
bool bAddTexture = true;
if( HasTexture() )
{
for( vector<int>::size_type i = 0; i < m_ListTexture.size(); ++i )
{
oag::OAGTexture* pObjTexture = m_ListTexture[i];
if ( pTexture->GetFileName().compare( pObjTexture->GetFileName() ) == 0 )
{
bAddTexture = false;
break;
}
}
}
if( bAddTexture )
m_ListTexture.push_back( pTexture );
}
oag::OAGTexture* oag::TextureMappingTable::GetTexture(std::string strName)
{
oag::OAGTexture* pTexture = NULL;
if ( HasTexture() )
{
for( vector<int>::size_type i = 0; i < m_ListTexture.size(); ++i )
{
oag::OAGTexture* pCurTexture = m_ListTexture[i];
if ( pCurTexture->GetTextureName().compare( strName ) == 0 )
{
pTexture = m_ListTexture[i];
break;
}
}
}
return pTexture;
}
void oag::TextureMappingTable::ReadNodeXML(CXmlNode* pNode)
{
CXmlNode* pNodeTextures = pNode->GetNode("Textures");
if( pNodeTextures )
{
CXmlNodeList* pNodeTextureList = pNodeTextures->GetNodeList();
if( pNodeTextureList )
{
for( std::vector<int>::size_type i=0; i < pNodeTextureList->Count(); ++i )
{
CXmlNode* pcurNode = pNodeTextureList->GetAt(i);
std::string strImageFile = "";
strImageFile.append( m_strFolderPath );
strImageFile.append("\\");
strImageFile.append( pcurNode->GetAttribute("FileName") );
oag::OAGTexture * pTexture = oag::OAGTextureLoader::LoadTextureFromDisk( strImageFile );
if ( pTexture )
{
pTexture->SetDefaultFilter();
pTexture->BuildTexture();
pTexture->SetTextureName( pcurNode->GetAttribute("Name") );
m_ListTexture.push_back( pTexture );
}
}
delete pNodeTextureList;
}
}
}
void oag::TextureMappingTable::SaveNodeXML(CXmlNode* pNode)
{
if( HasTexture() )
{
CXmlNode* pNodeListTexture = new CXmlNode("Textures");
pNode->AppendChild( pNodeListTexture );
for( vector<int>::size_type i = 0; i < m_ListTexture.size(); ++i )
{
oag::OAGTexture* pTexture = m_ListTexture[i];
CXmlNode* pNodeTexture = new CXmlNode("Texture");
pNodeTexture->AddAttribute("Name", pTexture->GetTextureName() );
pNodeTexture->AddAttribute("FileName", pTexture->GetFileName() );
pNodeListTexture->AppendChild( pNodeTexture );
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I live in Matão, a small city in Brazil. I studied as Programmer in a College for Software Development in Database.
After finishing the College I have been working with java, c# and Computer Graphics with searches for OpenGL.