Create Texture From File

Jul 15, 2014 at 8:18am
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);
	}
}
Jul 15, 2014 at 9:58am
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 Jul 15, 2014 at 10:00am
Jul 15, 2014 at 10:16am
D3DXCreateTextureFromFileInMemory works though if I don't wrap it in my own function
Jul 15, 2014 at 10:24am
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 Jul 15, 2014 at 10:29am
Jul 15, 2014 at 10:41am
Whats the best way to wrap it in my own function then?
Jul 15, 2014 at 11:28am
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);
	}
}
Jul 16, 2014 at 1:07pm
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.