Forum > Graphics

Demo Scene Text Fx

(1/4) > >>

Gigatron:
Hi,

Yesterdat i've played with .ttf font with lazarus fpc and bgra component to make a nice intro under 100 lines of code.

the font is from Digital demo group on Amiga converted to ttf by me included in attachement;

the code source :


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,  BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes;  type   { TForm1 }   TForm1 = class(TForm)    BGRAVirtualScreen1: TBGRAVirtualScreen;    Timer1: TTimer;    procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);    procedure FormCreate(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    public   end; var  Form1: TForm1;  ta,xapp,yapp : double;  x,y,i,j  : integer;   tx: Array[0..9]  Of String; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin     ta :=0;     xapp :=0;     yapp :=0;     x:=0;     y:=60;     i :=0;     j :=0;      tx[0] := '***************************';     tx[1] := '*       GIGATRON          *';     tx[2] := '*                         *';     tx[3] := '*    PRESENTS TEXT FX#1   *';     tx[4] := '*                         *';     tx[5] := '*      BGRA COMPONENT     *';     tx[6] := '*-------------------------*';     tx[7] := '*   LAZARUS FPC RULEZ  !!!*';     tx[8] := '*-------------------------*';     tx[9] := '***************************'; end;  procedure TForm1.Timer1Timer(Sender: TObject);begin    BGRAVirtualScreen1.RedrawBitmap;end; procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap); begin   bitmap.FontName:='AmigaDigital8';  bitmap.FontHeight := 40;  bitmap.FontAntialias := false;      for i:=0 to 27 do    begin    for j:=0 to 9 do     begin      ta := ta +0.002;         xapp := (x + 2)  + 8   * sin(ta-j*0.05);        yApp := (y+i*15) + 4  * sin(tA-j*0.4-i) * 2;       bitmap.TextOut(i*24+xapp-10, (j*32 + yapp-i*15)+6  , tx[j][i],BGRA(0,0,0));      bitmap.TextOut(i*24+xapp-10,  j*32 + yapp-i*15   ,   tx[j][i],BGRA(255,255,255));     end;    end;   end;  end.  
This fx is slow for me ..

lainz:
I like how you create effects with few lines of code.

Gigatron:
But, it's thanks to you lainz and the best component BGRA ;

So the same fx but with usin open GL, it's smooth and faster than light ;)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,  BGLVirtualScreen, BGRAOpenGL, BGRABitmap, BGRABitmapTypes; type   { TForm1 }   TForm1 = class(TForm)    BGLVirtualScreen1: TBGLVirtualScreen;    Timer1: TTimer;    procedure BGLVirtualScreen1Redraw(Sender: TObject; BGLContext: TBGLContext);    procedure FormCreate(Sender: TObject);    procedure FormShow(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private        GLFont: IBGLFont;  public   end; var  Form1: TForm1;  ta,xapp,yapp : double;  x,y,i,j  : integer;  tx: Array[0..9]  Of String; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin     ta :=0; xapp :=0; yapp :=0; x:=0; y:=60; i :=0; j :=0;      tx[0] := '***************************';     tx[1] := '*       GIGATRON          *';     tx[2] := '*                         *';     tx[3] := '*    PRESENTS TEXT FX#1   *';     tx[4] := '*                         *';     tx[5] := '*     BGRA COMPONENT GL   *';     tx[6] := '*-------------------------*';     tx[7] := '*   LAZARUS FPC RULEZ  !!!*';     tx[8] := '*-------------------------*';     tx[9] := '***************************';end; procedure TForm1.FormShow(Sender: TObject);begin     GLFont := BGLFont('AmigaDigital8',40);end; procedure TForm1.BGLVirtualScreen1Redraw(Sender: TObject;BGLContext: TBGLContext);begin    for i:=0 to 27 do    begin    for j:=0 to 9 do     begin      ta := ta +0.0004;         xapp := (x + 2)  + 10   * sin(ta-j*0.005);        yApp := (y+i*15) + 6    * sin(tA-j*0.004-i)*2 ;       GLFont.TextOut(i*24+xapp, (j*32 + yapp-i*15)+6  , tx[j][i],BGRA(68,85,102));      GLFont.TextOut(i*24+xapp,  j*32 + yapp-i*15   ,   tx[j][i],BGRA(255,255,255));     end;    end; end; procedure TForm1.Timer1Timer(Sender: TObject);begin         BGLVirtualScreen1.Repaint;end; end. 

KodeZwerg:
Minimal modified so it actually use on windows the font that you shared :D
(also renamed variables to better qualifier names)
(modified for a smoother wave look)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Windows,  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,  BGLVirtualScreen, BGRAOpenGL, BGRABitmap, BGRABitmapTypes; type   { TForm1 }   TForm1 = class(TForm)    BGLVirtualScreen1: TBGLVirtualScreen;    Timer1: TTimer;    procedure BGLVirtualScreen1Redraw(Sender: TObject; BGLContext: TBGLContext);    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);    procedure FormShow(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    angle,    xPos, yPos : double;    xStart,    yStart: Integer;    Message: array[0..9] of AnsiString;  private     GLFont: IBGLFont;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Timer1Timer(Sender: TObject);begin  BGLVirtualScreen1.Repaint;end; procedure TForm1.FormCreate(Sender: TObject);begin  angle   := 0;  xPos    := 0;  yPos    := 0;  xStart  := 0;  yStart  := 60;   Message[0] := '***************************';  Message[1] := '*       GIGATRON          *';  Message[2] := '*                         *';  Message[3] := '*    PRESENTS TEXT FX#1   *';  Message[4] := '*                         *';  Message[5] := '*     BGRA COMPONENT GL   *';  Message[6] := '*-------------------------*';  Message[7] := '*   LAZARUS FPC RULEZ  !!!*';  Message[8] := '*-------------------------*';  Message[9] := '***************************';   // preset a minimal wanted window size  Self.Width := 710;  Self.Height := 460;   // adopted your color from screenshot :D  BGLVirtualScreen1.Color := $00776655;   // adjust timer to your needs  Timer1.Interval := 1;   // load the font on the fly and make it systemwide public  AddFontResource('AmigaDigital8.ttf');  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);end; procedure TForm1.FormDestroy(Sender: TObject);begin  // unload the font and make it systemwide public  RemoveFontResource('AmigaDigital8.ttf');  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);end; procedure TForm1.BGLVirtualScreen1Redraw(Sender: TObject;  BGLContext: TBGLContext);var  i, j: Integer;begin  for i := 0 to 27 do    for j := 0 to 9 do      begin        // movement modifier        angle := angle + 0.0004;        // left to right movement        xPos := (xStart + 2) + 10 * Sin(angle - j * 0.005);        // up and down movement        yPos := (yStart + i * 15) + 6 * Cos(angle - j * 0.004 - i) * 2;        // fake shadow character        GLFont.TextOut(i * 24 + xPos, (j * 32 + yPos - i * 15) + 6, Message[j][i], BGRA(68, 85, 102));        // actual text character        GLFont.TextOut(i * 24 + xPos, j * 32 + yPos - i * 15, Message[j][i], BGRA(255, 255, 255));      end;end; procedure TForm1.FormShow(Sender: TObject);begin  GLFont := BGLFont('AmigaDigital8', 40);end; end.Thank you Gigatron for that nice example!

Attached is how it looks without font installed, I am unsure what is used but its not the AmigaDigital8  ;D

TRon:

--- Quote from: Gigatron on May 06, 2024, 08:36:12 am ---This fx is slow for me ..

--- End quote ---
Yeah, that is way of things. Learn to know the tools and their trade-offs.

So,
- the font can be set to the virtual screen once. However slightly, it helps.
- at a certain point clearing the screen (big surface) at once is cheaper than (re)drawing smaller bits
- in accordance with the above, skip drawing when there is actually nothing to draw (spaces)
- also however slightly it helps, pre-calculation of sin/coords (that has a certain drawback ofc.)
- note that using a timer to actually time frames is .. not smart ... to say the least. It fires every x-th millisecond an is literally wasting all time in between (I know it a timer is a simple pleasure usage and use it myself as well).
- the bigger slowness seem to originate form redrawing of the same thing over and over (opengl caches some important parts hence the speed increase), so pre-draw the glyphs and blit a single glyph at once.

There are many more things that are able to influence speed (or the perception thereof).

The funny part of this is... we are talking about hardware that is around 3-4 decades old (the generation before Amiga was also capable of these same fx) and is able to display such a wavy text without breaking a sweat with enough time to spare to do some actual important stuff. It is a living testimony that relying on cpu grunt alone is not the smartest way to approach these kind of things.

Navigation

[0] Message Index

[#] Next page

Go to full version