TextureLoader.FromFile(Device,String)

FromFile メソッド

使用例

ファイルを基にしてテクスチャを作成する。

定義

Visual Basic Public Shared Function FromFile( _
    ByVal device As Device, _
    ByVal srcFile As String _
) As Texture
C# public static Texture FromFile(
    Device device,
    string srcFile
);
Managed C++ public: static Texture* FromFile(
    Devicedevice,
    StringsrcFile
);
JScript public static function FromFile(
    device : Device,
    srcFile : String
) : Texture;

パラメータ

device Microsoft.DirectX.Direct3D.Device.
srcFile System.String.

戻り値

Microsoft.DirectX.Direct3D.Texture.

使用例

ファイルを基にしたテクスチャの作成

この例では、ビットマップ化したテクスチャ ファイルをロードする方法を示す。

ファイルを基にして、テクスチャ値を含むテクスチャ オブジェクトを作成するには、TextureLoader.FromFile メソッドを呼び出す。この例では、オーバーロードされた FromFile(Device,String) メソッドが呼び出される。このメソッドは Device 名とファイルの場所を示す文字列を引数にとる。

次は、アプリケーション定義の OnResetDevice メソッドに対し、各呼び出しでロードされるテクスチャ値である。

using Microsoft.DirectX.Direct3D;
.
.
.
// Global variables for this project
Device device = null; // Rendering device
Texture texture = null;

// Initialize the device
.
.
.
// Device reset method
public void OnResetDevice(object sender, EventArgs e)
{
    Device dev = (Device)sender;
    
    // Now create the texture
    texture = TextureLoader.FromFile(dev, Application.StartupPath + 
                                              @"\..\..\banana.bmp");
}

メッシュを基にしたテクスチャの作成

この例は、メッシュから作成されたテクスチャ オブジェクトに対し、ビットマップ化されたテクスチャ ファイルを適用する方法である。

アプリケーション定義の OnResetMeshDevice メソッドは次の内容を実行する。

  1. メッシュ要素は、Mesh.FromFile(String,MeshFlags,Device,ExtendedMaterial[]) を使ってファイルからロードする。
  2. ExtendedMaterial マテリアル バッファにファイルのデータを書き込む。
  3. テクスチャ名およびマテリアル プロパティは、Material3D を使って、マテリアル バッファから抽出する。
  4. ファイルから取得したテクスチャ値は FromFile(Device,String) を使って、各メッシュ要素に適用する。
using Microsoft.DirectX.Direct3D;

public class Meshes : System.Windows.Forms.Form
{
    // Global variables for this project
    Device device = null;              // Rendering device
    Mesh mesh = null;                  // Mesh object
    Direct3D.Material[] meshMaterials; // Materials structure for mesh
    Texture[] meshTextures;            // Textures structure for mesh

    public bool InitializeGraphics()   // Initialize the Direct3D object
    {
        .
        .
        .
        // Call method to reset mesh device
        device.DeviceReset += new System.EventHandler(this.OnResetMeshDevice);
        .
        .
        .
    }
    
    // Mesh device reset method
    public void OnResetMeshDevice(object sender, EventArgs e) 
    {
        ExtendedMaterial[] materials = null;
        Device dev = (Device)sender;
        
        // Set up the directory to load the proper data
        System.IO.Directory.SetCurrentDirectory(
                 System.Windows.Forms.Application.StartupPath +  @"\..\..\");
        
        // Load the mesh from the specified file
        mesh = Mesh.FromFile("tiger.x", MeshFlags.SystemMem,
                             device, out materials);

        // Extract texture names and material properties from material buffer
        meshTextures  = new Texture[materials.Length];
        meshMaterials = new Direct3D.Material[materials.Length];
        for( int i=0; i<materials.Length; i++ )
        {
            meshMaterials[i] = materials[i].Material3D;
            
            // Set the ambient color for the material
            meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
            
            // Create the texture
            meshTextures[i] = TextureLoader.FromFile(dev,
                                            materials[i].TextureFilename);
        }
        .
        .
        .
    }
    
    static void Main()
    {
        Meshes frm = new Meshes();
        if (!frm.InitializeGraphics())
        {
            // Error handling
        }
        System.Windows.Forms.Application.Run(frm);
    }
}

対象

TextureLoader

© 2002 Microsoft Corporation. All rights reserved. Terms of use.