directx - texture render result is incorrect

随声附和 提交于 2019-12-23 02:20:12

问题


case 1:
I create the texture by

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

and update the texture with white color.

    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);

the render result shows as:

What I want is pure white on the surface.

The z value of all the vertexes equals to 0.0f.

case 2:
If I create the texture by

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

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

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???


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

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

回答1:


Congratulations. When the mipmap level argument of D3DXCreateTexture is set to 0, full mipmapped texture will be created. If you want to use mipmaps, your function ConvertRGB2RGBA should cover not only the top level texture, but also lower level textures.




回答2:


Change the levels param to 1, then it works.

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


来源:https://stackoverflow.com/questions/12400167/directx-texture-render-result-is-incorrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!