Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: BitBLT VS ?

  1. #1

    BitBLT VS ?

    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.

  2. #2

    BitBLT VS ?

    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/...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...
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  3. #3
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    BitBLT VS ?

    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.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  4. #4

    BitBLT VS ?

    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))
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  5. #5

    BitBLT VS ?

    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?

  6. #6

    BitBLT VS ?

    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!
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  7. #7

    BitBLT VS ?

    ok, but i managed to speed it up by only redrawing what it needs to

  8. #8

    BitBLT VS ?

    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!
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  9. #9

    BitBLT VS ?

    oh.. and i tested the find vs. directly acessing the array... The speed increase is enourmous.

  10. #10

    BitBLT VS ?

    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.
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •