Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualEvil Steve

Posted 07 February 2012 - 04:50 PM

The 3rd parameter to CreateTexture() is the number of mip levels to generate, with 0 meaning "All, down to 1x1". NULL evaluates to 0, so you're generating a texture with a full mip chain. I'm not sure what the texture contains when it's created, but I'd assume that it's either undefined or all 0 bytes. If you have 0 bytes, then you'll end up with the alpha channel being set to 0 in the lower mips. If you generate the lower mips with a call to GenerateMipSubLevels, then you may end up with the texture getting blurred and the alpha channel messed up - especially if the texture has a lot of alpha in it.

In either case, you ned up with a texture that has a lot of alpha in the lower mips, and the lower mips are displayed when the texture is further away. Setting the mip filter to linear means the two closest mip levels are linearly interpolated to give the output colour, and not setting it means it stays at point (I.e. no mip filtering).
I can only assume that your particular setup makes the linear interpolation go screwy somehow.

What happens if you use D3DXSaveTextureToFile, save as .dds and then use the DirectX texture tool to look at the lower mip levels?

Also, slightly off topic, your code won't work correctly if the texture is not a multiple of 4 in width and height. It should be:
CopyMemory(rc.pBits, pTextureData+4, ((width+3)/4) * ((height+3)/4) * 16);

#1Evil Steve

Posted 07 February 2012 - 04:50 PM

The 3rd parameter to CreateTexture() is the number of mip levels to generate, with 0 meaning "All, down to 1x1". NULL evaluates to 0, so you're generating a texture with a full mip chain. I'm not sure what the texture contains when it's created, but I'd assume that it's either undefined or all 0 bytes. If you have 0 bytes, then you'll end up with the alpha channel being set to 0 in the lower mips. If you generate the lower mips with a call to GenerateMipSubLevels, then you may end up with the texture getting blurred and the alpha channel messed up - especially if the texture has a lot of alpha in it.

In either case, you ned up with a texture that has a lot of alpha in the lower mips, and the lower mips are displayed when the texture is further away. Setting the mip filter to linear means the two closest mip levels are linearly interpolated to give the output colour, and not setting it means it stays at point (I.e. no mip filtering).
I can only assume that your particular setup makes the linear interpolation go screwy somehow.

What happens if you use D3DXSaveTextureToFile, save as .dds and then use the DirectX texture tool to look at the lower mip levels?

Also, slightly off topic, your code won't work correctly if the texture not a multiple of 4 in width and height. It should be:
CopyMemory(rc.pBits, pTextureData+4, ((width+3)/4) * ((height+3)/4) * 16);

PARTNERS