Create Texture From File

Im having problems with this little function im making

for some reason the texture dont get created (messagebox never gets called)

Im trying to pass a BYTE array of a image to the function

1
2
3
4
5
6
7
8
void AddTexture(BYTE* texture)
{
	LPDIRECT3DTEXTURE9 Direct3DTexture = NULL;
	if (D3D_OK == D3DXCreateTextureFromFileInMemory(pDevice, &texture, sizeof(texture), &Direct3DTexture))
	{
		MessageBoxA(NULL, "created", "created", MB_OK);
	}
}
The third argument is supposed to be the size of the file in memory. sizeof(texture) gives you the size of the texture pointer (probably 4 or 8 bytes).
Last edited on
D3DXCreateTextureFromFileInMemory works though if I don't wrap it in my own function
Note that the type is important when using sizeof. If texture is an array it will return the size of the array. If texture is a pointer it will return the size of the pointer.

1
2
3
4
5
6
7
8
9
10
11
12
void SomeOtherFunction()
{
	BYTE texture[1000];
	// texture is an array here.
	// sizeof(texture) will return 1000.
}

void AddTexture(BYTE* texture)
{
	// texture is a pointer here. 
	// sizeof(texture) will return the size of the pointer (usually 4 or 8).
}
Last edited on
Whats the best way to wrap it in my own function then?
1
2
3
4
5
6
7
8
void AddTexture(BYTE* texture, UINT size)
{
	LPDIRECT3DTEXTURE9 Direct3DTexture = NULL;
	if (D3D_OK == D3DXCreateTextureFromFileInMemory(pDevice, &texture, size, &Direct3DTexture))
	{
		MessageBoxA(NULL, "created", "created", MB_OK);
	}
}
I tried it just like that before i made this topic.
But it dont create the texture using it like that
Topic archived. No new replies allowed.