Archived

This topic is now archived and is closed to further replies.

3dZmaster

Object Loading. How to get textures?

Recommended Posts

if( FAILED( m_pBall->Create( m_pd3dDevice, _T("Ball.x") ) ) ) { MessageBox(NULL, "Could not find Ball.x", "Engine.exe", MB_OK); return E_FAIL; } this is what I''m using. Alone it doesn''t load textures. What other operations I should do at the loading and rendering part? thx...

Share this post


Link to post
Share on other sites
The mesh file contains the texture filenames associated with the subsets. D3DX loader can automatically fill an array of material definitions, which contain the filenames, for you.

See D3DXLoadMeshFromX(), and especially 5th parameter of it.

rgds Nik

[edited by - Nik02 on October 5, 2003 10:13:59 AM]

Share this post


Link to post
Share on other sites
Yes, set the texture before rendering the object you want to use the said texture with.

for example:

dev->SetTexture(0,textures[0]);
//this will be drawn using textures[0],

//which is a pointer of a texture.

mesh->DrawSubset(0);

dev->SetTexture(0,&textures[1]);
mesh->DrawSubset(1); //and this will be drawn using textures[1].



Note that from texture loader, you only get an array of D3DXMATERIALS, which contain the filenames, should you decide to use them. My sample code assumes that the textures are already loaded into the textures[] array.

-Nik



[edited by - Nik02 on October 5, 2003 11:22:08 AM]

Share this post


Link to post
Share on other sites
quote:

The mesh file contains the texture filenames associated with the subsets. D3DX loader can automatically fill an array of material definitions, which contain the filenames, for you.



Could you explain how to do this?

Share this post


Link to post
Share on other sites
Normally i'd say "check the sdk" but i'm in a very good mood today
You do have the sdk docs?

D3DXLoadMeshFromX function takes, as it's fifth parameter, a pointer to a pointer of a ID3DXBuffer interface.
That means, if you give the address of your empty buffer pointer to the loader, dx will allocate and fill the buffer for you.

Now, when/if the mesh has been successfully loaded, the material buffer contains an array of D3DXMATERIAL structures (if any are present in the x file), which in turn contain the texture filenames.

The rest i leave as an excercise for the reader (it's basic c++ from this point on).

kind rgds, Nik

PS. Send me an e-mail in Finnish, if you'd like some help in our native language. I don't want to mess up the forums with a language that the majority won't understand

PPS. Each mesh subset corresponds to exactly one D3DXMATERIAL instance in the mesh.

[edited by - Nik02 on October 5, 2003 12:37:25 PM]

Share this post


Link to post
Share on other sites