aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
Diffstat (limited to 'Game/Code')
-rw-r--r--Game/Code/Classes/TextGL.pas122
-rw-r--r--Game/Code/Classes/UTextClasses.pas57
-rw-r--r--Game/Code/UltraStar.dpr105
3 files changed, 214 insertions, 70 deletions
diff --git a/Game/Code/Classes/TextGL.pas b/Game/Code/Classes/TextGL.pas
index c73908f8..3f5d52b8 100644
--- a/Game/Code/Classes/TextGL.pas
+++ b/Game/Code/Classes/TextGL.pas
@@ -11,6 +11,8 @@ uses OpenGL12,
SDL,
UTexture,
Classes,
+ dialogs,
+ SDL_ttf,
ULog;
procedure BuildFont; // Build Our Bitmap Font
@@ -27,6 +29,16 @@ procedure SetFontStyle(Style: integer); // sets active font style (normal, bold,
procedure SetFontItalic(Enable: boolean); // sets italic type letter (works for all fonts)
procedure SetFontAspectW(Aspect: real);
+// Start of SDL_ttf
+function NextPowerOfTwo(Value: Integer): Integer;
+//Checks if the ttf exists, if yes then a SDL_ttf is returned
+function LoadFont(FileName: PAnsiChar; PointSize: integer):PTTF_Font;
+
+// Does the renderstuff, color is in $ffeecc style
+function RenderText(font: PTTF_Font; Text:PAnsiChar; Color: Cardinal):PSDL_Surface;
+procedure printrandomtext();
+// End of SDL_ttf
+
type
TTextGL = record
X: real;
@@ -323,6 +335,7 @@ procedure glPrint(text: pchar); // Custom GL "Print" Routine
var
// Letter : char;
iPos : Integer;
+
begin
if (Text = '') then // If There's No Text
Exit; // Do Nothing
@@ -350,6 +363,115 @@ begin
end;
+function NextPowerOfTwo(Value: Integer): Integer;
+// tyty to Asphyre
+begin
+ Result:= 1;
+ asm
+ xor ecx, ecx
+ bsr ecx, Value
+ inc ecx
+ shl Result, cl
+ end;
+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 );
+ 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) / 255);
+ clr.g := ((Color and $ff00) shr 8)/255;
+ clr.b := ( Color and $ff)/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, 0, intermediary, 0);
+
+ glGenTextures(1, texture);
+
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 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;
+
procedure glPrintCut(text: pchar);
var
Letter: char;
diff --git a/Game/Code/Classes/UTextClasses.pas b/Game/Code/Classes/UTextClasses.pas
new file mode 100644
index 00000000..5f66d0e8
--- /dev/null
+++ b/Game/Code/Classes/UTextClasses.pas
@@ -0,0 +1,57 @@
+unit UTextClasses;
+
+interface
+uses OpenGL12,
+ SDL,
+ UTexture,
+ Classes,
+ dialogs,
+ SDL_ttf,
+ ULog;
+
+{
+// okay i just outline what should be here, so we can create a nice and clean implementation of sdl_ttf
+// based up on this uml: http://jnr.sourceforge.net/fusion_images/www_FRS.png
+// thanks to Bob Pendelton and Koshmaar!
+// (1) let's start with a glyph, this represents one character in a word
+
+type
+ TGlyph = record
+ character : Char; // unsigned char, uchar is something else in delphi
+ glyphsSolid[8] : GlyphTexture; // fast, but not that
+ glyphsBlended[8] : GlyphTexture; // slower than solid, but it look's more pretty
+
+//this class has a method, which should be a deconstructor (mog is on his way to understand the principles of oop :P)
+ deconstructor procedure ReleaseTextures();
+end;
+
+// okay, we now need the stuff that's even beneath this glyph - we're right at the birth of text in here :P
+
+ GlyphTexture = record
+ textureID : GLuint; // we need this for caching the letters, if the texture wasn't created before create it, should be very fast because of this one
+ width,
+ height : Cardinal;
+ charWidth,
+ charHeight : Integer;
+ advance : Integer; // don't know yet for what this one is
+}
+
+{
+// after the glyph is done, we now start to build whole words - this one is pretty important, and does most of the work we need
+ TGlyphsContainer = record
+ glyphs array of TGlyph;
+ FontName array of string;
+ refCount : uChar; // unsigned char, uchar is something else in delphi
+ font : PTTF_font;
+ size,
+ lineSkip : Cardinal; // vertical distance between multi line text output
+ descent : Integer;
+
+
+
+}
+
+
+implementation
+
+end.
diff --git a/Game/Code/UltraStar.dpr b/Game/Code/UltraStar.dpr
index f795e250..cdd4aca4 100644
--- a/Game/Code/UltraStar.dpr
+++ b/Game/Code/UltraStar.dpr
@@ -6,49 +6,32 @@ program UltraStar;
{$I switches.inc}
uses
- //------------------------------
- //Includes - 3rd Party Libraries
- //------------------------------
- SDL in 'lib\JEDI-SDLv1.0\SDL\Pas\SDL.pas',
+ SDL in 'lib\JEDI-SDLv1.0\SDL\Pas\SDL.pas',
moduleloader in 'lib\JEDI-SDLv1.0\SDL\Pas\moduleloader.pas',
- sdlutils in 'lib\JEDI-SDLv1.0\SDL\Pas\sdlutils.pas',
- SDL_Image in 'lib\JEDI-SDLv1.0\SDL_Image\Pas\sdl_image.pas',
- OpenGL12 in 'lib\JEDI-SDLv1.0\OpenGL\Pas\OpenGL12.pas',
-
- bass in 'lib\bass\delphi\bass.pas',
-
- PNGImage in 'lib\PNGImage\PNGImage.pas',
- PNGzLib in 'lib\PNGImage\PNGzLib.pas',
- pnglang in 'lib\PNGImage\pnglang.pas',
-
- midiout in 'lib\midi\midiout.pas',
- midiin in 'lib\midi\midiin.pas',
- Circbuf in 'lib\midi\CIRCBUF.PAS',
- MidiType in 'lib\midi\MidiType.PAS',
- MidiDefs in 'lib\midi\MidiDefs.PAS',
- MidiCons in 'lib\midi\MidiCons.PAS',
- MidiFile in 'lib\midi\MidiFile.PAS',
- Delphmcb in 'lib\midi\Delphmcb.PAS',
-
- {$IFDEF UseSerialPort}
- zlportio in 'lib\zlportio\zlportio.pas',
- ddkint in 'lib\zlportio\ddkint.pas',
- {$ENDIF}
-
- avcodec in 'lib\ffmpeg\avcodec.pas',
- avformat in 'lib\ffmpeg\avformat.pas',
- avutil in 'lib\ffmpeg\avutil.pas',
- rational in 'lib\ffmpeg\rational.pas',
- opt in 'lib\ffmpeg\opt.pas',
- avio in 'lib\ffmpeg\avio.pas',
-
+ sdlutils in 'lib\JEDI-SDLv1.0\SDL\Pas\sdlutils.pas',
+ sdl_image in 'lib\JEDI-SDLv1.0\SDL_Image\Pas\sdl_image.pas',
+ OpenGL12 in 'lib\JEDI-SDLv1.0\OpenGL\Pas\OpenGL12.pas',
+ sdl_ttf in 'lib\JEDI-SDLv1.0\SDL_ttf\Pas\sdl_ttf.pas',
+ bass in 'lib\bass\delphi\bass.pas',
+ PNGImage in 'lib\PNGImage\PNGImage.pas',
+ PNGzLib in 'lib\PNGImage\PNGzLib.pas',
+ pnglang in 'lib\PNGImage\pnglang.pas',
+ midiout in 'lib\midi\midiout.pas',
+ midiin in 'lib\midi\midiin.pas',
+ CIRCBUF in 'lib\midi\CIRCBUF.PAS',
+ MidiType in 'lib\midi\MidiType.PAS',
+ MidiDefs in 'lib\midi\MidiDefs.PAS',
+ MidiCons in 'lib\midi\MidiCons.PAS',
+ MidiFile in 'lib\midi\MidiFile.PAS',
+ Delphmcb in 'lib\midi\Delphmcb.PAS',
+ avcodec in 'lib\ffmpeg\avcodec.pas',
+ avformat in 'lib\ffmpeg\avformat.pas',
+ avutil in 'lib\ffmpeg\avutil.pas',
+ rational in 'lib\ffmpeg\rational.pas',
+ opt in 'lib\ffmpeg\opt.pas',
+ avio in 'lib\ffmpeg\avio.pas',
SQLiteTable3 in 'lib\SQLite\SQLiteTable3.pas',
- SQLite3 in 'lib\SQLite\SQLite3.pas',
-
-
- //------------------------------
- //Includes - Menu System
- //------------------------------
+ SQLite3 in 'lib\SQLite\SQLite3.pas',
UDisplay in 'Menu\UDisplay.pas',
UMenu in 'Menu\UMenu.pas',
UMenuStatic in 'Menu\UMenuStatic.pas',
@@ -59,11 +42,7 @@ uses
UMenuSelectSlide in 'Menu\UMenuSelectSlide.pas',
UDrawTexture in 'Menu\UDrawTexture.pas',
UMenuButtonCollection in 'Menu\UMenuButtonCollection.pas',
-
- //------------------------------
- //Includes - Classes
- //------------------------------
- UCommon in 'Classes\UCommon.pas',
+ UCommon in 'Classes\UCommon.pas',
UGraphic in 'Classes\UGraphic.pas',
UTexture in 'Classes\UTexture.pas',
UMusic in 'Classes\UMusic.pas',
@@ -91,18 +70,10 @@ uses
UDLLManager in 'Classes\UDLLManager.pas',
UParty in 'Classes\UParty.pas',
UPlaylist in 'Classes\UPlaylist.pas',
- UCommandLine in 'Classes\UCommandLine.pas',
+ UCommandLine in 'Classes\UCommandLine.pas',
USingScores in 'Classes\USingScores.pas',
USingNotes in 'Classes\USingNotes.pas',
-
- //------------------------------
- //Includes - Video Support
- //------------------------------
UVideo in 'Classes\UVideo.pas',
-
- //------------------------------
- //Includes - Screens
- //------------------------------
UScreenLoading in 'Screens\UScreenLoading.pas',
UScreenWelcome in 'Screens\UScreenWelcome.pas',
UScreenMain in 'Screens\UScreenMain.pas',
@@ -131,29 +102,16 @@ uses
UScreenStatDetail in 'Screens\UScreenStatDetail.pas',
UScreenCredits in 'Screens\UScreenCredits.pas',
UScreenPopup in 'Screens\UScreenPopup.pas',
-
- //------------------------------
- //Includes - Screens PartyMode
- //------------------------------
UScreenSingModi in 'Screens\UScreenSingModi.pas',
UScreenPartyNewRound in 'Screens\UScreenPartyNewRound.pas',
UScreenPartyScore in 'Screens\UScreenPartyScore.pas',
UScreenPartyPlayer in 'Screens\UScreenPartyPlayer.pas',
UScreenPartyOptions in 'Screens\UScreenPartyOptions.pas',
UScreenPartyWin in 'Screens\UScreenPartyWin.pas',
-
- //------------------------------
- //Includes - Modi SDK
- //------------------------------
ModiSDK in '..\..\Modis\SDK\ModiSDK.pas',
-
- //------------------------------
- //Includes - Delphi
- //------------------------------
Windows,
- SysUtils;
-
-
+ SysUtils,
+ UTextClasses in 'Classes\UTextClasses.pas';
const
Version = 'UltraStar Deluxe V 1.10 Alpha Build';
@@ -218,6 +176,13 @@ begin
Log.BenchmarkEnd(1);
Log.LogBenchmark('Initializing SDL', 1);
+ // SDL_ttf
+ Log.BenchmarkStart(1);
+ Log.LogStatus('Initialize SDL_ttf', 'Initialization');
+ TTF_Init(); //ttf_quit();
+ Log.BenchmarkEnd(1);
+ Log.LogBenchmark('Initializing SDL_ttf', 1);
+
// Skin
Log.BenchmarkStart(1);
Log.LogStatus('Loading Skin List', 'Initialization'); Skin := TSkin.Create;