Jump to content
  • Advertisement
Sign in to follow this  
sinyester

Loading .x, no texture showing..

This topic is 2229 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

Solved!
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 ^^

>.< angry.png

Hey!

I'm trying to load a .x model ([size=2]a polygon sphere). 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";}



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 = d3dxMaterials.MatD3D; //grab mat
model->materials.Ambient = model->materials.Diffuse; // set ambient for mat

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

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);
d3ddev->SetTexture(0, model->textures);

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

}


Best regards Edited by sinyester

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!