Skip to main content
GameDev.net gamedev.net
🔒 Locked

Direct3d textures

Started by didalabu2 Nov 7, 2004 at 11:31 AM 4 replies 1.2k views
Original Post
didalabu2
didalabu2
How to i go about creating a texture from a custom image format? I know how to do this in opengl by specifically passing in the array of bytes that make up the image. Every function that I can find for Direct3D makes you create a texture from a known file (format) or resource. Thanks for the help!
ms291052
ms291052
Check out these handy functions:

HRESULT D3DXCreateTextureFromFileInMemory( LPDIRECT3DDEVICE9 pDevice,
LPCVOID pSrcData,
UINT SrcData,
LPDIRECT3DTEXTURE9 *ppTexture
);

HRESULT D3DXCreateTextureFromFileInMemoryEx( LPDIRECT3DDEVICE9 pDevice,
LPCVOID pSrcData,
UINT SrcDataSize,
UINT Width,
UINT Height,
UINT MipLevels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
DWORD Filter,
DWORD MipFilter,
D3DCOLOR ColorKey,
D3DXIMAGE_INFO *pSrcInfo,
PALETTEENTRY *pPalette,
LPDIRECT3DTEXTURE9 *ppTexture
);

HRESULT D3DXCreateTextureFromResource( LPDIRECT3DDEVICE9 pDevice,
HMODULE hSrcModule,
LPCTSTR pSrcResource,
LPDIRECT3DTEXTURE9 *ppTexture
);

HRESULT D3DXCreateTextureFromResourceEx( LPDIRECT3DDEVICE9 pDevice,
HMODULE hSrcModule,
LPCTSTR pSrcResource,
UINT Width,
UINT Height,
UINT MipLevels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
DWORD Filter,
DWORD MipFilter,
D3DCOLOR ColorKey,
D3DXIMAGE_INFO *pSrcInfo,
PALETTEENTRY *pPalette,
LPDIRECT3DTEXTURE9 *ppTexture
);

Sound good?
drekkar
drekkar
alternatively you could create a texture, lock it, and write it how you please

	if(FAILED(pD3DDevice->CreateTexture(32, 32, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture)))		return 0;	D3DLOCKED_RECT LockedRect;	pTexture->LockRect(0, &LockedRect, 0, 0);	DWORD* bits = (DWORD*) LockedRect.pBits;// from here just load your color info however you want :P	int x, y;	for(y=0; y<32; y++){		for(x=0; x<32; x++){			bits[x+(y*(LockedRect.Pitch >> 2))] = D3DCOLOR_ARGB(128, x, y, 255);		}	}// finally dont forget to unlock	pTexture->UnlockRect(0);
didalabu2
didalabu2
Suppose I just have an array of bytes in memory.

I dont see how those functions will let me take my array and make a texture out of it???
Pipo DeClown
Pipo DeClown
You'll have to fill the texture like this.

1) Use D3DXCreateTexture(...) to create a texture of some format.
2) Lock the texture.
3) Fill the texture.
4) Unlock the texture.

Now you have the data in the texture.
didalabu2
didalabu2
thanks guys

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.