Recent

Author Topic: Fast Canvas Library V1.0  (Read 1939 times)

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Fast Canvas Library V1.0
« on: June 09, 2025, 06:01:00 pm »
Ok

Here is the first release of my gfx Library V1.0 Include just base primitives to
draw lines, rectangles , triangles , star, pixel(plot) etc.
Will include the others functions in future release (copperbar, 2d,3d, Starfield, Image, plasma etc...) Step by Step !

This library is for my personal usage to make Demo faster Like on Amiga. It Use Winapi
and working on my X64 windows. The performance is really faster.

To start the show; Just start a new normal project and include a Timer... look the example code: Maybe i made mistakes and forgot some improvements !

Project is included.

Have Fun

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,
  9.   Windows, ExtCtrls;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Timer1: TTimer;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure Timer1Timer(Sender: TObject);
  18.   private
  19.     FNativeFastCanvas: TNativeFastCanvas;
  20.     FAnimTimer: Integer;
  21.   public
  22.     procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer); // Main Loop Draw
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. begin
  36.   // Création du composant TNativeFastCanvas
  37.   FNativeFastCanvas := TNativeFastCanvas.Create(Self);
  38.  
  39.   with FNativeFastCanvas do
  40.   begin
  41.     Parent := Self;
  42.     Align := alClient;         // Full Screen
  43.    // SetBounds(50,5,800,600); // or déclare screen size
  44.     BackgroundColor := RGB(0, 0, 32);  // Bleu foncé style Amiga
  45.     OnNativePaint := @NativeFastCanvas1NativePaint;
  46.   end;
  47.  
  48.   FAnimTimer := 0;
  49. end;
  50.  
  51. procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;
  52.   Pixels: PFastPixel; Ww, Hh: Integer);
  53. var
  54.   FastCanvas: TNativeFastCanvas;
  55.   i, x, y: Integer;
  56.   CenterX, CenterY: Integer;
  57.   Radius: Integer;
  58.   Col: TColor;
  59. begin
  60.   FastCanvas := TNativeFastCanvas(Sender);
  61.   CenterX := Ww div 2;
  62.   CenterY := Hh div 2;
  63.  
  64. // **** DÉMONSTRATION DES PRIMITIVES Dessin de BASE + Etoiles Triangle Etc .. ***
  65.  
  66. // Stars
  67.   FastCanvas.Star(CenterX, CenterY, 30, 12, 5,  FAnimTimer * 0.02, RGB(255, 255, 0));
  68.   FastCanvas.Star(CenterX, CenterY, 60, 25, 5,  FAnimTimer * 0.03, RGB(255, 255, 0));
  69.   FastCanvas.Star(CenterX, CenterY, 100, 40, 5, FAnimTimer * 0.04, RGB(255, 255, 0));
  70.   FastCanvas.Star(CenterX, CenterY, 150, 60, 5, FAnimTimer * 0.01, RGB(255, 255, 0));
  71.  
  72. //  Pixels Random !
  73.  for i := 0 to 199 do // or 19999+1 pixels
  74.  begin
  75.    x := Random(Ww);
  76.    y := Random(Hh);
  77.   // FastCanvas.SetPixel(x, y, RGB(255, 255, 255));
  78.  end;
  79.  
  80.  // H Lines Copper bars style Amiga
  81.  for i := 0 to 15 do  //16 lines
  82.  begin
  83.    y := 50 + i * 4; // saut 4 pixel Y
  84.    Col := RGB(255 - i * 15, i * 16, 128 + i * 8);
  85.    FastCanvas.HorizontalLine(20, Ww - 20, y, Col);
  86.  end;
  87.  
  88.  // Vertical Lines
  89.  for i := 0 to 20 do
  90.  begin
  91.    x := 100 + i * 20;
  92.    FastCanvas.VerticalLine(x, 200, 280, RGB(0, 255, 100));
  93.  end;
  94.  
  95.  // Diagonal Lines
  96.  for i := 0 to 11 do
  97.  begin
  98.    x := CenterX + Round(100 * Cos((i * 30 + FAnimTimer * 2) * Pi / 180));
  99.    y := CenterY + Round(100 * Sin((i * 30 + FAnimTimer * 2) * Pi / 180));
  100.    Col := RGB(255, 128 + i * 10, 0);
  101.    FastCanvas.Line(CenterX, CenterY, x, y, Col);
  102.  end;
  103.  
  104.  //  Rectangle The Big
  105.  FastCanvas.Rectangle(10, 10, Ww - 10, Hh - 10,     RGB(255, 255, 255));
  106.  FastCanvas.Rectangle(10+1, 10+1, Ww - 9, Hh - 9, RGB(200, 200, 200));
  107.  
  108.  // Rectangles Filled
  109.  for i := 0 to 15 do
  110.  begin
  111.    x := 50 + i * 50;
  112.    Col := RGB(i * 32, 255 - i * 32, 128);
  113.    FastCanvas.FillRect(x, Hh - 80, x + 40, Hh - 30, Col);
  114.  end;
  115.  
  116.  // Circle
  117.  Radius := 80 + Round(20 * Sin(FAnimTimer * 0.1));
  118.  FastCanvas.Circle(CenterX - 150, CenterY, Radius, RGB(255, 0, 255));
  119.  
  120.  // Circle Filled
  121.  Radius := 60 + Round(10 * Sin(FAnimTimer * 0.15));
  122.  Col := RGB(255, 255 - Round(50 * Sin(FAnimTimer * 0.1)), 0);
  123.  FastCanvas.FillCircle(CenterX + 150, CenterY, Radius, Col);
  124.  
  125.  // Ellipse
  126.  FastCanvas.Ellipse(CenterX, CenterY, 200, 120, RGB(0, 255, 255));
  127.  
  128.  // Ellipse Filled
  129.  x := CenterX + Round(180 * Cos(FAnimTimer * 0.05));
  130.  y := CenterY + Round(100 * Sin(FAnimTimer * 0.05));
  131.  FastCanvas.FillEllipse(x, y, 25, 15, RGB(0, 200, 100));
  132.  
  133.  // Get Pixel then if not back color SetPixel mirror FX
  134.  Col := FastCanvas.GetPixel(CenterX, CenterY);
  135.  if Col <> RGB(0, 0, 32) then
  136.  begin
  137.    FastCanvas.SetPixel(CenterX + 10, CenterY + 10, Col);
  138.    FastCanvas.SetPixel(CenterX - 10, CenterY - 10, Col);
  139.  end;
  140.  
  141.  // Simple Plasma Fx   100*100
  142.  for y := 320 to 420 do
  143.    for x := 20 to 120 do
  144.    begin
  145.      i := Round(128 + 127 * Sin((x + FAnimTimer) * 0.1) * Cos((y + FAnimTimer) * 0.08));
  146.      Col := RGB(i, 255 - i, 128);
  147.      FastCanvas.SetPixel(x, y, Col);
  148.    end;
  149.  
  150. // Triangle animation
  151.   FastCanvas.Triangle(350, 450, 300, 350, 150, 450, RGB(255, 0, 0));
  152.  
  153. // Triangle animation
  154.   x := CenterX + Round(80 * Cos(FAnimTimer * 0.1));
  155.   y := CenterY + Round(80 * Sin(FAnimTimer * 0.1));
  156.   FastCanvas.Triangle(CenterX, CenterY - 60, x, y, CenterX - 40, CenterY + 40, RGB(0, 255, 0));
  157.  
  158. // Triangles  effet kaleidoscope fx
  159.   for i := 0 to 5 do
  160.     begin
  161.      x := CenterX + Round(100 * Cos(i * 60 * Pi / 180 + FAnimTimer * 0.05));
  162.      y := CenterY + Round(100 * Sin(i * 60 * Pi / 180 + FAnimTimer * 0.05));
  163.      Col := RGB(255, i * 40, 255 - i * 40);
  164.      FastCanvas.Triangle(CenterX, CenterY, x, y,
  165.        CenterX + Round(50 * Cos((i * 60 + 30) * Pi / 180 + FAnimTimer * 0.05)),
  166.        CenterY + Round(50 * Sin((i * 60 + 30) * Pi / 180 + FAnimTimer * 0.05)), Col);
  167.     end;
  168.  
  169. end;
  170.  
  171. procedure TForm1.Timer1Timer(Sender: TObject);
  172. begin
  173.   Inc(FAnimTimer);
  174.   FNativeFastCanvas.Invalidate;
  175. end;
  176.  
  177. //  EXIT Destroy canvas !
  178. procedure TForm1.FormDestroy(Sender: TObject);
  179. begin
  180.   if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
  181. end;
  182.  
  183. end.

Sub Quantum Technology ! Gigatron 68000 Colmar France;

domasz

  • Hero Member
  • *****
  • Posts: 582
Re: Fast Canvas Library V1.0
« Reply #1 on: June 09, 2025, 06:02:54 pm »
Splendid!

440bx

  • Hero Member
  • *****
  • Posts: 5456
Re: Fast Canvas Library V1.0
« Reply #2 on: June 09, 2025, 07:41:09 pm »
Hello Gigatron,

I thought I'd have a look at your project.  When I tried to load it I got an error message about a missing package.  I looked in the OPM list and didn't see it there.

The troublesome package is XMPlayer.  see attachment.

My question is, how do I get that package installed so I can run your program ?
« Last Edit: June 09, 2025, 07:43:53 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #3 on: June 09, 2025, 09:41:11 pm »
Sorry,

I forgot to remove the XMPlayer package; It is not yet in use, you can skip this component.

Or install it for the future usage here ;

https://forum.lazarus.freepascal.org/index.php/topic,71172.0.html
Sub Quantum Technology ! Gigatron 68000 Colmar France;

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #4 on: June 10, 2025, 12:15:06 am »
Tired today with these vectors !!

The next version of this library will contain filled triangle and vector text or Chars, as shown in this example image.

Sub Quantum Technology ! Gigatron 68000 Colmar France;

Thaddy

  • Hero Member
  • *****
  • Posts: 17148
  • Ceterum censeo Trump esse delendam
Re: Fast Canvas Library V1.0
« Reply #5 on: June 10, 2025, 07:24:09 am »
How does it compare to OpenGLCanvas?
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #6 on: June 10, 2025, 08:05:38 pm »
How does it compare to OpenGLCanvas?

OpenglCanvas is really faster than this library which is a little slower i think,
but still fast according to the tests I performed.

Let's upgrade this library to V1.01.
Added filled triangles and vectorchar, vectorText, vector3drotate text etc...

Future usage for loading and display png image , hope i'ts working for you.
Code: Pascal  [Select][+][-]
  1. uses
  2.   Classes, SysUtils, Controls, Graphics, ExtCtrls, Windows, Types,
  3.   FPWritePNG, FPReadPNG, FPImage, IntfGraphics, GraphType;  

List of Fuctions here :

Code: Pascal  [Select][+][-]
  1.     procedure HorizontalLine(x1, x2, y: Integer; Col: TColor);
  2.     procedure VerticalLine(x, y1, y2: Integer; Col: TColor);
  3.     procedure Line(x1, y1, x2, y2: Integer; Col: TColor);
  4.     procedure Rectangle(x1, y1, x2, y2: Integer; Col: TColor);
  5.     procedure FillRect(x1, y1, x2, y2: Integer; Col: TColor);
  6.     procedure Circle(CenterX, CenterY, Radius: Integer; Col: TColor);
  7.     procedure FillCircle(CenterX, CenterY, Radius: Integer; Col: TColor);
  8.     procedure Ellipse(CenterX, CenterY, RadiusX, RadiusY: Integer; Col: TColor);
  9.     procedure FillEllipse(CenterX, CenterY, RadiusX, RadiusY: Integer; Col: TColor);
  10.     procedure Triangle(x1, y1, x2, y2, x3, y3: Integer; Col: TColor);
  11.     procedure FillTriangle(x1, y1, x2, y2, x3, y3: Integer; Col: TColor);
  12.     procedure Star(CenterX, CenterY, OuterRadius, InnerRadius: Integer; Points: Integer; RotationAngle: Double; Col: TColor);
  13.     /// ****** END OF COMMON BASIC GFX PRIMITIVES ******************************
  14.  
  15.     /// VectorChar Text Draw   ****************************
  16.     procedure DrawVectorChar(x, y: Integer; Ch: Char; Size: Integer; Col: TColor);
  17.     procedure DrawVectorText(x, y: Integer; const Txt: string; Size: Integer; Col: TColor);
  18.     procedure DrawVectorChar3D(x, y: Integer; Ch: Char; Size: Integer; RotX, RotY, RotZ: Single; Col: TColor);
  19.     procedure DrawVectorText3D(x, y: Integer; const Txt: string; Size: Integer; RotX, RotY, RotZ: Single; Col: TColor);
  20.     procedure RotateVectorText3D(GlobalX, GlobalY: Integer; Txt: string; Size: Integer; RotX, RotY, RotZ: Double; Col: TColor);
  21.  

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,
  9.   Windows, ExtCtrls;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Timer1: TTimer;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure Timer1Timer(Sender: TObject);
  18.   private
  19.     FNativeFastCanvas: TNativeFastCanvas;
  20.     FAnimTimer: Integer;
  21.   public
  22.     procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer); // Main Loop Draw
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   RotX, RotY : Single;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. begin
  37.   // Création du composant TNativeFastCanvas
  38.   FNativeFastCanvas := TNativeFastCanvas.Create(Self);
  39.  
  40.   with FNativeFastCanvas do
  41.   begin
  42.     Parent := Self;
  43.    // Align := alClient;         // Full Screen
  44.     SetBounds(30,5,960,620); // or déclare screen size
  45.     BackgroundColor := RGB(0, 0, 32);  // Bleu foncé style Amiga
  46.     OnNativePaint := @NativeFastCanvas1NativePaint;
  47.   end;
  48.  
  49.   FAnimTimer := 0;
  50.   RotX := 0;
  51.   RotY := 0;
  52.  
  53. end;
  54.  
  55. procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;
  56.   Pixels: PFastPixel; Ww, Hh: Integer);
  57. var
  58.   FastCanvas: TNativeFastCanvas;
  59.   i, x, y,x1,y1: Integer;
  60.   CenterX, CenterY: Integer;
  61.   Radius: Integer;
  62.   Col: TColor;
  63. begin
  64.   FastCanvas := TNativeFastCanvas(Sender);
  65.   CenterX := Ww div 2;
  66.   CenterY := Hh div 2;
  67.  
  68.   // Triangles  effet kaleidoscope fx
  69.   for i := 0 to 5 do
  70.     begin
  71.      x := CenterX + Round(100 * Cos(i * 60 * Pi / 180 - FAnimTimer * 0.01));
  72.      y := CenterY + Round(100 * Sin(i * 60 * Pi / 180 - FAnimTimer * 0.01));
  73.      Col := RGB(i*50, i * 40, 255 - i * 40);
  74.      FastCanvas.FillTriangle(CenterX, CenterY, x, y,
  75.        CenterX + Round(150 * Cos((i * 60 + 30) * Pi / 180 - FAnimTimer * 0.02)),
  76.        CenterY + Round(150 * Sin((i * 60 + 30) * Pi / 180 - FAnimTimer * 0.02)), Col);
  77.     end;
  78.  
  79.  
  80.  
  81.   rotY := FAnimTimer * 0.02;
  82.   rotX := FAnimTimer * 0.04;
  83.  
  84.   FastCanvas.RotateVectorText3D(450, 520,'LAZARUS 4.0',70,0,  Roty, 0, RGB(255, 255, 255));
  85.   FastCanvas.RotateVectorText3D(450, 100,'GIGATRON',70,RotX,  RotY,0, RGB(255, 255, 255));
  86.  
  87. end;
  88.  
  89. procedure TForm1.Timer1Timer(Sender: TObject);
  90. begin
  91.   Inc(FAnimTimer);
  92.   FNativeFastCanvas.Invalidate;
  93. end;
  94.  
  95. //  EXIT Destroy canvas !
  96. procedure TForm1.FormDestroy(Sender: TObject);
  97. begin
  98.  
  99.  // FNativeFastCanvas.FreeAllImages; // Libère toutes les images du cache
  100.  // inherited Destroy;
  101.   if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
  102.  
  103. end;
  104.  
  105. end.
« Last Edit: June 10, 2025, 08:18:17 pm by Gigatron »
Sub Quantum Technology ! Gigatron 68000 Colmar France;

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #7 on: June 11, 2025, 11:41:27 pm »
Hi

Status of this library 1.02;
Include ; Normal Textscrolling, VectorTextScrolling, BitmapFontScrolling, Star with Border,
Raster Bar , and Copper Bar V/H . Stay Tuned.. i will improve some functions.

This Screen Size is 960x620 and all running on 60 fps !! Cpu load 2.5 - 3.0 %
Some Gfx Operations is near opengl performance.

Regards

Gtr
Sub Quantum Technology ! Gigatron 68000 Colmar France;

440bx

  • Hero Member
  • *****
  • Posts: 5456
Re: Fast Canvas Library V1.0
« Reply #8 on: June 12, 2025, 12:03:32 am »
@Gigatron,

It looks great.

Any chance you could post an updated project, with source please, that doesn't require an additional package ?

Thank you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #9 on: June 12, 2025, 12:12:56 am »
@Gigatron,

It looks great.

Any chance you could post an updated project, with source please, that doesn't require an additional package ?

Thank you.

Sure , i must just add some other stuff  like png image load / display, wavy texture , 2D/3D starfield, will improve some functions to gain maximum performance. The next release end of this week.
 
Sub Quantum Technology ! Gigatron 68000 Colmar France;

440bx

  • Hero Member
  • *****
  • Posts: 5456
Re: Fast Canvas Library V1.0
« Reply #10 on: June 12, 2025, 12:23:09 am »
Sure , i must just add some other stuff  like png image load / display, wavy texture , 2D/3D starfield, will improve some functions to gain maximum performance. The next release end of this week.
That sounds good.  Thank you!.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #11 on: June 12, 2025, 06:44:27 pm »
Hi

I did some tests and added some nice effects on this library, for example 15 fx running at full speed with 500000 dots, 3Dstarfield (pre-computed sin table), CPU load 15%.

I'm going to clean up the code and add a plasma effect, so that's OK.

Regards
Sub Quantum Technology ! Gigatron 68000 Colmar France;

TBMan

  • Full Member
  • ***
  • Posts: 167
Re: Fast Canvas Library V1.0
« Reply #12 on: June 13, 2025, 02:38:56 pm »
Looks good!

Gigatron

  • Sr. Member
  • ****
  • Posts: 280
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #13 on: June 14, 2025, 01:33:39 am »
Looks good!

Thank you;

Normally this library will be ready for Sunday, these are the compilations of all the effects i made with lazarus pascal similar to the Amiga demos.

I can't include all the effects of the Amiga.
I think there are millions of effects ;)
Some operations are really fast like pixel ops and draw gfx primitives !
Hope I didn't make any mistakes! An example demo (YT) of the latest version, you can see the performance of the various effects

https://www.youtube.com/watch?v=9u5XQi5e23U

Regards Gtr
Sub Quantum Technology ! Gigatron 68000 Colmar France;

TBMan

  • Full Member
  • ***
  • Posts: 167
Re: Fast Canvas Library V1.0
« Reply #14 on: June 14, 2025, 03:26:59 am »
Looks good!

Thank you;

Normally this library will be ready for Sunday, these are the compilations of all the effects i made with lazarus pascal similar to the Amiga demos.

I can't include all the effects of the Amiga.
I think there are millions of effects ;)
Some operations are really fast like pixel ops and draw gfx primitives !
Hope I didn't make any mistakes! An example demo (YT) of the latest version, you can see the performance of the various effects

https://www.youtube.com/watch?v=9u5XQi5e23U

Regards Gtr

Very nice! Does it support page flipping?

 

TinyPortal © 2005-2018