随笔 - 505  文章 - 1034  trackbacks - 0
<2008年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910


子曾经曰过:编程无他,唯手熟尔!

常用链接

留言簿(94)

随笔分类(649)

随笔档案(505)

相册

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

积分与排名

  • 积分 - 894865
  • 排名 - 14

最新随笔

最新评论

阅读排行榜

评论排行榜

缘起:
         本篇在此篇基础上来写的
         《精通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 七星重剑 阅读(2898) 评论(3)  编辑 收藏 引用 所属分类: Game Graphics

FeedBack:
# re: 自己动手填充动态纹理[未登录] 2010-09-02 19:26 Summer
谢谢 !! 解决了我的大问题!  回复  更多评论
  
# re: 自己动手填充动态纹理[未登录] 2010-09-02 19:31 Summer
顺便问下:
我是想动态加载camera的图像在纹理上,每帧都会更新比如BYTE * buffer = new BYTE[1280*800*4]; 这么大的数据到 纹理上。
使用你的动态纹理的方法性能已经很不错了!! thanks!

问下, 有没有比这个 更快 ,性能更佳的 办法?   回复  更多评论
  
# re: 自己动手填充动态纹理[未登录] 2011-05-27 17:03 nickolas
@Summer
用汇编是不是能快一些  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理