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

Aktuelle Zeit: Do Jul 17, 2025 08:46

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Charactor Size
BeitragVerfasst: Sa Jul 24, 2004 01:43 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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.  

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jul 24, 2004 09:46 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
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.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jul 24, 2004 14:38 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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 | 3260-mal betrachtet ]

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Jul 27, 2004 15:41 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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.  

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


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.010s | 18 Queries | GZIP : On ]