简体   繁体   English

C ++ DirectX Muliti纹理

[英]c++ directx muliti textures

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.............. 例如,如果我想做一个骰子,我的顶数应该是1边是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);

What you do is create a texture and put the 6 faces of the dice into that one texture. 您要做的是创建一个纹理并将骰子的6个面放入该一个纹理中。 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. 然后,对于每个面,使用与要在其上具有骰子面的纹理部分相对应的UV。

Failing that ... you draw 6 times. 失败的话...您画了6次。 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 ... 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. 我所描述的第一种方法很可能仍将为您提供最佳性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM