DirectX-纹理渲染结果不正确 [英] directx - texture render result is incorrect

查看:126
本文介绍了DirectX-纹理渲染结果不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况1

我通过

case 1:
I create the texture by

    D3DXCreateTexture(device, width, height, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture)

并更新

    D3DLOCKED_RECT lr;
    HRESULT hr = texture->LockRect(0, &lr, NULL, 0);
    ConvertRGB2RGBA(width, height, pixels, stride, (unsigned char*)(lr.pBits), lr.Pitch);
    texture->UnlockRect(0);

渲染结果显示为:

我想要的是表面上的纯白色。

What I want is pure white on the surface.

所有顶点的z值等于0.0f。

情况2 :< br>
如果我通过

case 2:
If I create the texture by

    D3DXCreateTextureFromFile(device, "e:\\test.bmp",  &texture);

并且不更新纹理,它表示绝对正确。

and do not update the texture, it shows absolutly correct.

情况3

如果我以情况2 从文件中创建纹理,并以情况更新纹理1 ,结果不正确,有test.bmp内容。

case 3:
If I create the texture from file as case 2, and update the texture as case 1, the result is incorrect, there is test.bmp content remains slightly.

结论:

更新纹理一定有问题。

conclusion:
There must be something wrong with updating texture. What's wrong???

已解决!
将级别参数更改为1,然后就可以使用。

SOLVED!!!
Change the levels param to 1, then it works.

    D3DXCreateTexture(device, width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture)


推荐答案

将级别参数更改为1,然后可以使用。

Change the levels param to 1, then it works.

D3DXCreateTexture(device, width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture)

这篇关于DirectX-纹理渲染结果不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆