Code:
//--------------------------
//Parsing main m2 file
for(int x=1;x<Model.header.nTextures+1;x++)
{
TextureDef buf;
ReadFile(file, &buf, 16, &read, 0);
SetFilePointer(file, buf.ofsFilename, 0, 0);
ReadFile(file, &buf3, buf.lenFilename, &read, 0);
buf2 = buf3;
Model.TextureNames.push_back(buf2);
SetFilePointer(file, Model.header.ofsTextures+(x*16), 0, 0);
}
//----------------------------
//Read texture unit in .skin file
SetFilePointer(file, skin_header.ofsTextureUnits, 0, 0);
TexUnit buf;
for(int x=0;x<skin_header.nTextureUnits;x++)
{
if(!ReadFile(file, &buf,sizeof(TexUnit), &read, 0))//24
return false;
TexUnits.push_back(buf);
}
//----------------------------
//Set textures inside function that adds object to d3d part
//I'm thinking this is where the trouble comes in
for(int x=0;x<MPQ.Models.size();x++)
{
for (int y=0;y<MPQ.Models[x].TexUnits.size();y++)
{
MPQ.Models[x].obj[MPQ.Models[x].TexUnits[y].SubmeshIndex1].texture = MPQ.Models[x].TexUnits[y].Texture;
//MPQ.Models[x].obj[MPQ.Models[x].TexUnits[y].SubmeshIndex2].texture = MPQ.Models[x].TexUnits[y].Texture;
}
Hopefully something obvious I'm missing.
Code:
else if (Objs[x].subs[z].textured && Objs[x].subs[z].gTexture.size() > 1) // if textured and more than 1 texture
{
for (int o=0;o<Objs[x].subs[z].gTexture.size() && o<7;o++)
g_pD3DDevice->SetTexture(o, Objs[x].subs[z].gTexture[o]); //loop and set all textures
g_pD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);// set base texture
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); // to first stage
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // texture
g_pD3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1); // pull color from
g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // texture
g_pD3DDevice->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
g_pD3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA);//D3DTOP_BLENDTEXTUREALPHA); // pull color from
g_pD3DDevice->SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_TEXTURE); //alpha blend
g_pD3DDevice->SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE); //D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(2, D3DTSS_ALPHAARG1, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_SELECTARG1); // pull color from
g_pD3DDevice->SetTextureStageState(3, D3DTSS_COLORARG1, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(3, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // texture
g_pD3DDevice->SetTextureStageState(4, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA); // pull color from
g_pD3DDevice->SetTextureStageState(4, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(4, D3DTSS_COLORARG2, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(4, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(4, D3DTSS_ALPHAARG1, D3DTA_CURRENT); // texture
g_pD3DDevice->SetTextureStageState(5, D3DTSS_COLOROP, D3DTOP_SELECTARG1); // pull color from
g_pD3DDevice->SetTextureStageState(5, D3DTSS_COLORARG1, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(5, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(5, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // texture
g_pD3DDevice->SetTextureStageState(6, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA); // pull color from
g_pD3DDevice->SetTextureStageState(6, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(6, D3DTSS_COLORARG2, D3DTA_CURRENT); // current
g_pD3DDevice->SetTextureStageState(6, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // pull alpha from
g_pD3DDevice->SetTextureStageState(6, D3DTSS_ALPHAARG1, D3DTA_CURRENT); // texture
Sorry some of the comments are off because I c/p'd, but it should still be easy enough to follow. When using all the textures in 1 stage it ignores the base texture, and then just alpha blends the alpha texture so that the ground is transparent.