我花了一个下午的时间查看上下文/表面上的文档,并遵循了相当多的指南,但我只是不明白这是如何做到的。
我想要的是使用一个位图(已经加载),并把它放在我的场景作为背景。
我听说我必须先画一个曲面,但我完全不知道如何获得曲面,也不知道如何将位图分配给它。
任何帮助都是非常感谢的。
发布于 2016-01-26 05:36:05
是的,一种方法是使用Surface,但是我会推荐这种方法
我不知道您是如何加载位图的,不管怎样,您可以这样使用位图作为背景。
//Make texture object
LPDIRECT3DTEXTURE9 m_myBitmapTexture;
// During Initialization, Load texture from file
if(FAILED(D3DXCREATETEXTUREFROMFILE(device,"filepath\\file.bmp", 0, 0, 0, D3DMFT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFULT, D3DX_DEFAULT, 0x00000000, NULL, NULL, *m_myBitmapTexture)))
return E_FAIL;
// During Rendering, set texture
device->SetTexture(0, m_myBitmapTexture);
device->SetStreamSource(0, yourBuffer, 0, size(YourBufferStruct));
device->SetFVF(yourTextureFVF); // Setting flexible vertex format
device->DrawPrimitive(topologyType, startindex, totalIndex);你只需要确保,你的缓冲区应该有纹理坐标,你的阴影也应该有。
struct YourBufferStruct
{
D3DXVECTOR3 position;
D3DXVECTOR2 textureCoord;
}
// Define your flexible vertex format, i am just adding position and texture,
//well you can add color, normal whatever extra you want
#define yourTextureFVF (D3DFVF_XYZ | D3DFVF_TEX1) 现在也向着色器添加纹理坐标。
有关更多详细信息,请参阅此链接https://msdn.microsoft.com/en-us/library/windows/desktop/bb153262(v=vs.85).aspx。
https://stackoverflow.com/questions/35006407
复制相似问题