Original Post
Hi I've created a new class under my very newbie small engine and I wanted it to load the textures into an LPDIRECT3DTEXTURE9 array of textures. I've created the header file: And the Source file: And my problem is when m_VectorDimension is equalled to j, the m_VectorDimension gets stupid values (should be 5). I've tried to do loads of things none of them succeeded, so I am asking your help. Thanks in advance for your time.
#ifndef _H_Textures_
#define _H_Textures_
#include "Engine.h"
#include <vector>
using namespace std;
struct FILES
{
char Header[30];
int Size;
char FileName[128];
};
class Textures
{
public:
Textures();
~Textures();
int m_VectorDimension;
vector<LPDIRECT3DTEXTURE9> m_Textures;
bool LoadTextureFile( LPDIRECT3DDEVICE9 pd3dDevice, const char *TextureFile );
void SetTextureState( LPDIRECT3DDEVICE9 pd3dDevice, int Indice );
};
#endif
#include "Textures.h"
//-----------------------------------------------------------------------------
// Name: Textures()
// Desc: Textures constructor
//-----------------------------------------------------------------------------
Textures::Textures()
{
}
//-----------------------------------------------------------------------------
// Name: ~Textures()
// Desc: Textures destructor
//-----------------------------------------------------------------------------
Textures::~Textures()
{
for ( int i = 0; i <= m_VectorDimension; i++ )
{
SAFE_RELEASE( m_Textures );
}
}
//-----------------------------------------------------------------------------
// Name: LoadTextureFile()
// Desc: Loads the list of textures file.
//-----------------------------------------------------------------------------
bool Textures::LoadTextureFile( LPDIRECT3DDEVICE9 pd3dDevice, const char *TextureFile )
{
FILES Files;
FILE *fp = fopen( TextureFile, "rb" );
if ( fp == NULL )
{
return false;
}
fgets( Files.Header, 30, fp );
char sizetmp[5];
fgets( sizetmp, 5, fp );
Files.Size = atoi( sizetmp );
m_Textures.reserve( Files.Size );
int j = 0; // ERROR WITH THIS VAR
while ( !feof( fp ) )
{
// Check the current path too?
fgets( Files.FileName, 128, fp );
if ( char *cr1 = strchr( Files.FileName, '\n' ) )
*cr1 = '\0';
if ( char *cr2 = strchr( Files.FileName, '\r' ) )
*cr2 = '\0';
if ( SUCCEEDED( D3DXCreateTextureFromFile( pd3dDevice, Files.FileName, &m_Textures[j] ) ) )
{
j++;
}
else
{
return false;
}
}
m_VectorDimension = j;
fclose( fp ) ;
return true;
}
//-----------------------------------------------------------------------------
// Name: SetTextureState()
// Desc:
//-----------------------------------------------------------------------------
void Textures::SetTextureState( LPDIRECT3DDEVICE9 pd3dDevice, int Indice )
{
// Setup our texture. Using textures introduces the texture stage states,
// which govern how textures get blended together (in the case of multiple
// textures) and lighting information. In this case, we are modulating
// (blending) our texture with the diffuse color of the vertices.
pd3dDevice->SetTexture( 0, m_Textures[Indice] );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
}