Sign in to follow this  

Loading Custom Image formats for Direct3D

This topic is 4854 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 have been looking around the MSDN site lately and i have yet to find any help on this (searched Game Dev as well as some other places). How would i load my own image format to Direct3D. I can't use the D3DXLoadTextureFromFile because my image format differs from the ones D3D supports. I know i need to place pixels to the surface but there seems to be no information on MSDN on how to do this. Should i just load my image format and then use D3DX to use it like a file format that is supported?

Share this post


Link to post
Share on other sites
Once it's loaded you just need to create a texture, lock it and transfer the pixel data inside, then unlock it.

This way you have to take care of pixel format conversion though. Never rely on any specific pixel format to be supported by a gfx card. Always enumerate the supported formats and pick the most appropriate one.

Share this post


Link to post
Share on other sites
How would i do that though, how would i transfer the pixel data.

Like what functions would i use to do that. If anyone has any tutorials or sites on this could you link me?

Share this post


Link to post
Share on other sites
You usually can't use functions unless the pixel format of your loaded image data is exactly the same as that of the surface.

Then you can use memcpy to copy line per line to the target (line per line because of the pitch).

If you have to convert in between it's just getting a value from a pointer and writing a value to a pointer.

With memcpy it looks like this (this example using 24bit RGB)

unsigned char* pTarget // acquired from the lock
unsigned char* pSource // pointing to your source data

for ( int iY = 0; iY < iHeight; ++iY )
{
memcpy( pTarget,
pSource,
iWidth * 3 );
pSource += iWidth * 3; // assuming your source data has no padding
pTarget += pPitch; // the pitch you got from locking
}

Share this post


Link to post
Share on other sites

This topic is 4854 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this