Problem loading .X files in DirectX.

Started by
18 comments, last by directXtreme 16 years, 11 months ago
MODEL *LoadModel(char *filename) { MODEL *model = (MODEL*)malloc(sizeof(MODEL)); LPD3DXBUFFER matbuffer; HRESULT result; //load mesh from the specified file result = D3DXLoadMeshFromX( filename, //filename D3DXMESH_SYSTEMMEM, //mesh options d3ddev, //Direct3D device NULL, //adjacency buffer &matbuffer, //material buffer NULL, //special effects &model->material_count, //number of materials &model->mesh); //resulting mesh if (result != D3D_OK) { MessageBox(NULL, "Error loading model file", "Error", MB_OK); return NULL; } //extract material properties and texture names from material buffer LPD3DXMATERIAL d3dxMaterials = (LPD3DXMATERIAL)matbuffer->GetBufferPointer(); model->materials = new D3DMATERIAL9[model->material_count]; model->textures = new LPDIRECT3DTEXTURE9[model->material_count]; //create the materials and textures for(DWORD i=0; i<model->material_count; i++) { //grab the material model->materials = d3dxMaterials.MatD3D; //set ambient color for material model->materials.Ambient = model->materials.Diffuse; model->textures = NULL; if( d3dxMaterials.pTextureFilename != NULL && lstrlen(d3dxMaterials.pTextureFilename) > 0 ) { //load texture file specified in .x file result = D3DXCreateTextureFromFile(d3ddev, d3dxMaterials.pTextureFilename, &model->textures); if (result != D3D_OK) { MessageBox(NULL, "Could not find texture file", "Error", MB_OK); return NULL; } } } //done using material buffer matbuffer->Release(); return model; } This is the code to load a Model that I got from the book "Begining game programming" by Jonathoan S. Harbour. Now, for some reason when I export an X file from 3DS max and try to load it into the framework from the book it doesn't load the textures, and if I open the .X file and insert the texture name into the file then the program says "Could not find texture file". The modelk appears white as a ghost. with out any textures
Advertisement
what are you using to export the meshes from 3dsmax? Panda?! Dont forget to check the Copy Textures(or something like) option. Export it as text and take a look at the file. open it in the notepad and search for the filename of your texture. Are you setting the textures before rendering?!
.
void DrawModel(MODEL *model)
{
//draw each mesh subset
for( DWORD i=0; i<model->material_count; i++ )
{
// Set the material and texture for this subset
d3ddev->SetMaterial( &model->materials );
d3ddev->SetTexture( 0, model->textures );

// Draw the mesh subset
model->mesh->DrawSubset( i );
}
}

this function renders the model but for some reason, it wont render the texture.
void DrawModel(MODEL *model)
{
//draw each mesh subset
for( DWORD i=0; i<model->material_count; i++ )
{
// Set the material and texture for this subset
d3ddev->SetMaterial( &model->materials );
d3ddev->SetTexture( 0, model->textures );

// Draw the mesh subset
model->mesh->DrawSubset( i );
}
}

this function renders the model but for some reason, it wont render the texture.
void DrawModel(MODEL *model)
{
//draw each mesh subset
for( DWORD i=0; i<model->material_count; i++ )
{
// Set the material and texture for this subset
d3ddev->SetMaterial( &model->materials );
d3ddev->SetTexture( 0, model->textures );

// Draw the mesh subset
model->mesh->DrawSubset( i );
}
}

this function renders the model but for some reason, it wont render the texture.

P.S. Sorry for the thriple post. thought didn't go through case it was being slow.

[Edited by - directXtreme on May 9, 2007 9:11:12 PM]
May be you need to set a light I've neaver rendered any textures with out a light, may not be it, but when you said it was all white.

And also when you export it with pandatsoft set the Materials on the 3ds max objets tab and also on the Textures & fx files tab don't have Use Full PathNames selected and put all the textures in the folder of your current app.

this info was for PandaSoft 4.9.63.0 and 3DSMax 9
Quote:Original post by ankhd
May be you need to set a light I've neaver rendered any textures with out a light, may not be it, but when you said it was all white.

And also when you export it with pandatsoft set the Materials on the 3ds max objets tab and also on the Textures & fx files tab don't have Use Full PathNames selected and put all the textures in the folder of your current app.

this info was for PandaSoft 4.9.63.0 and 3DSMax 9


I did what U said: The Material checkbox is always checked, everything is default and the Left_Handed_Axis is checked. I don't know whether it's something in the LoadModel function or the DrawModel function. I use folders to put the models in then I do mode = LoadModel("foldername/model.x") when I export the model from 3DS max, it exports the textures to the directory that model is going to. So I don't know. this is driving me nuts.
Hi man,

Try :

pD3D->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pD3D->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

tell me if it worked.
There is nothing that can't be solved. Just people that can't solve it. :)
sorry, dude, still the same.......
Hey ya,
Did you check the result from the D3DXCreateTextureFromFile was it loaded
if so then did you copy the files to the same directory as your application, They are not in the xfile them selfs anyway. and are the images powers of 2
eg 256 X 256, 128, 256.

This topic is closed to new replies.

Advertisement