Skip to content

Instantly share code, notes, and snippets.

@sysrpl
Created July 4, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sysrpl/8af6e5a9d62cc2f2a1c40f9a9ae13b64 to your computer and use it in GitHub Desktop.
Save sysrpl/8af6e5a9d62cc2f2a1c40f9a9ae13b64 to your computer and use it in GitHub Desktop.
// InternalWrite optionally writes the line 2 times, optionally with a shadow, then in color
procedure TFontWriter.InternalWrite(const Line: string; Scale, Col, Row: Float);
procedure Draw(const Lead, Base: TColorF; OX, OY: Float);
var
O, K, CX, CY: Float;
I: Integer;
begin
O := Opacity;
K := (FStore.Kerning * Scale) / 2;
OX := OX * Scale + Origin.X;
OY := OY * Scale + Origin.Y;
// FStore has a map of the height and width of each glyph
CX := Col * FStore.Map[$20].Width * Scale + OX;
CY := Row * FStore.Map[$20].Height * Scale + OY;
// Here is the for loop that itterates over each char in the line
for I := 1 to Length(Line) do
begin
if (Line[I] < '!') or (Line[I] > '}') then
begin
CX := CX + FStore.Map[$20].Width * Scale;
Continue;
end;
with FStore.Map[Ord(Line[I])] do
begin
// World commands populate a vertex buffer with sufficient room
World
.Vert(CX + Width * Scale + K, CY)
.Color(Lead.Red, Lead.Green, Lead.Blue, Lead.Alpha * O)
.TexCoord(B.X, A.Y)
.Vert(CX - K, CY)
.TexCoord(A.X, A.Y)
.Vert(CX - K, CY + Height * Scale)
.Color(Base.Red, Base.Green, Base.Blue, Base.Alpha * O)
.TexCoord(A.X, B.Y)
.Vert(CX + Width * Scale + K, CY + Height * Scale)
.TexCoord(B.X, B.Y);
CX := CX + Width * Scale;
end;
end;
end;
begin
if (Scale = 0) or (Line = '') then Exit;
if FShadows then
Draw(ShadowColor, ShadowColor, ShadowOffset.X, ShadowOffset.Y);
Draw(LeadColor, BaseColor, 0, 0);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment