Page 4 of 4 FirstFirst ... 234
Results 31 to 39 of 39

Thread: Slow when drawing the Map into another surface

  1. #31

    Slow when drawing the Map into another surface

    OK I will see it.
    Ijcro.

  2. #32

    Slow when drawing the Map into another surface

    Quote Originally Posted by ijcro
    OK I will see it.
    If you'd like I have written a simple example problem reproduction:

    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DXClass, DXDraws, StdCtrls;
    
    type
      TForm1 = class(TForm)
        dd1: TDXDraw;
        DXTimer1: TDXTimer;
        rb1: TRadioButton;
        RadioButton1: TRadioButton;
        procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
        procedure dd1Initialize(Sender: TObject);
        procedure PrepareNewSurface;
      private
         newsurface: TDirectDrawSurface;
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    var
       nWidth: Integer = 0;
       bGoing: Boolean = true;
    
    procedure TForm1.PrepareNewSurface;
    begin
       newsurface.Fill( 0 );
       newsurface.Canvas.Rectangle( 10, 10, 10 + nWidth, 50 );
    
       if bGoing then
       begin
          Inc( nWidth, 3 );
    
          if nWidth = newsurface.Width - 10 then
             bGoing := not bGoing;
       end
       else
       begin
          Dec( nWidth, 3 );
    
          if nWidth <= 10 then
             bGoing &#58;= not bGoing;
       end;
    
       newsurface.Canvas.Release;
    end;
    
    procedure TForm1.DXTimer1Timer&#40;Sender&#58; TObject; LagCount&#58; Integer&#41;;
    begin
       dd1.surface.fill&#40; 0 &#41;;
       PrepareNewSurface;
    
       if radiobutton1.Checked then
          dd1.Surface.Draw&#40; 0, 0, newsurface &#41;
       else
          dd1.Surface.BltFast&#40; 0, 0, dd1.surface.ClientRect, 0, newsurface &#41;;
    
       dd1.surface.canvas.release;
       dd1.Flip;
    end;
    
    procedure TForm1.dd1Initialize&#40;Sender&#58; TObject&#41;;
    begin
       newsurface &#58;=TDirectDrawSurface.Create&#40; dd1.DDraw &#41;;
       newsurface.SetSize&#40; dd1.Width, dd1.height &#41;;
    end;

    If I use Non-hardware acceleration (removing the [do3D] from options), it works but with software.

    Thanx!

  3. #33

    Slow when drawing the Map into another surface

    Hello!

    I tried your example!

    And there is my solution (you have to use version undelphi 1.07b):

    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      Dialogs, DXClass, DXDraws, StdCtrls;
    
    type
      TForm1 = class&#40;TForm&#41;
        dd1&#58; TDXDraw;
        DXTimer1&#58; TDXTimer;
        doBltFast&#58; TRadioButton;
        doDraw&#58; TRadioButton;
        procedure DXTimer1Timer&#40;Sender&#58; TObject; LagCount&#58; Integer&#41;;
        procedure dd1Initialize&#40;Sender&#58; TObject&#41;;
        procedure PrepareNewSurface;
      private
         newsurface&#58; TDirectDrawSurface;
        &#123; Private declarations &#125;
      public
        &#123; Public declarations &#125;
      end;
    
    var
      Form1&#58; TForm1;
    
    implementation
    
    &#123;$R *.dfm&#125;
    
    var 
       nWidth&#58; Integer = 0; 
       bGoing&#58; Boolean = true; 
    
    procedure TForm1.PrepareNewSurface;
    begin 
       newsurface.Fill&#40; 0 &#41;; 
       newsurface.Canvas.Rectangle&#40; 10, 10, 10 + nWidth, 50 &#41;; 
    
       if bGoing then
       begin 
          Inc&#40; nWidth, 3 &#41;; 
    
          if nWidth = newsurface.Width - 10 then 
             bGoing &#58;= not bGoing; 
       end
       else 
       begin 
          Dec&#40; nWidth, 3 &#41;; 
    
          if nWidth <= 10 then 
             bGoing &#58;= not bGoing;
       end; 
    
       newsurface.Canvas.Release; 
    end; 
    
    procedure TForm1.DXTimer1Timer&#40;Sender&#58; TObject; LagCount&#58; Integer&#41;;
    begin 
       dd1.surface.fill&#40; 0 &#41;;
       PrepareNewSurface; 
       dd1.ClearStack;
       if doDraw.Checked then
          dd1.Surface.Draw&#40; 0, 0, newsurface &#41;
       else
          dd1.Surface.BltFast&#40; 0, 0, dd1.surface.ClientRect, 0, newsurface &#41;;
    
       dd1.surface.canvas.release; 
       dd1.Flip; 
    end;
    
    procedure TForm1.dd1Initialize&#40;Sender&#58; TObject&#41;; 
    begin 
       newsurface &#58;=TDirectDrawSurface.Create&#40; dd1.DDraw &#41;; 
       newsurface.SetSize&#40; dd1.Width, dd1.height &#41;; 
    end;
    
    end.
    Shortly, use simple
    Code:
    dd1.ClearStack;
    for clear texture stack.

    Regards
    Ijcro.

  4. #34

    Slow when drawing the Map into another surface

    First of all, thank you for the solution!
    This works for Draw, but for DrawAlpha it does not work :cry:

  5. #35

    Slow when drawing the Map into another surface

    Please, send me your demo (code) with DrawAlpha or DrawAdd, I see it!
    Thanks
    Ijcro.

  6. #36

    Slow when drawing the Map into another surface

    Quote Originally Posted by ijcro
    Please, send me your demo (code) with DrawAlpha or DrawAdd, I see it!
    Thanks
    Just change the dd1.surface.Draw to dd1.Surface.DrawAlpha, in the same example, with an alpha of 100 for example.

    Thanx

  7. #37

    Slow when drawing the Map into another surface

    OK.
    Ijcro.

  8. #38

    Slow when drawing the Map into another surface

    You can try this construction, but small problem with alpha is here still... :cry: sorry

    Code:
    procedure TForm1.DXTimer1Timer&#40;Sender&#58; TObject; LagCount&#58; Integer&#41;;
    begin
      dd1.surface.fill&#40;dd1.Surface.ColorMatch&#40;clBlack&#41;&#41;;
      dl1.Items.Find&#40;'krecci'&#41;.StretchDraw&#40;dd1.Surface, dd1.Surface.ClientRect, 0&#41;;
      PrepareNewSurface;
      dd1.ClearStack;
      if doDraw.Checked then
        //dd1.Surface.Draw&#40; 0, 0, newsurface &#41;
        dd1.Surface.Draw&#40;0, 0, newsurface.ClientRect, newsurface&#41;
      else if doBlend.Checked then begin
        if dd1.Surface.Lock then begin
          dd1.Surface.DrawAlpha&#40;dd1.Surface.ClientRect, newSurface.ClientRect, newsurface, True, 128&#41;;
          dd1.Surface.UnLock;
        end;
      end
      else
        dd1.Surface.BltFast&#40;0, 0, dd1.surface.ClientRect, 0, newsurface&#41;;
    
      //dd1.surface.canvas.release;
      dd1.Flip;
    end;
    Ijcro.

  9. #39

    Slow when drawing the Map into another surface

    I made little the analyse of problem.

    Problem has two parts.
    At first it is refresh of image surface.
    It is not bug in unDelphiX. The concept no compute with change the picture in DDS, but prefer direct drawing. ClearStack dramatically suspend speed of drawing, I no advice it (so only for special purpose).

    And second it is drawing...using DrawAlpha, DrawAdd and etc.
    I think that it can be bug. I did track all the calls low level routines to DirectX and all returned with DD_OK flag (I am using last published version 1.07b). But pictures no show! This can be the same bug that picture is drawing on empty Surface. But I don't know best solution.

    You can use ...

    1/ technique of videotexture like Hori's sample

    2/ predefined picture and draw it throught DXImageList (from one picture)

    3/ directly drawing via DXDraw.Surface[.Canvas]

    4/ own another technique for me unknown

    Many clever and handy programmers are here.
    Can anybody help us with this problem? For better unDelphiX? Thanks!
    Ijcro.

Page 4 of 4 FirstFirst ... 234

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
  •