ID3DXMesh* Mesh = 0;
std::vector<D3DMATERIAL9> Mtrls(0);
std::vector<IDirect3DTexture9*> Textures(0);
bool Setup()
{
HRESULT hr = 0;
// Load the XFile data.
ID3DXBuffer* adjBuffer = 0;
ID3DXBuffer* mtrlBuffer = 0;
DWORD numMtrls = 0;
hr = D3DXLoadMeshFromX(
"H-German-Idle.x",
D3DXMESH_MANAGED,
Device,
&adjBuffer,
&mtrlBuffer,
0,
&numMtrls,
&Mesh);
if( mtrlBuffer != 0 && numMtrls != 0 )
{
D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();
for(int i = 0; i < numMtrls; i++)
{
// the MatD3D property doesn't have an ambient value set
// when its loaded, so set it now:
mtrls[i].MatD3D.Ambient = mtrls[i].MatD3D.Diffuse;
// save the ith material
Mtrls.push_back( mtrls[i].MatD3D );
// check if the ith material has an associative texture
if( mtrls[i].pTextureFilename != 0 )
{
// yes, load the texture for the ith subset
IDirect3DTexture9* tex = 0;
D3DXCreateTextureFromFile(
Device,
mtrls[i].pTextureFilename,
&tex);
// save the loaded texture
Textures.push_back( tex );
}
else
{
// no texture for the ith subset
Textures.push_back( 0 );
}
}
}
d3d::Release<ID3DXBuffer*>(mtrlBuffer); // done w/ buffer
}
// Set texture filters.
Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
void Cleanup()
{ d3d::DrawBasicScene(0, 0.0f);
d3d::Release<ID3DXMesh*>(Mesh);
for(int i = 0; i < Textures.size(); i++)
d3d::Release<IDirect3DTexture9*>( Textures[i] );
}
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
//Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
Device->BeginScene();
bool Display(float timeDelta)
{
for(int i = 0; i < Mtrls.size(); i++)
{
Device->SetMaterial( &Mtrls[i] );
Device->SetTexture(0, Textures[i]);
Mesh->DrawSubset(i);
}
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}
Note: I have clipped code that is not essential to this topic. And this code works fine with .bmp's but not .dds's. Thanks
-Rob
[edited by - 3Dgangsta on February 20, 2004 12:11:41 PM]
.dds problems
Hi,
I bought a package of 3D models in the .x format but the stupid testures are in a .dds format and I only know how to use bitmaps. So Ill post the code I have and maybe someone could please tell me what I am doing wrong. Thanks
Can you at least say what''s wrong? Are there any runtime errors? Does the debug spew say anything? You really should check the return HRESULT''s of the DX functions. At the VERY least, you should check the HRESULT of D3DXCreateTextureFromFile, since you think the problem is with the texture loading code.
D3DXCreateTextureFromFile should be able to load .dds files the same way it loads .bmp files.
neneboricua
D3DXCreateTextureFromFile should be able to load .dds files the same way it loads .bmp files.
neneboricua
NO errors are returned at all. The model just appears with a wierd maroon color on it. I put the .dds in the same directory and everything.
[edited by - 3Dgangsta on February 20, 2004 12:34:57 PM]
[edited by - 3Dgangsta on February 20, 2004 12:34:57 PM]
It could be because the dds is in the same directory. I know maya tends to have absolute filenames in the .x file. Open the .x in a text editor and search out the texture areas, you will probably have to change all the texture file names to relative by hand. (just to a search for .dds).
Step through your loading code and see if the function to load textures retruns an error. You can do something like:
IDirect3DTexture9* tex = 0;if( FAILED( hr = D3DXCreateTextureFromFile( Device, mtrls.pTextureFilename, &tex) ) )<br> DXTRACE_ERR_MSGBOX( "D3DXCreateTextureFromFile", hr );<br>Textures.push_back( tex );<br> </pre> <br>Do something similar for the call to load the mesh in the first place. If there is some kind of error, you'll at least have an idea as to what it is.<br><br>neneboricua <br><br><SPAN CLASS=editedby>[edited by - neneboricua19 on February 20, 2004 1:46:08 PM]</SPAN>
I actually started to look though the .x file and found that the texture name was german.BMP so I changed it to german.DDS and it worked!! But now I have a off topic question. How exactly to I postion the object? THanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement