Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Mi Jul 09, 2025 08:04

Foren-Übersicht » Programmierung » Einsteiger-Fragen
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Do Jun 15, 2006 13:13 
Offline
DGL Member

Registriert: Di Mai 24, 2005 16:43
Beiträge: 710
basierend auf dem bomberman tutorial habe ich mir einen bitmapfont manager geschrieben:
Code:
  1.  
  2. unit UBitmapFont;
  3.  
  4. interface
  5.  
  6. uses sysutils, inifiles, graphics, dglOpenGL, glBitmap, UConst, UVectors, UColors;
  7.  
  8. const
  9.  FontCoords: array[0..16, 0..16, 0..1] of Single = (
  10.     ((0.00000, 1.00000), (0.00000, 0.93750), (0.00000, 0.87500), (0.00000, 0.81250), (0.00000, 0.75000), (0.00000, 0.68750), (0.00000, 0.62500), (0.00000, 0.56250), (0.00000, 0.50000), (0.00000, 0.43750), (0.00000, 0.37500), (0.00000, 0.31250), (0.00000, 0.25000), (0.00000, 0.18750), (0.00000, 0.12500), (0.00000, 0.06250), (0.00000, 0.00000)),
  11.     ((0.06250, 1.00000), (0.06250, 0.93750), (0.06250, 0.87500), (0.06250, 0.81250), (0.06250, 0.75000), (0.06250, 0.68750), (0.06250, 0.62500), (0.06250, 0.56250), (0.06250, 0.50000), (0.06250, 0.43750), (0.06250, 0.37500), (0.06250, 0.31250), (0.06250, 0.25000), (0.06250, 0.18750), (0.06250, 0.12500), (0.06250, 0.06250), (0.06250, 0.00000)),
  12.     ((0.12500, 1.00000), (0.12500, 0.93750), (0.12500, 0.87500), (0.12500, 0.81250), (0.12500, 0.75000), (0.12500, 0.68750), (0.12500, 0.62500), (0.12500, 0.56250), (0.12500, 0.50000), (0.12500, 0.43750), (0.12500, 0.37500), (0.12500, 0.31250), (0.12500, 0.25000), (0.12500, 0.18750), (0.12500, 0.12500), (0.12500, 0.06250), (0.12500, 0.00000)),
  13.     ((0.18750, 1.00000), (0.18750, 0.93750), (0.18750, 0.87500), (0.18750, 0.81250), (0.18750, 0.75000), (0.18750, 0.68750), (0.18750, 0.62500), (0.18750, 0.56250), (0.18750, 0.50000), (0.18750, 0.43750), (0.18750, 0.37500), (0.18750, 0.31250), (0.18750, 0.25000), (0.18750, 0.18750), (0.18750, 0.12500), (0.18750, 0.06250), (0.18750, 0.00000)),
  14.     ((0.25000, 1.00000), (0.25000, 0.93750), (0.25000, 0.87500), (0.25000, 0.81250), (0.25000, 0.75000), (0.25000, 0.68750), (0.25000, 0.62500), (0.25000, 0.56250), (0.25000, 0.50000), (0.25000, 0.43750), (0.25000, 0.37500), (0.25000, 0.31250), (0.25000, 0.25000), (0.25000, 0.18750), (0.25000, 0.12500), (0.25000, 0.06250), (0.25000, 0.00000)),
  15.     ((0.31250, 1.00000), (0.31250, 0.93750), (0.31250, 0.87500), (0.31250, 0.81250), (0.31250, 0.75000), (0.31250, 0.68750), (0.31250, 0.62500), (0.31250, 0.56250), (0.31250, 0.50000), (0.31250, 0.43750), (0.31250, 0.37500), (0.31250, 0.31250), (0.31250, 0.25000), (0.31250, 0.18750), (0.31250, 0.12500), (0.31250, 0.06250), (0.31250, 0.00000)),
  16.     ((0.37500, 1.00000), (0.37500, 0.93750), (0.37500, 0.87500), (0.37500, 0.81250), (0.37500, 0.75000), (0.37500, 0.68750), (0.37500, 0.62500), (0.37500, 0.56250), (0.37500, 0.50000), (0.37500, 0.43750), (0.37500, 0.37500), (0.37500, 0.31250), (0.37500, 0.25000), (0.37500, 0.18750), (0.37500, 0.12500), (0.37500, 0.06250), (0.37500, 0.00000)),
  17.     ((0.43750, 1.00000), (0.43750, 0.93750), (0.43750, 0.87500), (0.43750, 0.81250), (0.43750, 0.75000), (0.43750, 0.68750), (0.43750, 0.62500), (0.43750, 0.56250), (0.43750, 0.50000), (0.43750, 0.43750), (0.43750, 0.37500), (0.43750, 0.31250), (0.43750, 0.25000), (0.43750, 0.18750), (0.43750, 0.12500), (0.43750, 0.06250), (0.43750, 0.00000)),
  18.     ((0.50000, 1.00000), (0.50000, 0.93750), (0.50000, 0.87500), (0.50000, 0.81250), (0.50000, 0.75000), (0.50000, 0.68750), (0.50000, 0.62500), (0.50000, 0.56250), (0.50000, 0.50000), (0.50000, 0.43750), (0.50000, 0.37500), (0.50000, 0.31250), (0.50000, 0.25000), (0.50000, 0.18750), (0.50000, 0.12500), (0.50000, 0.06250), (0.50000, 0.00000)),
  19.     ((0.56250, 1.00000), (0.56250, 0.93750), (0.56250, 0.87500), (0.56250, 0.81250), (0.56250, 0.75000), (0.56250, 0.68750), (0.56250, 0.62500), (0.56250, 0.56250), (0.56250, 0.50000), (0.56250, 0.43750), (0.56250, 0.37500), (0.56250, 0.31250), (0.56250, 0.25000), (0.56250, 0.18750), (0.56250, 0.12500), (0.56250, 0.06250), (0.56250, 0.00000)),
  20.     ((0.62500, 1.00000), (0.62500, 0.93750), (0.62500, 0.87500), (0.62500, 0.81250), (0.62500, 0.75000), (0.62500, 0.68750), (0.62500, 0.62500), (0.62500, 0.56250), (0.62500, 0.50000), (0.62500, 0.43750), (0.62500, 0.37500), (0.62500, 0.31250), (0.62500, 0.25000), (0.62500, 0.18750), (0.62500, 0.12500), (0.62500, 0.06250), (0.62500, 0.00000)),
  21.     ((0.68750, 1.00000), (0.68750, 0.93750), (0.68750, 0.87500), (0.68750, 0.81250), (0.68750, 0.75000), (0.68750, 0.68750), (0.68750, 0.62500), (0.68750, 0.56250), (0.68750, 0.50000), (0.68750, 0.43750), (0.68750, 0.37500), (0.68750, 0.31250), (0.68750, 0.25000), (0.68750, 0.18750), (0.68750, 0.12500), (0.68750, 0.06250), (0.68750, 0.00000)),
  22.     ((0.75000, 1.00000), (0.75000, 0.93750), (0.75000, 0.87500), (0.75000, 0.81250), (0.75000, 0.75000), (0.75000, 0.68750), (0.75000, 0.62500), (0.75000, 0.56250), (0.75000, 0.50000), (0.75000, 0.43750), (0.75000, 0.37500), (0.75000, 0.31250), (0.75000, 0.25000), (0.75000, 0.18750), (0.75000, 0.12500), (0.75000, 0.06250), (0.75000, 0.00000)),
  23.     ((0.81250, 1.00000), (0.81250, 0.93750), (0.81250, 0.87500), (0.81250, 0.81250), (0.81250, 0.75000), (0.81250, 0.68750), (0.81250, 0.62500), (0.81250, 0.56250), (0.81250, 0.50000), (0.81250, 0.43750), (0.81250, 0.37500), (0.81250, 0.31250), (0.81250, 0.25000), (0.81250, 0.18750), (0.81250, 0.12500), (0.81250, 0.06250), (0.81250, 0.00000)),
  24.     ((0.87500, 1.00000), (0.87500, 0.93750), (0.87500, 0.87500), (0.87500, 0.81250), (0.87500, 0.75000), (0.87500, 0.68750), (0.87500, 0.62500), (0.87500, 0.56250), (0.87500, 0.50000), (0.87500, 0.43750), (0.87500, 0.37500), (0.87500, 0.31250), (0.87500, 0.25000), (0.87500, 0.18750), (0.87500, 0.12500), (0.87500, 0.06250), (0.87500, 0.00000)),
  25.     ((0.93750, 1.00000), (0.93750, 0.93750), (0.93750, 0.87500), (0.93750, 0.81250), (0.93750, 0.75000), (0.93750, 0.68750), (0.93750, 0.62500), (0.93750, 0.56250), (0.93750, 0.50000), (0.93750, 0.43750), (0.93750, 0.37500), (0.93750, 0.31250), (0.93750, 0.25000), (0.93750, 0.18750), (0.93750, 0.12500), (0.93750, 0.06250), (0.93750, 0.00000)),
  26.     ((1.00000, 1.00000), (1.00000, 0.93750), (1.00000, 0.87500), (1.00000, 0.81250), (1.00000, 0.75000), (1.00000, 0.68750), (1.00000, 0.62500), (1.00000, 0.56250), (1.00000, 0.50000), (1.00000, 0.43750), (1.00000, 0.37500), (1.00000, 0.31250), (1.00000, 0.25000), (1.00000, 0.18750), (1.00000, 0.12500), (1.00000, 0.06250), (1.00000, 0.00000)));
  27.  
  28. type
  29.   TBitmapFont = class
  30.     Fonts: array of Tgluint;
  31.     FontBases: array of Tgluint;
  32.     FontName: THashedStringList;
  33.     constructor Create;
  34.     destructor Destroy; override;    
  35.     procedure Free;
  36.   public
  37.     procedure AddFont(pFileName, pFontName: String);
  38.     procedure AddFontsInDir(pDirName, pFileMask: String; psubdirs: boolean);
  39.     procedure PrintText(pFontName: String; pposition: TVector2D; pscalefactor: single; pColor: TColor; pAlpha: integer; ptext: string);
  40.   end;
  41.  
  42. implementation
  43.  
  44. constructor TBitmapFont.Create;
  45. begin
  46.   inherited Create;
  47.   setlength(Fonts, 0);
  48.   setlength(FontBases, 0);
  49.   FontName := THashedStringList.Create;
  50. end;
  51.  
  52. destructor TBitmapFont.Destroy;
  53. begin
  54.   FontName.Free;
  55.   inherited Destroy;
  56. end;
  57.  
  58. procedure TBitmapFont.Free;
  59. begin
  60.   if Self <> nil then
  61.     Destroy;
  62. end;
  63.  
  64. procedure TBitmapFont.AddFont(pFileName, pFontName: String);
  65. var
  66.   x, y: Byte;
  67. begin
  68.   if (fileexists(pFilename)) and (FontName.IndexOf(pFontname) = -1) then
  69.   begin
  70.     setlength(Fonts, length(Fonts) + 1);
  71.     setlength(FontBases, length(FontBases) + 1);
  72.     LoadTexture(pFilename, Fonts[high(Fonts)], False);
  73.     FontBases[High(FontBases)] := glGenLists(256);
  74.     for x := 0 to 15 do
  75.       for y := 0 to 15 do
  76.       begin
  77.         glNewList(FontBases[High(FontBases)] + x + y * 16, GL_COMPILE);
  78.         glEnable(GL_ALPHA_TEST);
  79.         glAlphaFunc(GL_GREATER, 0.1);
  80.         glBindTexture(GL_TEXTURE_2D, Fonts[high(fonts)]);
  81.         glBegin(GL_QUADS);
  82.           glTexCoord2fv(@FontCoords[x,   y]);    glVertex3f( 0,  0, 0);
  83.           glTexCoord2fv(@FontCoords[x+1, y]);    glVertex3f(16,  0, 0);
  84.           glTexCoord2fv(@FontCoords[x+1, y+1]);  glVertex3f(16, 16, 0);
  85.           glTexCoord2fv(@FontCoords[x,   y+1]);  glVertex3f( 0, 16, 0);
  86.         glEnd;
  87.         glDisable(GL_ALPHA_TEST);
  88.         glTranslatef(12, 0, 0);
  89.         glEndList;
  90.       end;
  91.     FontName.add(pFontName);
  92.   end;
  93. end;
  94.  
  95. procedure TBitmapFont.AddFontsInDir(pDirName, pFileMask: String; psubdirs: boolean);
  96.   procedure ScanDir(const Directory: String);
  97.     function CutExt(astr: string): string;
  98.     var
  99.       i: integer;
  100.     begin
  101.       result := astr;
  102.       for i := length(astr) downto 1 do
  103.         if astr[i] = '.' then
  104.         begin
  105.           result := copy(astr, 1, i - 1);
  106.           exit;
  107.         end;
  108.     end;
  109.   var
  110.     SR: TSearchRec;
  111.   begin
  112.     if FindFirst(Directory + pFileMask, faAnyFile - faDirectory, SR) = 0 then
  113.     try
  114.       repeat
  115.         AddFont(Directory + SR.Name, CutExt(SR.Name));
  116.       until FindNext(SR) <> 0;
  117.     finally
  118.       FindClose(SR);
  119.     end;
  120.     if pSubDirs then
  121.     begin
  122.       if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then
  123.       try
  124.         repeat
  125.           if ((SR.attr and faDirectory) = faDirectory) and (SR.Name <> '.') and (SR.Name <> '..') then
  126.             ScanDir(Directory + SR.Name + '');
  127.         until FindNext(SR) <> 0;
  128.       finally
  129.         FindClose(SR);
  130.       end;
  131.     end;
  132.   end;
  133. var
  134.   aDir: string;
  135. begin
  136.   aDir := pDirName;
  137.   if aDir = '' then
  138.     Exit;
  139.   if aDir[Length(aDir)] <> '' then
  140.     aDir := aDir + '';
  141.   ScanDir(aDir);
  142. end;
  143.  
  144. procedure TBitmapFont.PrintText(pFontName: String; pposition: TVector2D; pscalefactor: single; pColor: TColor; pAlpha: integer; ptext: string);
  145. var
  146.   aindex: integer;
  147. begin
  148.   aindex := Fontname.IndexOf(pFontName);
  149.   glDisable(GL_DEPTH_TEST);
  150.   glBindTexture(GL_TEXTURE_2D, Fonts[aindex]);
  151.   RGBAf(pcolor, palpha);
  152.   glPushMatrix;
  153.     glTranslatef(pPosition.x, pPosition.y, 0);
  154.     glScalef(pScaleFactor, pScaleFactor , pScaleFactor);
  155.     glListBase(FontBases[aindex]);
  156.     glCallLists(Length(pText), GL_BYTE, Pointer(pText));
  157.   glPopMatrix;
  158.   RGBAf(clwhite, 255);
  159.   glEnable(GL_DEPTH_TEST);
  160. end;
  161.  
  162. end.
  163.  

angenommen ich schreibe als testtext die zeichen von a-z dann sind die zeichen anscheinend 3 spalten zu weite unten (ok kann man ja noch korrigieren, obwohl das schon merkwürdig ist), aber dann kommen auf einmal nur noch großbuchstaben, ziemlich komisch, dabei ist der hauptcode so ziemlich der gleiche.

aufruf erfolgt so:

Code:
  1.  
  2. BitmapFont.PrintText('verdana', to_v2d(10, 10), 2, clblue, 255, 'abcdefghijklmnopqrstuvwxyz');
  3.  


RGBAf ist das ungefähr das gleiche wie glColor4ub (heißt das so ?)

vielen dank schonmal, mfg


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jun 17, 2006 21:12 
Offline
DGL Member

Registriert: Di Mai 24, 2005 16:43
Beiträge: 710
das problem besteht immernoch, und ich habe keinen blassesn schimmer warum das nicht funktioniert.

der code aus dem tutorial ist identisch. was ist denn hier großartig anders ?


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Foren-Übersicht » Programmierung » Einsteiger-Fragen


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 5 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.012s | 15 Queries | GZIP : On ]