Sign in to follow this  
kingpinzs

problem loading mesh with trancparent texture

Recommended Posts

kingpinzs    117
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
kingpinzs    117
I am using this sample code for now tell I figure out how it all works
[code]
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[i] = d3dxMaterials[i].MatD3D;

//set ambient color for material
model->materials[i].Ambient = model->materials[i].Diffuse;

model->textures[i] = NULL;
if( d3dxMaterials[i].pTextureFilename != NULL &&
lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
{
//load texture file specified in .x file
result = D3DXCreateTextureFromFile(d3ddev,
d3dxMaterials[i].pTextureFilename,
&model->textures[i]);

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[i] != NULL)
model->textures[i]->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[i] );
d3ddev->SetTexture( 0, model->textures[i] );

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

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