0
votes

How can I set set more than one texture on a cube like the front of the cube has different texture from the back of it....

I tired to use the stages but it didn't work. for example, if i wanna make a dice i would have top would be 1 side be 2..............

D3DXCreateTextureFromFile(d3ddev,   //Direct3D Device
                                _T("image.png"),       //File Name
                                &g_texture);    //Texture handle

    d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);    // turn off the 3D lighting
    d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);    // turn off culling
    d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
 d3ddev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
    d3ddev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
    d3ddev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);   //Ignored

    d3ddev->SetTexture(1,g_texture);

 D3DXCreateTextureFromFile(d3ddev,   //Direct3D Device
                                _T("images.png"),       //File Name
                                &texture2);    //Texture handle



    d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);    // turn off the 3D lighting
    d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);    // turn off culling
    d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
 d3ddev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
    d3ddev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
    d3ddev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);   //Ignored

 d3ddev->SetTexture(0, texture2);
1

1 Answers

1
votes

What you do is create a texture and put the 6 faces of the dice into that one texture. Then for each face you use the UVs that correspond to the portion of the texture that has the dice side you want on it.

Failing that ... you draw 6 times. Once for each texture.

The former method is by far the best way to do it if you can though. Less draw calls is better with DirectX 9 ...

Edit: Actually, in fairness, there are a few other ways you could do it. You could use a volume texture and put each die face in one slice and then render that slice on to the face of the cube. Or, you could also use a cube texture and set it up so that the texture look up occurs on to the face you want.

The first method I described will still, most probably, give you the best performance though.