缘起: 本篇在此篇基础上来写的
《精通DirectX 3D》第六章 纹理映射基础 01_TextureBase 为看如下链接做知识储备,因为不熟悉
动态纹理 玩玩DirectShow--(2) NVIDIA SDK 9.5 GPU Video Effects 截图: 过程: 这句是从图片文件来创建纹理
D3DXCreateTextureFromFile( g_pd3dDevice, L"texture.rectangle.uv.png", &g_pTexture )
我们换成动态创建纹理
g_pd3dDevice->CreateTexture(nTextureWidth, nTextureHeight, 1, D3DUSAGE_DYNAMIC
, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_pTexture, NULL)
此时运行效果如下,texture里面每个像素的数据都是未初始化的(不一定是0x00000000)
我们锁住纹理再解锁试试
// 锁住纹理
D3DLOCKED_RECT d3dLocked_rect;
if( FAILED(g_pTexture->LockRect(0, &d3dLocked_rect, 0, D3DLOCK_DISCARD)))
return E_FAIL;
// 纹理解锁
if (FAILED(g_pTexture->UnlockRect(0)))
return E_FAIL;
此时效果
看来每个像素的数据都初始化了(变成0x00000000)
我们填充下数据,让全国河山一片红
每个像素使用4个字节,即一个DWORD,我们每次填充4个像素的数据
// 填充数据
BYTE* pTextureBuffer = static_cast<BYTE*>(d3dLocked_rect.pBits);
INT nTexturePitch = d3dLocked_rect.Pitch;
for (UINT row = 0; row < nTextureHeight; ++row)
{
DWORD* pdwDest = (DWORD*)pTextureBuffer;
for (UINT column = 0; column < nTextureWidth/4; ++column)
{
pdwDest[0] = 0xFFFF0000;
pdwDest[1] = 0xFFFF0000;
pdwDest[2] = 0xFFFF0000;
pdwDest[3] = 0xFFFF0000;
pdwDest +=4;
}
pTextureBuffer += nTexturePitch;
}
啊,红了
再动动花花肠子
// 填充数据
BYTE* pTextureBuffer = static_cast<BYTE*>(d3dLocked_rect.pBits);
INT nTexturePitch = d3dLocked_rect.Pitch;
for (UINT row = 0; row < nTextureHeight; ++row)
{
DWORD* pdwDest = (DWORD*)pTextureBuffer;
UINT nPartWidth = nTextureWidth/4/4;
for (UINT column = 0; column < nPartWidth; ++column)
{
pdwDest[0] = 0xFFFF0000;
pdwDest[1] = 0xFFFF0000;
pdwDest[2] = 0xFFFF0000;
pdwDest[3] = 0xFFFF0000;
pdwDest +=4;
}
for (UINT column = nPartWidth; column < nPartWidth*2; ++column)
{
pdwDest[0] = 0xFF00FF00;
pdwDest[1] = 0xFF00FF00;
pdwDest[2] = 0xFF00FF00;
pdwDest[3] = 0xFF00FF00;
pdwDest +=4;
}
for (UINT column = nPartWidth*2; column < nPartWidth*3; ++column)
{
pdwDest[0] = 0xFF0000FF;
pdwDest[1] = 0xFF0000FF;
pdwDest[2] = 0xFF0000FF;
pdwDest[3] = 0xFF0000FF;
pdwDest +=4;
}
for (UINT column = nPartWidth*3; column < nTextureWidth/4; ++column)
{
pdwDest[0] = 0xFF000000;
pdwDest[1] = 0xFF000000;
pdwDest[2] = 0xFF000000;
pdwDest[3] = 0xFF000000;
pdwDest +=4;
}
pTextureBuffer += nTexturePitch;
}
啊,好像哪个国家的国旗啊
当然这样子的也不在话下了
posted on 2008-12-25 03:06
七星重剑 阅读(2918)
评论(3) 编辑 收藏 引用 所属分类:
Game Graphics