PDA

View Full Version : Texture + Bitmap + GDI drawing



chronozphere
09-01-2007, 06:36 PM
Hi PGD Guys 8)

I have a few questions:

I want to create a texture using D3DXCreateTextureFromFileInMemory but how can i setup a bitmapfile in memory???
What datastructures to use? :?

Secondly i want to perform GDI drawing operations on that bitmap. So when i've changed the bitmap, i can upload it again to video RAM to apply the changes. :)

Can someone provide me with some info on how to setup a bitmap, draw on it using GDI stuff and loading it using D3DXCreateTextureFromFileInMemory.

Thank you :)

BTW: is there a way to reload a texture from ram. (if that's possible, i dont have to create a new one , each time it must be updated)

chronozphere
11-01-2007, 01:58 PM
ah... i've just figured it out myself :lol:

I've modified the Texturing tutorial in Clooties SDK.
Here is a piece of code:


var BMP: TBitmap;
Memstream: TMemoryStream;
begin
BMP := TBitmap.Create;
MemStream := TMemoryStream.Create;
try
BMP.LoadFromFile('banana.bmp');
BMP.SaveToStream(MemStream);

if FAILED(D3DXCreateTextureFromFileInMemory(
g_pd3dDevice,MemStream.Memory^,MemStream.Size,g_pT exture))
then Exit;
finally
MemStream.Free;
BMP.Free;
end;
...


It's easier then i thought. You just keep the Bitmap in ram, change it, and update it using a MemoryStream. Pascal is sooow easy :)

Have fun. ;)

EDIT: the only disadvantage is that you have to create a new texture for each update... Is there a way to update the pixeldata from a TBitmap to the texture??? :?

Galfar
12-01-2007, 01:54 PM
the only disadvantage is that you have to create a new texture for each update... Is there a way to update the pixeldata from a TBitmap to the texture??? :?

You can lock that D3D texture and copy pixels from bitmap into it. Lock gives you pointer to texture data so you can use Move to copy data here (from Bitmap.Scanline). Texture and bitmap pixel formats must be the same of course.

chronozphere
12-01-2007, 02:39 PM
?łeah thanx... That should work for 32bit A8R8G8B8 textures, i think :)
but it raises another question:

How is the pixeldata stored in a 16bit bitmap??
Is it like R5G6B5 or X1R5G5B5 or some other format??

Galfar
12-01-2007, 03:09 PM
Most 16bit bitmaps are in X1R5G5B5 format but bitmap files can store R5G6B5, A4R4G4B4, and more formats too (uses custom channel bitmasks). I've just briefly looked at VCL TBitmap and seems that it uses pf15Bit for X1R5G5B5 bitmaps, pf16Bit for R5G6B5, and pfCustom for 16bit bitmaps with other channel masks.

chronozphere
12-01-2007, 03:57 PM
Thank you very much :razz:

That's the info i needed :)