• Advertisement
Sign in to follow this  

Problem with texture on .x model

This topic is 4586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've loaded a .x model and it is rendering fine, except that the texture isn’t on it. I’m using the following pieces to load the model, ignoring any animation/bones for now. D3DXLoadMeshFromX(sXFile,D3DXMESH_MANAGED,m_pDevice, NULL, &materialBuffer,NULL, &m_dwNumMaterials, &m_mesh ) D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer(); . . Loop through materials { // Copy the material m_meshMaterials = d3dxMaterials.MatD3D; // Set the ambient color for the material (D3DX does not do this) m_meshMaterials.Ambient = m_meshMaterials.Diffuse; // hardcode the texture name for now TCHAR strTexture2[MAX_PATH]; wsprintf(strTexture2,L"./muve_media/Tiny_skin.bmp"); if( FAILED( D3DXCreateTextureFromFile( m_pDevice, strTexture2, &(m_meshTextures) ) ) ) { //failed to load texture m_meshTextures = NULL; } } -------------------- To render I call this: for( DWORD i=0; i<m_dwNumMaterials; i++ ) { // Set the material and texture for this subset m_pDevice->SetMaterial( &m_meshMaterials ); m_pDevice->SetTexture( 0, m_meshTextures ); // Draw the mesh subset m_mesh->DrawSubset( i ); } -------------------- Light is on, I’ve tried with a default material I use for other things, I’ve played with different render settings. Everything seems fine to the point, if I render a triangle manually it works fine, but I don’t know what drawsubset is doing that would break anything. Like I said the model draws fine, and is shaded from the light correct. It’s just there is no texture, like maybe no tu/tv is set in the model. I know that’s not the case because it looks fine in the .x viewer. Any ideas what I might be doing wrong? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Yeah.

Your problem is here :
wsprintf(strTexture2,L"./muve_media/Tiny_skin.bmp");

Active directory is probably not be the same as your exe directory.
Get exe directory with GetModuleFileName (or GetModuleName ?) and make absolute path :
strcpy (strTexture2, AppPath);
strcat (strTexture2, L"//muve_media//Tiny_skin.bmp");

Share this post


Link to post
Share on other sites
no that's not the problem, but thanks for trying. I specifically set it that way for what I'm doing, and I know it's the correct path. I also know I'm loading the texture correctly, as I can draw a simple poly and the texture renders fine on it. My problem is something to do with the .x utility programs and something they're requiring that I'm not getting set correctly.

Any other suggestions?

Share this post


Link to post
Share on other sites
What did you use to make the .X file? Depending on what you exported it from and what you used to export it you may have a problem with your .X file.

Open it up and check your materials to see if they have associated textures... if they don't then you know why its not working. Solving the problem is a whole 'nother kettle of fish.

I sugges this because I just encountered this problem trying to export from Maya 6.0 using the July SDK update exporter(and for the record NONE of the exporters MS has made for maya have worked).

Share this post


Link to post
Share on other sites
Thanks but I'm just using one of the directx sample files for now, the tiny_4anim.x file and the tiny.x file. Neither is working. I suspect there is some step I'm missing or something I haven't turned on/off, but I don't know what it is.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement