You've already forked lazarus-ccr
implemented TGLUTBitmapFont
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2245 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -5,7 +5,7 @@ program widget_test;
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
GLut, GL, GLu,
|
GLut, GL, GLu,
|
||||||
nvWidgets, nvGLWidgets, nvBaseFont, nvGlutWidgets, GLFreeTypeFont;
|
nvWidgets, nvGLWidgets, nvBaseFont, nvGlutWidgets, GLFreeTypeFont, GLUTBitmapFont;
|
||||||
|
|
||||||
var
|
var
|
||||||
ui: GlutUIContext;
|
ui: GlutUIContext;
|
||||||
@ -197,6 +197,7 @@ begin
|
|||||||
ui := GlutUIContext.Create;
|
ui := GlutUIContext.Create;
|
||||||
ui.Painter := GLUIPainter.Create;
|
ui.Painter := GLUIPainter.Create;
|
||||||
ui.Painter.Font := TGLFreeTypeFont.Create('Ubuntu-R.ttf', 10);
|
ui.Painter.Font := TGLFreeTypeFont.Create('Ubuntu-R.ttf', 10);
|
||||||
|
//ui.Painter.Font := TGLUTBitmapFont.Create('fixed', 15);
|
||||||
|
|
||||||
if not ui.init(win_w, win_h) then
|
if not ui.init(win_w, win_h) then
|
||||||
begin
|
begin
|
||||||
|
@ -5,7 +5,7 @@ unit GLUTBitmapFont;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, GLut, nvBaseFont;
|
Classes, SysUtils, GL, GLut, nvBaseFont;
|
||||||
|
|
||||||
type
|
type
|
||||||
TFontStyles = record
|
TFontStyles = record
|
||||||
@ -15,16 +15,18 @@ type
|
|||||||
StrikeTrough: boolean;
|
StrikeTrough: boolean;
|
||||||
Underline: boolean;
|
Underline: boolean;
|
||||||
Font: pointer;
|
Font: pointer;
|
||||||
|
TextListBase: integer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TGLUTFreeTypeFont }
|
{ TGLUTBitmapFont }
|
||||||
|
|
||||||
TGLUTFreeTypeFont = class(TNVBaseFont)
|
TGLUTBitmapFont = class(TNVBaseFont)
|
||||||
private
|
private
|
||||||
FFontList: array of TFontStyles;
|
FFontList: array of TFontStyles;
|
||||||
FCount: integer;
|
FCount: integer;
|
||||||
FActiveFont: integer;
|
FActiveFont: integer;
|
||||||
procedure FindStylizedFont;
|
procedure FindStylizedFont;
|
||||||
|
function InitializeFont(AFont: pointer): integer;
|
||||||
protected
|
protected
|
||||||
procedure SetFlags(AIndex: integer; AValue: boolean); override;
|
procedure SetFlags(AIndex: integer; AValue: boolean); override;
|
||||||
public
|
public
|
||||||
@ -44,9 +46,9 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{ TGLUTFreeTypeFont }
|
{ TGLUTBitmapFont }
|
||||||
|
|
||||||
procedure TGLUTFreeTypeFont.FindStylizedFont;
|
procedure TGLUTBitmapFont.FindStylizedFont;
|
||||||
var
|
var
|
||||||
item: TFontStyles;
|
item: TFontStyles;
|
||||||
i: integer;
|
i: integer;
|
||||||
@ -71,14 +73,32 @@ begin
|
|||||||
FActiveFont := 0;
|
FActiveFont := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGLUTFreeTypeFont.SetFlags(AIndex: integer; AValue: boolean);
|
function TGLUTBitmapFont.InitializeFont(AFont: pointer): integer;
|
||||||
|
var
|
||||||
|
TextListBase: integer;
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
//just doing 7-bit ascii
|
||||||
|
TextListBase := glGenLists(128);
|
||||||
|
|
||||||
|
for i := 0 to 127 do
|
||||||
|
begin
|
||||||
|
glNewList(TextListBase + i, GL_COMPILE);
|
||||||
|
glutBitmapCharacter(AFont, i);
|
||||||
|
glEndList;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := TextListBase;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TGLUTBitmapFont.SetFlags(AIndex: integer; AValue: boolean);
|
||||||
begin
|
begin
|
||||||
inherited SetFlags(AIndex, AValue);
|
inherited SetFlags(AIndex, AValue);
|
||||||
|
|
||||||
FindStylizedFont;
|
FindStylizedFont;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TGLUTFreeTypeFont.Create(AName: string; ASize: integer);
|
constructor TGLUTBitmapFont.Create(AName: string; ASize: integer);
|
||||||
begin
|
begin
|
||||||
inherited Create(AName, ASize);
|
inherited Create(AName, ASize);
|
||||||
|
|
||||||
@ -87,7 +107,7 @@ begin
|
|||||||
FActiveFont := 0;
|
FActiveFont := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TGLUTFreeTypeFont.Destroy;
|
destructor TGLUTBitmapFont.Destroy;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
@ -97,38 +117,63 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGLUTFreeTypeFont.Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean);
|
procedure TGLUTBitmapFont.Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean);
|
||||||
begin
|
begin
|
||||||
Inc(FCount);
|
Inc(FCount);
|
||||||
SetLength(FFontList, FCount);
|
SetLength(FFontList, FCount);
|
||||||
|
|
||||||
with FFontList[FCount - 1] do
|
with FFontList[FCount - 1] do
|
||||||
begin
|
begin
|
||||||
//Font.Init(AName, Size);
|
case LowerCase(AName) of
|
||||||
|
'helvetica': case Size of
|
||||||
|
10: Font := GLUT_BITMAP_HELVETICA_10;
|
||||||
|
12: Font := GLUT_BITMAP_HELVETICA_12;
|
||||||
|
18: Font := GLUT_BITMAP_HELVETICA_18;
|
||||||
|
else
|
||||||
|
raise Exception.CreateFmt('GLUT font size %d does not exist for font %s', [Size, AName]);
|
||||||
|
end;
|
||||||
|
'times roman': case Size of
|
||||||
|
10: Font := GLUT_BITMAP_TIMES_ROMAN_10;
|
||||||
|
24: Font := GLUT_BITMAP_TIMES_ROMAN_24;
|
||||||
|
else
|
||||||
|
raise Exception.CreateFmt('GLUT font size %d does not exist for font %s', [Size, AName]);
|
||||||
|
end;
|
||||||
|
'fixed': case Size of
|
||||||
|
13: Font := GLUT_BITMAP_8_BY_13;
|
||||||
|
15: Font := GLUT_BITMAP_9_BY_15;
|
||||||
|
else
|
||||||
|
raise Exception.CreateFmt('GLUT font size %d does not exist for font %s', [Size, AName]);
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
raise Exception.CreateFmt('GLUT font name not supported %s', [AName]);
|
||||||
|
end;
|
||||||
|
|
||||||
Name := AName;
|
Name := AName;
|
||||||
Bold := ABold;
|
Bold := ABold;
|
||||||
Italic := AItalic;
|
Italic := AItalic;
|
||||||
StrikeTrough := AStrikeTrough;
|
StrikeTrough := AStrikeTrough;
|
||||||
Underline := AUnderline;
|
Underline := AUnderline;
|
||||||
|
TextListBase := InitializeFont(Font);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FindStylizedFont;
|
FindStylizedFont;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TGLUTFreeTypeFont.TextHeight(Text: string): integer;
|
function TGLUTBitmapFont.TextHeight(Text: string): integer;
|
||||||
begin
|
begin
|
||||||
Result := Size;
|
Result := Size;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TGLUTFreeTypeFont.TextWidth(Text: string): integer;
|
function TGLUTBitmapFont.TextWidth(Text: string): integer;
|
||||||
begin
|
begin
|
||||||
//only one font available or style not found then show default
|
Result := glutBitmapLength(FFontList[FActiveFont].Font, PChar(Text));
|
||||||
//Result := FFontList[FActiveFont].Font.TextWidth(Text)
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGLUTFreeTypeFont.TextOut(x, y: double; Text: string);
|
procedure TGLUTBitmapFont.TextOut(x, y: double; Text: string);
|
||||||
begin
|
begin
|
||||||
//FFontList[FActiveFont].Font.Print(x, y, Text);
|
glListBase(FFontList[FActiveFont].TextListBase);
|
||||||
|
glRasterPos2f(x, y);
|
||||||
|
glCallLists(Length(Text), GL_UNSIGNED_BYTE, @Text[1]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Reference in New Issue
Block a user