Exemplo n.º 1
0
Material::Material(char* name, char* path) : Resource<Material>(name, path)
{
    D3DXIMAGE_INFO info;
    Script* script = new Script(name, path);

    if( script->GetColourData( "transparency" )->a == 0.0f )
    {
        // Load the texture without transparency.
        D3DXCreateTextureFromFileEx( Engine::GetInstance()->GetDevice(), script->GetStringData( "texture" ), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, 0, &info, NULL, &m_texture);
    }
    else
    {
        // Load the texture using a transparency colour value.
        D3DCOLORVALUE *colour = script->GetColourData( "transparency" );
        D3DCOLOR transparency = D3DCOLOR_COLORVALUE( colour->r, colour->g, colour->b, colour->a );
        D3DXCreateTextureFromFileEx( Engine::GetInstance()->GetDevice(), script->GetStringData( "texture" ), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, transparency, &info, NULL, &m_texture);
    }

    m_width = info.Width;
    m_height = info.Height;

    m_lighting.Diffuse = *script->GetColourData("diffuse");
    m_lighting.Ambient = *script->GetColourData("ambient");
    m_lighting.Specular = *script->GetColourData("specular");
    m_lighting.Power = *script->GetFloatData("power");

    m_ignoreFace = *script->GetBoolData("ignore_face");
    m_ignoreFog = *script->GetBoolData("ignore_fog");
    m_ignoreRay = *script->GetBoolData("ignore_ray");

    SAFE_DELETE(script);
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// The material class constructor.
//-----------------------------------------------------------------------------
Material::Material( char *name, char *path ) : Resource< Material >( name, path )
{
	D3DXIMAGE_INFO info;

	// Load the script for this material.
	Script *script = new Script( name, path );

	// Check if the material's texture has transparency.
	if( script->GetColourData( "transparency" )->a == 0.0f )
	{
		// Load the texture without transparency.
		D3DXCreateTextureFromFileEx( g_engine->GetDevice(), script->GetStringData( "texture" ), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, 0, &info, NULL, &m_texture );
	}
	else
	{
		// Load the texture using a transparency colour value.
		D3DCOLORVALUE *colour = script->GetColourData( "transparency" );
		D3DCOLOR transparency = D3DCOLOR_COLORVALUE( colour->r, colour->g, colour->b, colour->a );
		D3DXCreateTextureFromFileEx( g_engine->GetDevice(), script->GetStringData( "texture" ), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, transparency, &info, NULL, &m_texture );
	}

	// Store the width and height of the texture.
	m_width = info.Width;
	m_height = info.Height;

	// Set the material's lighting properties.
	m_lighting.Diffuse = *script->GetColourData( "diffuse" );
	m_lighting.Ambient = *script->GetColourData( "ambient" );
	m_lighting.Specular = *script->GetColourData( "specular" );
	m_lighting.Emissive = *script->GetColourData( "emissive" );
	m_lighting.Power = *script->GetFloatData( "power" );

	// Set the ignore face flag.
	m_ignoreFace = *script->GetBoolData( "ignore_face" );

	// Set the ignore fog flag.
	m_ignoreFog = *script->GetBoolData( "ignore_fog" );

	// Set the ignore ray flag.
	m_ignoreRay = *script->GetBoolData( "ignore_ray" );

	// Destory the material's script.
	SAFE_DELETE( script );
}