DGL
https://delphigl.com/forum/

Charactor Size
https://delphigl.com/forum/viewtopic.php?f=19&t=3081
Seite 1 von 1

Autor:  Stucuk [ Sa Jul 24, 2004 01:43 ]
Betreff des Beitrags:  Charactor Size

Im working on creating a Text system, one like Half-Life has, where text can fade in and out etc. But since id like to be able to make the system "write" the text and have the option of per Charactor fade and/or colour change i need to draw the charactors seperatly. The problem is i don't know how to work out the size each charactor would take up. (thus it looks a bit stupid)

Code:
  1.  
  2. procedure MakeRasterFont(var TextSystem : TTextSystem);
  3. var fnt : HFONT;
  4. begin
  5.   TextSystem.Font.ID := glGenLists (128);             // generate 128 display lists
  6.   fnt := CreateFont(TextSystem.Font.Height, TextSystem.Font.Width,0,0, FW_NORMAL, 0, 0, 0, OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY    , FF_DONTCARE + DEFAULT_PITCH, Pchar(TextSystem.Font.Name));
  7.   SelectObject(h_DC, fnt);
  8.   wglUseFontBitmaps(h_DC, 0, 127, TextSystem.Font.ID);
  9. end;
  10.  
  11. procedure PrintChar(TextChar : TTextChar; Font : TTextFont);
  12. var
  13. S : string;
  14. begin
  15.  
  16.   if not TextChar.Draw then
  17.   exit;
  18.  
  19.   glLoadIdentity;
  20.   with TextChar do
  21.   begin
  22.   glColor4f(Colour.X,Colour.Y,Colour.Z,Alpha);
  23.   glRasterPos2f(Position.X, SCREEN_HEIGHT-Position.Y);                        // Set the position for the text to be rendered
  24.   glPushAttrib (GL_LIST_BIT);
  25.     glListBase(Font.ID);
  26.     S := Charactor;
  27.     glCallLists(length(S), GL_UNSIGNED_BYTE,  PChar(S));
  28.   glPopAttrib();
  29.   end;
  30.  
  31. end;
  32.  

Autor:  Sascha Willems [ Sa Jul 24, 2004 09:46 ]
Betreff des Beitrags: 

Since you're working with wglUseFontBitmaps, you can use GetCharWidth32 (for more infos, look at the Windows SDK help) to get the size of a specific character.

Autor:  Stucuk [ Sa Jul 24, 2004 14:38 ]
Betreff des Beitrags: 

fnt moved to the TextFont so can b called later:
Code:
  1.  
  2. procedure MakeRasterFont(var TextSystem : TTextSystem);
  3. begin
  4.   TextSystem.Font.ID := glGenLists (128);             // generate 128 display lists
  5.   TextSystem.Font.fnt := CreateFont(TextSystem.Font.Height, TextSystem.Font.Width,0,0, FW_NORMAL, 0, 0, 0, OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY    , FF_DONTCARE + DEFAULT_PITCH, Pchar(TextSystem.Font.Name));
  6.   SelectObject(h_DC, TextSystem.Font.fnt);
  7.   wglUseFontBitmaps(h_DC, 0, 127, TextSystem.Font.ID);
  8. end;
  9.  


Modifyed bit that sets up the charactors in the TextSystem:
Code:
  1.  
  2. MakeRasterFont(TextSystem);
  3.  
  4. SelectObject(h_DC, TextSystem.Font.fnt);
  5. L := 0;
  6.  
  7. for x := 0 to TextSystem.Charactor_No-1 do
  8. begin
  9. if not GetCharWidth32(h_DC,Ord(S[x+1]),Ord(S[x+1]),TextSystem.Charactors[x].Width) then
  10. messagebox(0,'Error: Couldn`t get Width','Text Error',0);
  11. TextSystem.Charactors[x].Charactor := S[x+1];
  12. TextSystem.Charactors[x].Alpha := 1;
  13. TextSystem.Charactors[x].Colour := SetVector(1,1,1);
  14. TextSystem.Charactors[x].Draw := true;
  15. L := L + TextSystem.Charactors[x].Width;
  16. TextSystem.Charactors[x].Position.X := 50 + L;//X*TextSystem.Font.Width;
  17. TextSystem.Charactors[x].Position.Y := 50;
  18. end;
  19.  


Going by This the untyped varible is a integer.

Attachment shows x and M overlap with other charactors.

EDIT: nm stupid error on my part

Code:
  1.  
  2. L := L + TextSystem.Charactors[x].Width;
  3. TextSystem.Charactors[x].Position.X := 50 + L;//X*TextSystem.Font.Width;
  4.  


should have been

Code:
  1.  
  2. TextSystem.Charactors[x].Position.X := 50 + L;//X*TextSystem.Font.Width;
  3. L := L + TextSystem.Charactors[x].Width;
  4.  


Thx for ur help SOS.

Dateianhänge:
Dateikommentar: Text not right, X and M overlapp.
notrighttext.JPG
notrighttext.JPG [ 1.36 KiB | 3262-mal betrachtet ]

Autor:  Stucuk [ Di Jul 27, 2004 15:41 ]
Betreff des Beitrags: 

Is there a thing to work out font height? The font Papyrus at size 72 is about 51 pixels in height. The reason i ask is cos id like the text system to work with 0,0 at the top left rather than the opengl bottom left.

Iv seen a few ways some ppl have worked it out. Tho these are wrong.

Code:
  1.  
  2. Abs(-Font.Height);
  3. Trunc(-FontDialog1.Font.Height * Font.PixelsPerInch / 72);
  4.  

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/