aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/TextGL.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-19 11:36:41 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-19 11:36:41 +0000
commit6edda5db659a67a119b3469ad92080e168ed2944 (patch)
tree1a8c4e477d4737003bc3bcea70ca66990c031862 /src/base/TextGL.pas
parente60c0d3e29be2c77e7ab8deca6c37d0b07ebf085 (diff)
downloadusdx-6edda5db659a67a119b3469ad92080e168ed2944.tar.gz
usdx-6edda5db659a67a119b3469ad92080e168ed2944.tar.xz
usdx-6edda5db659a67a119b3469ad92080e168ed2944.zip
offscreen rendering removed:
- fixes zoom errors - fixes missing lyric lines if window is too small - better text quality - fixes some other errors git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1457 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src/base/TextGL.pas')
-rw-r--r--src/base/TextGL.pas150
1 files changed, 16 insertions, 134 deletions
diff --git a/src/base/TextGL.pas b/src/base/TextGL.pas
index 8569fadf..03351adf 100644
--- a/src/base/TextGL.pas
+++ b/src/base/TextGL.pas
@@ -37,7 +37,6 @@ uses
gl,
SDL,
UTexture,
-// SDL_ttf,
ULog;
procedure BuildFont; // build our bitmap font
@@ -45,6 +44,7 @@ procedure KillFont; // delete the font
function glTextWidth(text: PChar): real; // returns text width
procedure glPrintLetter(letter: char);
procedure glPrint(text: pchar); // custom GL "Print" routine
+procedure ResetFont(); // reset font settings of active font
procedure SetFontPos(X, Y: real); // sets X and Y
procedure SetFontZ(Z: real); // sets Z
procedure SetFontSize(Size: real);
@@ -209,13 +209,19 @@ function glTextWidth(text: pchar): real;
var
Letter: char;
i: integer;
+ Font: PFont;
begin
Result := 0;
+ Font := @Fonts[ActFont];
+
for i := 0 to Length(text) -1 do
begin
Letter := Text[i];
- Result := Result + Fonts[ActFont].Width[Ord(Letter)] * Fonts[ActFont].Tex.H / 30 * Fonts[ActFont].AspectW;
+ Result := Result + Font.Width[Ord(Letter)] * Font.Tex.H / 30 * Font.AspectW;
end;
+
+ if ((Result > 0) and Font.Italic) then
+ Result := Result + 12 * Font.Tex.H / 60 * Font.AspectW;
end;
procedure glPrintLetter(Letter: char);
@@ -332,6 +338,14 @@ begin
end;
end;
+procedure ResetFont();
+begin
+ SetFontPos(0, 0);
+ SetFontZ(0);
+ SetFontItalic(False);
+ SetFontReflection(False, 0);
+end;
+
procedure SetFontPos(X, Y: real);
begin
Fonts[ActFont].Tex.X := X;
@@ -374,136 +388,4 @@ begin
Fonts[ActFont].Blend := Enable;
end;
-
-
-
-(*
-<mog> I uncommented this, because it was some kind of after hour hack together with blindy
-it's actually just a prove of concept, as it's having some flaws
-- instead nice and clean ttf code should be placed here :)
-
-{$IFDEF FPC}
- {$ASMMODE Intel}
-{$ENDIF}
-
-function NextPowerOfTwo(Value: integer): integer;
-begin
- Result:= 1;
-{$IF Defined(CPUX86_64)}
- asm
- mov rcx, -1
- bsr rcx, Value
- inc rcx
- shl Result, cl
- end;
-{$ELSEIF Defined(CPU386) or Defined(CPUI386)}
- asm
- mov ecx, -1
- bsr ecx, Value
- inc ecx
- shl Result, cl
- end;
-{$ELSE}
- while (Result <= Value) do
- Result := 2 * Result;
-{$IFEND}
-end;
-
-function LoadFont(FileName: PAnsiChar; PointSize: integer):PTTF_Font;
-begin
- if (FileExists(FileName)) then
- begin
- Result := TTF_OpenFont( FileName, PointSize );
- end
- else
- begin
- Log.LogStatus('ERROR Could not find font in ' + FileName , '');
- ShowMessage( 'ERROR Could not find font in ' + FileName );
- Result := nil;
- end;
-end;
-
-function RenderText(font: PTTF_Font; Text:PAnsiChar; Color: Cardinal): PSDL_Surface;
-var
- clr : TSDL_color;
-begin
- clr.r := ((Color and $ff0000) shr 16 ) div 255;
- clr.g := ((Color and $ff00 ) shr 8 ) div 255;
- clr.b := ( Color and $ff ) div 255 ;
-
- result := TTF_RenderText_Blended( font, text, cLr);
-end;
-
-procedure printrandomtext();
-var
- stext,intermediary : PSDL_surface;
- clrFg, clrBG : TSDL_color;
- texture : Gluint;
- font : PTTF_Font;
- w,h : integer;
-begin
-
- font := LoadFont('fonts\comicbd.ttf', 42);
-
- clrFg.r := 255;
- clrFg.g := 255;
- clrFg.b := 255;
- clrFg.unused := 255;
-
- clrBg.r := 255;
- clrbg.g := 0;
- clrbg.b := 255;
- clrbg.unused := 0;
-
- sText := RenderText(font, 'katzeeeeeee', $fe198e);
- //sText := TTF_RenderText_Blended( font, 'huuuuuuuuuund', clrFG);
-
- // Convert the rendered text to a known format
- w := nextpoweroftwo(sText.w);
- h := nextpoweroftwo(sText.h);
-
- intermediary := SDL_CreateRGBSurface(0, w, h, 32,
- $000000ff, $0000ff00, $00ff0000, $ff000000);
-
- SDL_SetAlpha(intermediary, 0, 255);
- SDL_SetAlpha(sText, 0, 255);
- SDL_BlitSurface(sText, nil, intermediary, nil);
-
- glGenTextures(1, @texture);
-
- glBindTexture(GL_TEXTURE_2D, texture);
-
- glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, intermediary.pixels);
-// on big endian machines (powerpc) this may need to be changed to
-// Needs to be tests. KaMiSchi Sept 2008
-// glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, intermediary.pixels);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- glEnable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glBindTexture(GL_TEXTURE_2D, texture);
- glColor4f(1, 0, 1, 1);
-
- glbegin(gl_quads);
- glTexCoord2f(0, 0); glVertex2f(200 , 300 );
- glTexCoord2f(0, sText.h/h); glVertex2f(200 , 300 + sText.h);
- glTexCoord2f(sText.w/w, sText.h/h); glVertex2f(200 + sText.w, 300 + sText.h);
- glTexCoord2f(sText.w/w, 0); glVertex2f(200 + sText.w, 300 );
- glEnd;
- glfinish();
- glDisable(GL_BLEND);
- gldisable(gl_texture_2d);
-
- SDL_FreeSurface(sText);
- SDL_FreeSurface(intermediary);
- glDeleteTextures(1, @texture);
- TTF_CloseFont(font);
-
-end;
-*)
-
-
end.