0

Since a few days im working on a tool where i need to draw textures on several file format with directX 11. After googling a lot, i didnt found how to do.

I'm using D3DX11CreateShaderResourceViewFromFile for load .dds and .png files, but i read somewhere else that .tga isn't supported anymore. I read something too about D3DLOCKED_RECT to set each pixels of the texture, and read .tga files to know these pixels, but that was for directX 9.

Any help or tips? Thanks in advance.

Aulaulz
  • 459
  • 4
  • 15
  • TGA is inferior in nearly every aspect compared to PNG. Can you simply convert your files? – Bartek Banachewicz Jul 20 '13 at 12:16
  • No, unfortunately i must keep theses differents file format. Because my tool create a .txt file that will be used this another program, so the users will have to convert again, not really practical. – Aulaulz Jul 20 '13 at 13:31
  • 2
    @BartekBanachewicz: Nope. PNG takes much longer to decompress. – SigTerm Jul 20 '13 at 13:56

1 Answers1

0

//note: I don't use D3D11

MSDN page for D3DX11CreateShaderResourceViewFromFile says there is DirectXTex library, that should be able to load *.tga files using LoadFromTGAFile routine. You should give it a try. If it doesn't work for you, you'll have to write your own texture loader. (because it was possible to make your loader for textures in D3D9, it should be possible to do the same thing in D3D11). *.tga format is documented somewhere and many beginner tutorials specifically deal with loading this particular format without 3rd party libraries.

Two advices:

  1. Next time, when in doubt, read documentation.
  2. DON'T look at *.png format. This format loads very slowly (jpeg is faster, uncompressed bmp is faster, dds is faster) and most likely isn't suitable for games that need to load many images often (it is okay to use it for start menu, ending screen, etc). Either use uncompressed format (such as *.tga) or (since you're using directx) use *.dds format. Your images most likely will take extra disk space, but will load more quickly.
SigTerm
  • 26,089
  • 6
  • 66
  • 115
  • I was more interested by setting the texture pixel by pixel and read the file format for know these pixel than use another library, and i found how to do. Btw thanks for help. If someone is interested by this, follow this link http://www.gamedev.net/topic/583161-d3d11-creating-a-dynamic-texture/ – Aulaulz Jul 21 '13 at 02:58
  • @Aulaulz: You don't ever set textures pixel by pixel. You LOCK it, then dump entire pixel array into memory at once, and then unlock it. In DX9 generating mipmaps for the texture could also be your responsibility. – SigTerm Jul 22 '13 at 01:59
  • I would have to, if i had to use D3D9, but i use D3D11, and there is no Lock and Unlock function. Anyway, what i've done to resolve my problem is setting pixel at the texture creation, with the D3D11_SUBRESOURCE_DATA parameter in function ID3D11Device::Create2DTexture. – Aulaulz Jul 23 '13 at 06:49