PDA

View Full Version : Cannot load textures from memory



chronozphere
27-01-2007, 02:22 PM
Hi all 8)

I have a problem with loading a texture from memory.
I use this code:



Stream := TMemoryStream.Create;
try
fBitmap.SaveToStream(Stream);
if fFormat = pf16bit then
fmt := D3DFMT_R5G6B5
else
fmt := D3DFMT_A8R8G8B8;
{create texture from memory}
HR := D3DXCreateTextureFromFileInMemoryEx(Graphic.fD3DDe vice,
Stream.Memory,Stream.Size,0,0,0,0,
fmt,D3DPOOL_DEFAULT,D3DX_FILTER_NONE,
D3DX_DEFAULT,fTransColor,nil,nil,fTexture);
if Failed(HR) then
begin
//Report error....
end;
finally
Stream.Free;
end;


The function returns D3DERR_INVALIDCALL but i cant figure out why, :(

Can anyone help me??
thanx

P.S doesn't seem to work :(

Clootie
27-01-2007, 03:09 PM
Maybe that is bacause you are trying to create texture with dimentions WxH = 0x0? Nil texture? :shock: :lol:
Please read decription of this function and it's parameters in documentation.

Btw, why are you using Ex variant of function?

chronozphere
27-01-2007, 05:18 PM
Maybe that is bacause you are trying to create texture with dimentions WxH = 0x0? Nil texture? Shocked Laughing
Please read decription of this function and it's parameters in documentation.


I've done that and it says:


Width
[in] Width in pixels. If this value is zero or D3DX_DEFAULT, the dimensions are taken from the file.
Height
[in] Height, in pixels. If this value is zero or D3DX_DEFAULT, the dimensions are taken from the file.

So that shouldn't be the problem. :)
Even when i do:



{create texture from memory}
HR := D3DXCreateTextureFromFileInMemoryEx(Graphic.fD3DDe vice,Stream.Memory,Stream.Size,
fBitmap.Width,fBitmap.Height,0,0,fmt,D3DPOOL_DEFAU LT,D3DX_FILTER_NONE,D3DX_DEFAULT,fTransColor,nil,n il,fTexture);



The bug is still there. :(

I am using the ex version because i want to set the transparent color and the format/filtering/mipmapping settings for the texture.
I'll implement these later.

Do you know a way of fixing this?? :?

chronozphere
28-01-2007, 09:46 AM
Seems like i have fixed the bug :)

Stream.Memory should be: Stream.Memory^ :P