PDA

View Full Version : BitBLT VS ?



Androk
09-12-2002, 11:34 PM
I found out how to use BitBLT command, but just heard that there is a better way to do same thing using DirectX, Can anyone tell me how exactly do I do that? I have sprite sheet, from which I have to exctract images.

If there is DelphiX way please tell me how to use the command, and explain variables.

Thank You.

TheLion
10-12-2002, 11:01 AM
Let's see if I understand what you want to do here, you have a bitmap with a lot of sprites on it and you want to copy one sprite of that bitmap to a DirectDrawSurface... If you use DelphiX and instead of a TBitmap use a TDirectDrawSurface (works the same, just easier to work with) then you can use:

DXDraw1.Surface.Draw(X : Integer; Y : Integer; SrcRect : TRect; Source : TDirectDrawSurface; [Transparent : boolean = True])

An example of this method would be, let's say our first sprite is in the top left corner and is 64 px width and 64 px heigh and we draw it at position (20, 25):

DXDraw1.Surface.Draw(20, 25, RECT(0, 0, 64, 64), SpriteSheet, True);

if your sprites all have the same size, then the second sprite would be found at:
DXDraw1.Surface.Draw(20, 25, RECT(64, 0, 2 * 64, 64), SpriteSheet, True);

Remember however that there are 2 Surface.Draw functions, one has the ability to work with Rectangles and the other has not!

For more information on how to work with TDirectDrawSurface objects and how to draw with the TDXDraw object have a look at my tutorial at: http://members.lycos.co.uk/lionprod/articles/dxdrawtut.html


PS. I moved this topic to the DelphiX forum, since it's a specific DelphiX question! ;)


NOTE. I made a mistake in the calculation. If you have the tiled bitmaps standing next to eachother the previous calculation won't work, therefor I have changed the calculation in this message...

cairnswm
13-12-2002, 06:28 AM
If I've got an DXImageList and all the sprites are on a specific image in the image list - can I use the same funtion?

Does using a big sheet of images improve performance? I have found that using anything except the Draw function really hits my performance and am worried that the alternate draw function may slow me further.

TheLion
13-12-2002, 08:37 AM
If I'm not mistaken the DXDraw.Surface.Draw function is used by the DXImageList too, however I'm not quite sure if the DXDraw.Surface.Draw function works with the DXImagelist too.

There is a way to use tiled bitmaps (bitmap sheets) with the DXImageList, you have to specify the height and the width each image has by setting the PatternWidht and PatternHeight property of the Item (TPictureCollectionItem) of the DXImageList. If you use the DXImageList.Items[x].Draw function you just specify:

DXImageList1.Items[0].PatternWidth := 64;
DXImageList1.Items[0].PatternHeight := 64;
DXImageList1.Items[0].Draw(DXDraw1.Surface, 20, 15, 2);

Using this line, your first DXImageList1 image will be draw on the DXDraw1.Surface at position (20,15) and the 2nd image in the tiled bitmap (bitmap sheet) will be drawn ( = RECT(64, 0, 2 * 64, 64))

Shadowfax
23-12-2002, 04:28 AM
i have been having problems with speed on my tile based engine. I am using DXImageList to store the giant bitmap containing all sprites/backgrounds. Then rendering them using DXImageList.Items.Find('blah').Draw(...). But i have found that it slows the game down alot when i use small tiles.. My original plans were to use 16x16 tiles.. But it makes it terribly slow. So i have changed to 32x32 tiles. Which increases the performance alot.. Is there any other faster ways to do it?

TheLion
23-12-2002, 08:35 AM
not using DXImageList.Find :) even better not even using a DXImageList, but simply an array of TDirectDrawSurface objects. The DXImageList is yet another computer which both uses memory and your program has to go through (another layer to get to the core if you like) so it slows your code down. If I'm not mistaken the Find function iterates through all the images until the image with that exact name is found, so you'll be entering a loop which uses a lot of cpu power (100%) so all these things slow you down. I have found that a large "tiled"-bitmap (one bitmap which contains all your graphics) could even make the your application take ages to start up, a long time ago I tried adding a 5 MB bitmap to the DXImageList and the application needed about 1-2 minutes to start up.

A simple array of TDirectDrawSurface objects would solve most of these problems and the cool part of this is that you have more control and that the TDirectDrawSurface object is quite similar to a TBitmap object, however drawing to the DXDraw surface is a bit different and will require getting used to.


EDIT: Another thing you might consider (if you haven't allready) is drawing only the tiles that are visible to you on the screen instead of the entire map!

Shadowfax
27-12-2002, 06:35 AM
ok, but i managed to speed it up by only redrawing what it needs to

TheLion
27-12-2002, 09:08 AM
that's even a better solution! ;)

However to reply here to your post at the general forum, dximagelists are indeed very slow, so you might even get an extra speedboost from using a normal TDirectDrawSurface array... :) Your choice of course! ;)

Shadowfax
28-12-2002, 06:43 AM
oh.. and i tested the find vs. directly acessing the array... The speed increase is enourmous.

Useless Hacker
31-12-2002, 10:25 PM
You will probably get a benefit if you use the DXSprite engine in DelphiX. The TBackgroundSprite is ideal for drawing tiled backgrounds, and is probably faster.

Shadowfax
02-01-2003, 02:25 AM
how do you use it... Is there a DelphiX example anywhere that uses it? But i get 75fps normally usinga normal DXImageList just drawing tile after tile. And what would be the best way to have objects and other things working independantly.. the way i am doing it currently sucks.. Mine tracks different objects, i set it so there is a max 256 object on screen at once.. but sometimes it stuffs up, and it thinks there are objects around when they aren't. I dont know why... But help would be appreciated.

And how much faster would TBackgroundSprite be?

TheLion
02-01-2003, 07:43 AM
I'm very against using the DXSpriteEngine, since it has a lot of bugs and it clouds what it actually does. The bugs I'm referring too once destroyed a space invaders game I was creating (the sprites moved out of the screen after moving left and right for a while and it wasn't my mistake) and I found out it was a bug only a year later.

The TBackGround property is pretty cool though, however I never measured if it's faster so I can't deny nor admit it... Where would it get it's speed increase from you think Useless Hacker?

So to sum it up: use the DXSpriteEngine, but use it on your own risk! :)

P.S. I believe DelphiX comes with examples of about every component. The DXSpriteEngine and the TBackGround is used in the Basic Sprite example (which can be found in the samples\sprite\basic directory), just look trough the code for the word "BackGround" and the first word you'll find will be it! ;)

Shadowfax
09-01-2003, 03:54 AM
maybe some DGDev people can make an updated DelphiX.. Make it faster, and maybe use DX8.1 or 9.

TheLion
09-01-2003, 08:49 AM
I think there is something like that allready, it's called UnDelphiX...