Jump to content
  • Advertisement
Sign in to follow this  

converting an image to a directx texture

This topic is 3001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I am using freeImage to load images in to memory. When I tried to create a dx texture from these images, I found out that, I don't know internal format of the data which decoded and loaded to memory by freeImage, I can learn bits per pixel from freeImage, I also can get internal formats of images from freeImage like FIT_RGB16, and I can pick the best matched format from DXGI_FORMAT list, but what if there isn't a match at all ?
I believe handling (sampling, looking up, loading ...) texture data entirely depends on this texture format, that is freeImage format and directx texture format must match, what should I do if I have a 8 bit or 16 bit bitmap format ? they are not present in dx, does matching only bpps work ? Can you give an example of converting a standar 8 bit image to directx texture (in dx10 or 11) ?

thank you for your answers.

Share this post

Link to post
Share on other sites
Uyuşmayan formatlarla ilgili bir örnek verirsen daha iyi olur, bu bir. Çünkü DX te neredeyse tüm resim formatları var. Demişsin ki, "8 ya da 16 bir BMP ler söz konusu olduğunda ne yapacağım". Eğer yanlış anlamadıysam, bunların DX te tanımlanmadığını söylüyorsun. Halbuki, örneğin 8-bit BMP nin DX teki karşılığı DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT ten biri olmalı gibime geliyor.

İkinci husus olarak da kaplama doldurma var:
LockRect() ile D3D kaplamasına ilişkin bilgilere, pixel pixel erişebilirsin. Veya başka bir yöntem olarak da D3DXFillTexture() fonksiyonundan türetme fonksiyon yazarak ilgili kaplamayı doldurabilirsin. İkinci yöntem daha kolay.

Örnek (DX9 için ama DX10 veya 11 için de kullanılabileceğini zannediyorum);

//tanımlamaya dikkat!
VOID WINAPI KaplamaDoldurmaca (D3DXVECTOR4* pOut, const D3DXVECTOR2* pTexCoord, const D3DXVECTOR2* pTexelSize, LPVOID pData)
//I don't know how you get custom texture data from freeImage, or how they are stored.
// But I suppose datas are stored in an array like this: customTexData [1024][768];

float u = (*pTexCoord).x, v = (*pTexCoord).y;
float pixelX = u * yourCustomTextureWidth,
pixelY = v * yourCustomTextureHeight;

DWORD data = customTexData[(UINT)pixelX - 1] [(UINT)pixelY - 1];

D3DXCOLOR retColor (data);
D3DXVECTOR4 retData (retColor.r, retColor.g, retColor.b, retColor.a);

*pOut = retData;

Bu fonksiyonu yazdıktan sonra, doldurma işlemini başlatmak için;
D3DXFillTexture (yourTextureYouWantToFill, KaplamaDoldurmaca, NULL);

[In English]First, it'd better if you give us an example about format matching problem. Because, I think, all the image formats must be defined in DX. You ask that what could you do about 8 / 16 bit BMP formats. I think, a 8-bit BMP format equals to one of these: DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT.

And about the other issue, copying custom texture data to a DX texture. You can use LockRect() or a custom function like D3DXFillTexture(). I think, the second one would be easier.

And here's an example (for DX9, but I believe this can be used for either DX10 or 11:
(The code above)

Then, use this function to as a parameter to D3DXFillTexture:
D3DXFillTexture (yourTextureYouWantToFill, KaplamaDoldurmaca, NULL);
[/In English]

Umarım yardımı dokunur (hth)

Share this post

Link to post
Share on other sites
thank you for your answer, I thought that 8 bit bitmap means a pixel which takes 8 bits in memory, however R8G8B8A8 is 32bit (I am not sure about this, but I strongly believe this is correct, please fix me if I am wrong) but I found an example which uses Devil to create a dx texture from an image, he converts what ever the format is lets say R5G6B5 to a R8G8B8A8 this way he ensure to match formats in directx and Image data.

here is the link,


filling the data pixel by pixel into a buffer which I create in what ever format I want is an other way too as you mention, but I think this kind of operations requires texture usage to be D3D11_USAGE_DYNAMIC,this may be in efficient.

Share this post

Link to post
Share on other sites
I also want to add this, I search about 8bit images, they are palletized images, that is each pixel corresponds to a color in the pallet, this must be why directx didn't implement this format, pallets reduces the size but, directx must now about this pallet too.

Share this post

Link to post
Share on other sites
Load that texture via DX :
D3DX11CreateTextureFromFile( ... );

Get it's level-0 description:
ID3D11Texture2D::GetDesc ( ... );

Look it's format:
DXGI_FORMAT surfFmt = returningDescFromPreviousStep.Format;

I wonder what it is :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!