Sign in to follow this  
sinyester

Loading .x, no texture showing..

Recommended Posts

sinyester    102
[size=5]Solved![/size]
The problem was that the texture was located in the folder: mesh/lightblue.jpg, and when it searched for the texture it search in the root and not in the mesh folder. When I moved both files to the root it worked ^^

>.< [img]http://public.gamedev.net//public/style_emoticons/default/angry.png[/img]

Hey!

I'm trying to load a .x model ([size=2]a polygon sphere[/size]). It looks like it should in a 3dviewer but in my game it shows up without texture. The texture is a .jpg and is located in the same folder as the .x model. I get the "MessageBox - Couldn't find texture file".

sphere.x code: [size=2]TextureFilename {"lightblue.jpg";}[/size]


[CODE]
struct MODEL
{
LPD3DXMESH mesh;
D3DMATERIAL9* materials;
LPDIRECT3DTEXTURE9* textures;
DWORD material_count;
};

MODEL *LoadModel(char *filename)
{
MODEL *model = (MODEL*)malloc(sizeof(MODEL));
LPD3DXBUFFER matbuffer;
HRESULT result;

result = D3DXLoadMeshFromX(
filename,
D3DXMESH_SYSTEMMEM,
d3ddev,
NULL,
&matbuffer,
NULL,
&model->material_count,
&model->mesh);

if (result != D3D_OK)
{
MessageBox(NULL, "Error loading mdoel", "ERROR",MB_OK);
return NULL;
}

D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)matbuffer->GetBufferPointer();
model->materials = new D3DMATERIAL9[model->material_count];
model->textures = new LPDIRECT3DTEXTURE9[model->material_count];

for (DWORD i=0; i<model->material_count; i++)
{

model->materials[i] = d3dxMaterials[i].MatD3D; //grab mat
model->materials[i].Ambient = model->materials[i].Diffuse; // set ambient for mat

model->textures[i] = NULL;
if(d3dxMaterials[i].pTextureFilename != NULL &&
lstrlen(d3dxMaterials[i].pTextureFilename) > 0)
{
result = D3DXCreateTextureFromFile(d3ddev,
d3dxMaterials[i].pTextureFilename,
&model->textures[i]);

if (result != D3D_OK)
{
MessageBox(NULL,"Couldn't find texture file","ERROR",MB_OK);
}
}

}
matbuffer->Release();

return model;
}

void DrawModel(MODEL *model)
{
for (DWORD i=0; i < model->material_count; i++)
{
d3ddev->SetMaterial(&model->materials[i]);
d3ddev->SetTexture(0, model->textures[i]);

model->mesh->DrawSubset(i);
}

}
[/CODE]

Best regards Edited by sinyester

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this