DirectX 9 从内存数据建立纹理Texture的方法

LPDIRECT3DTEXTURE9 m_pTexture;
D3DXCreateTexture(m_pd3dDevice, width, height, 1, 0, D3DFMT_X8R8G8B8, 
D3DPOOL_MANAGED, &m_pTexture);
m_pTexture->LockRect(0, &lockRect, NULL, 0);
unsigned char* pdata = frame.data;
unsigned char* pDstBits = (unsigned char*)lockRect.pBits;
for(int y = 0; y < frame.height; ++y)
	for(int x = 0; x < frame.width; ++x)
	{
		pDstBits[2] = pdata[0];
		pDstBits[1] = pdata[1];
		pDstBits[0] = pdata[2];
		pDstBits[3] = 255;
		pdata += 3;
		pDstBits += 4;
	}
m_pTexture->UnlockRect(0);

1、创建一个空纹理,指定大小与纹理格式

2、把纹理的Rect锁定,并填充数据,最后解锁

3、使用该纹理






  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值