• Advertisement
Sign in to follow this  

problem loading mesh with trancparent texture

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

I am using D3DXLoadMeshFromX and D3DCreateTextureFromFile but it doesnt show transpaerncy with the texture

hw can I acomplish this? I am using directx 9c and c++

Share this post


Link to post
Share on other sites
Advertisement
I am using this sample code for now tell I figure out how it all works

ODEL *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;
}

VOID DeleteModel(MODEL *model)
{
//remove materials from memory
if( model->materials != NULL )
delete[] model->materials;

//remove textures from memory
if (model->textures != NULL)
{
for( DWORD i = 0; i < model->material_count; i++)
{
if (model->textures != NULL)
model->textures->Release();
}
delete[] model->textures;
}

//remove mesh from memory
if (model->mesh != NULL)
model->mesh->Release();

//remove model struct from memory
if (model != NULL)
free(model);

}

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 );
}
}


Share this post


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

  • Advertisement