Results 1 to 6 of 6

Thread: Updating a TDirectDrawSurface

  1. #1

    Updating a TDirectDrawSurface

    I have a component that pumps out 29 bitmaps a second. I want to use DelphiX to display them stretched to the size of the display. (Note: These bitmaps are not known until runtime)

    I originally tried to load each bitmap into the same slot in a DXImageList but that lead to many memory leaks and errors.

    Now I am trying to use a single TDirectDrawSurface as a buffer that holds the image and it is then drawn to the screen(DXDraw) on a DXTimer event. But the issue I am having is I cannot get another image into it after the initial image.

    Here is the initialization (Test) code

    Code:
    Surf : TDirectDrawSurface.
    
    procedure TForm1.DisplayInitialize(Sender: TObject);
    var bmp : TBitmap;
    begin
      bmp := TBitmap.Create;
      bmp.LoadFromFile('D:\Images\Niagra.bmp');
      Surf := TDirectDrawSurface.Create(Display.DDraw);
      Surf.LoadFromGraphic(bmp);
      Surf.Restore;
      bmp.Destroy;
    end;
    And in the timer event where all the drawing is being done it draws as expected. Next is some test code I run to see if I can replace the original image.

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var bmp : TBitmap;
    begin
      bmp := TBitmap.Create;
        bmp.LoadFromFile('D:\Images\Pillar.bmp');
        Surf.LoadFromGraphic(bmp);
        Surf.Restore;
        bmp.Destroy;
    end;
    But the image displayed does not change. I have also tried

    Code:
    procedure TForm1.Button2Click(Sender: TObject);
    var bmp : TBitmap;
    begin
      bmp := TBitmap.Create;
      bmp.LoadFromFile('D:\Images\Pillar.bmp');
      Surf.Canvas.Draw(0,0,bmp);
      Surf.Canvas.Release;
      Surf.Restore;
      bmp.Destroy;
    end;
    What is the correct way to update the image on the surface?

  2. #2
    Here is a link to another site where I asked this question in a more simplified example of the issue

    http://stackoverflow.com/questions/5...ectdrawsurface

  3. #3
    I don't see real error in the way you do it, but its long time since i've used DelphiX (i bet that's the case for most here).

    Which version of DelphiX or UnDelphiX are you using? It bacame a little different after the hardware acceleration change in UnDelphiX and some things didn't work same way as before. Old one was direct, new one needs to update the texture in video memory. (If Restore doesn't do it, its propably bugged. But i don't really know.)

    Also, you are using event onDisplayInitialize(), was there something like onInitializeSurface()?
    Last edited by User137; 23-02-2011 at 04:40 PM.

  4. #4
    The version I am using is: Version 1.09.x

    Good memory, there is an onInitializeSurface() however in creating the simplest project to test this I have moved the initialize code out into a function called by a button click. (Seen in the link above in my last reply)

    It bacame a little different after the hardware acceleration change in UnDelphiX
    By this you mean that the DelphiX that originally came out by Hori before Jaro Benes took over? Or was there a change between two of his versions?

    And thank you very much for replying and helping me.

  5. #5
    Hori's DelphiX was not hardware accelerated and therefore 10 times slower. UnDelphiX is different.

    I originally tried to load each bitmap into the same slot in a DXImageList but that lead to many memory leaks and errors.
    DXImageList should work aswell. You must have some error in the code or that is another bug..?

    edit: Oh, you can try freeing the Surface before drawing the picture in. It's a little weird solution though. Also what you are doing is using TBitmap whereas all graphics with DelphiX should properly be TDirectDrawSurfaces mainly from DXImageList. You can draw a list item on a surface without canvas.
    Last edited by User137; 23-02-2011 at 07:13 PM.

  6. #6
    what you are doing is using TBitmap whereas all graphics with DelphiX should properly be TDirectDrawSurfaces mainly from DXImageList. You can draw a list item on a surface without canvas.
    Yes, but the way I receive the frames of the video is as a bitmap, the component I am using for this outputs in no other format. I then have to put that bitmap into a TDirectDrawSurface. I left the DXImageList since I really should only need 1 buffer, which I have chosen a TDirectDrawSurface for.

    The link I posted above in a previous post a very simple example with all the code layed out that demonstrate the issue.

    Thank you again.

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
  •