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

Aktuelle Zeit: Sa Jul 19, 2025 21:12

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Mo Aug 22, 2005 13:50 
Offline
DGL Member
Benutzeravatar

Registriert: Do Jun 09, 2005 13:48
Beiträge: 117
Wohnort: Sankt Augustin
Ich habe (mit Hilfe von Vorlagen) eine Komponente zur Textausgabe geschrieben. Es klappt auch alles ganz toll bis auf eine Sache: wenn ich die Funktion glFont.Print (...) ausführe, verändert sich die Projektionsmatrix. Ich habe vorher alles schön perspektivisch dargestellt und habe es nach der Ausführung von CallLists im 2D Modus ohne tiefe etc. vor mir. Das habe ich ausprobiert, indem ich die Zeile mit CallLists auskommentiert habe. Ist sie auskommentiert sieht alles toll aus. Wenn nicht dann halt nicht. Ich habe mal den Code der Komponent eingefügt.

Wenn jemand das gleiche Problem schon mal hatte oder so weiß wodran es liegt, dann schreibt mir bitte.

Ich hjabe schon extra Prozeduren zum sichern und zurückspeichern aller Matrizen geschrieben (PushAll und PopAll) aber das bringt leider auch nichts.


Code:
  1.  
  2. unit glFont;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows,
  8.   Graphics,
  9.   SysUtils,
  10.   Classes,
  11.   Controls,
  12.   Dialogs,
  13.   Forms,
  14.   OpenGLUtil,
  15.   DglOpenGL;
  16.  
  17. type
  18.   TPglFont=^TglFont;
  19.   TglFont=class(TComponent)
  20.   private
  21.     FFont: HFONT;                                    // Windows Font ID
  22.     FFontList: GLUint;
  23.     FFontgmf : array [0..255] of GLYPHMETRICSFLOAT;  // Address Buffer For Font Storage
  24.     FEnabled: boolean;
  25.     procedure PopAll;
  26.     procedure PushAll;
  27.   public
  28.     constructor Create(AOwner:TComponent); override;
  29.     destructor Destroy; override;
  30.     procedure Print(text: pChar; V1: TGKvector);
  31.     procedure BuildFont (FontName: string; glFontDC: HDC);
  32.     procedure KillFont;
  33.   published
  34.     property Enabled: boolean read FEnabled write FEnabled;
  35.   end; {TOpenGL}
  36.  
  37. procedure Register;
  38.  
  39. var
  40.   OldFont: string;
  41.  
  42. implementation
  43.  
  44. constructor TglFont.Create(AOwner:TComponent);
  45. begin
  46.   inherited Create(AOwner);
  47.   FFont := 0;
  48. end;
  49.  
  50. destructor TglFont.Destroy;
  51. begin
  52.   inherited destroy;
  53. end;
  54.  
  55. procedure TglFont.BuildFont (FontName: string; glFontDC: HDC); // Build Our Bitmap Font
  56. begin
  57.   if not FEnabled then
  58.     exit;
  59.   if FFont <> 0 then
  60.     KillFont;
  61.   PushAll;
  62.  
  63.   FFontList := glGenLists(256);             // Storage For 256 Characters
  64.   glEnable(GL_POINT_SMOOTH);
  65.  
  66.   FFont := CreateFont(32,                   // Height Of Font
  67.                       10,                   // Width Of Font
  68.                       0,                    // Angle Of Escapement
  69.                       0,                    // Orientation Angle
  70.                       FW_BOLD,              // Font Weight
  71.                       0,                    // Italic
  72.                       0,                    // Underline
  73.                       0,                    // Strikeout
  74.                       ANSI_CHARSET,         // Character Set Identifier
  75.                       OUT_TT_PRECIS,        // Output Precision
  76.                       CLIP_DEFAULT_PRECIS,  // Clipping Precision
  77.                       ANTIALIASED_QUALITY,  // Output Quality
  78.                       FF_DONTCARE or DEFAULT_PITCH, // Family And Pitch
  79.                       PCHAR(FontName));     // Font Name
  80.  
  81.   SelectObject(glFontDC, FFont);            // Selects The Font We Want
  82.  
  83.   wglUseFontOutlines(glFontDC,              // Select The wanted DC
  84.                      0,                     // Starting Character
  85.                      256,                   // Number Of Display Lists To Build
  86.                      FFontList,             // Starting Display Lists
  87.                      0.0,                   // Deviation From The True Outlines
  88.                      0.5,                   // Font Thickness In The Z Direction
  89.                      WGL_FONT_POLYGONS,     // Use Polygons, Not Lines
  90.                      @FFontgmf);            // Address Of Buffer To Recieve Data
  91.  
  92.   PopAll;
  93. end;
  94.  
  95. procedure TglFont.KillFont;
  96. begin
  97.   if not FEnabled then
  98.     exit;
  99.   if not glIsList (FFontList) then
  100.     exit;
  101.   PushAll;
  102.   glDeleteLists(FFontList, 256);                   // Lösche alle 256 Zeichen
  103.   FFont := 0;
  104.   PopAll;
  105. end;
  106.  
  107. procedure TglFont.Print(text: pChar; V1: TGKvector);
  108. var
  109.   laenge: glfloat;
  110.   loop: integer;
  111.   V2: TGLvector;
  112. begin
  113.   if not FEnabled then
  114.     exit;
  115.   if text = '' then
  116.     exit;
  117.   if not glIsList (FFontList) then
  118.     exit;
  119.  
  120.   V2 := GK2GLvector (V1);  // vertauscht y und z
  121.  
  122.   // länge des texts ermitteln (für was auch immer...)
  123.   laenge := 0;
  124.   for loop:=1 to length(text)-1 do
  125.     laenge := laenge + FFontgmf[loop].gmfCellIncX;
  126.  
  127.   PushAll;
  128.   glPushAttrib(GL_LIST_BIT);
  129.   glListBase(FFontList);
  130.   glMatrixMode(GL_MODELVIEW);
  131.   glTranslatef(V2.x, V2.y, V2.z);
  132.   glCallLists(length(text),GL_UNSIGNED_BYTE,text);
  133.   glPopAttrib;
  134.   PopAll;
  135. end;
  136.  
  137. procedure TglFont.PushAll;
  138. begin
  139.   glMatrixMode(GL_MODELVIEW);
  140.   glPushMatrix;
  141.   glMatrixMode(GL_PROJECTION);
  142.   glPushMatrix;
  143.   glMatrixMode(GL_TEXTURE);
  144.   glPushMatrix;
  145. end;
  146.  
  147. procedure TglFont.PopAll;
  148. begin
  149.   glMatrixMode(GL_TEXTURE);
  150.   glPopMatrix;
  151.   glMatrixMode(GL_PROJECTION);
  152.   glPopMatrix;
  153.   glMatrixMode(GL_MODELVIEW);
  154.   glPopMatrix;
  155. end;
  156.  
  157. procedure Register;
  158. begin
  159.   RegisterComponents('OpenGL',[TglFont]);
  160. end;
  161.  
  162. end.
  163.  


Zuletzt geändert von Andyh am Di Aug 23, 2005 11:02, insgesamt 2-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 22, 2005 14:51 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7810
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
Also...ich hatte das vor einiger Zeit auch mal benutzt. Der Code sah so ähnlich aus...ich kann jetzt nicht nachvollziehen, wieso deine Push&Pops net greifen.... :?

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 22, 2005 19:17 
Offline
DGL Member
Benutzeravatar

Registriert: Sa Nov 13, 2004 11:00
Beiträge: 229
Wohnort: Steinhude
die stacks haben nur ne begrenzte größe. ist es möglich dass noch irgendwo anders die matrix gepusht wird und nicht zu rechten zeit wieder gepopt? in dem fall würden push und pop nämlich wirkungslos bleiben.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: hab ich schon überprüft
BeitragVerfasst: Di Aug 23, 2005 03:00 
Offline
DGL Member
Benutzeravatar

Registriert: Do Jun 09, 2005 13:48
Beiträge: 117
Wohnort: Sankt Augustin
An die Stacks hatte ich auch schon gedacht und habe versucht das nachzuvollziehen. Das scheint in Ordnung zu sein. Das komische ist, dass ich den Projektionsmodus nicht mehr auf Perspektive umschalten kann. Wenn ich einmal den Befehl CallLists aufgerufen habe, bleibt mein System immer im Ortho-Modus.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: funktioniert jetzt
BeitragVerfasst: Di Aug 23, 2005 03:32 
Offline
DGL Member
Benutzeravatar

Registriert: Do Jun 09, 2005 13:48
Beiträge: 117
Wohnort: Sankt Augustin
Ich habe mal ein bisschen rumprobiert und herausgefunden, dass der Befehl "glPushAttrib (GL_LIST_BIT) " nicht richtig war. man muss stattdessen "glPushAttrib (GL_ALL_ATTRIB_BITS)" ausführen. Hier wird bestimmt einiges weggesichert was man nicht sichern braucht aber ich habe keine Lust jetzt jedes einzelne Attribut zu testen.

Hier der Funktionierende Code un eine kurze Anleitung zum Gebrauch (funktioniert jetzt einwandfrei):

Code:
  1. unit glFont;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows,
  7.   Graphics,
  8.   SysUtils,
  9.   Classes,
  10.   Controls,
  11.   Dialogs,
  12.   Forms,
  13.   OpenGLUtil,
  14.   DglOpenGL;
  15.  
  16. type
  17.   TPglFont=^TglFont;
  18.   TglFont=class(TComponent)
  19.   private
  20.     FFont: HFONT;                                    // Windows Font ID
  21.     FFontList: TGLUint;
  22.     FFontSize: integer;
  23.     FFontThickness: integer;
  24.     FFontWidth: integer;
  25.     FFontgmf : array [0..255] of GLYPHMETRICSFLOAT;  // Address Buffer For Font Storage
  26.     FEnabled: boolean;
  27.   public
  28.     constructor Create(AOwner:TComponent); override;
  29.     destructor Destroy; override;
  30.     procedure Print(text: pChar; V1: TGKvector);
  31.     procedure BuildFont (FontName: string; glFontDC: HDC);
  32.     procedure KillFont;
  33.   published
  34.     property Enabled: boolean read FEnabled write FEnabled;
  35.     property FontSize: integer read FFontSize write FFontSize;
  36.     property FontThickness: integer read FFontThickness write FFontThickness;
  37.     property FontWidth: integer read FFontWidth write FFontWidth;
  38.   end; {TOpenGL}
  39.  
  40. procedure Register;
  41.  
  42. var
  43.   OldFont: string;
  44.  
  45. implementation
  46.  
  47. constructor TglFont.Create(AOwner:TComponent);
  48. begin
  49.   inherited Create(AOwner);
  50.   FFont := 0;
  51.   FFontSize := 12;
  52.   FFontWidth := 10;
  53.   FFontThickness := 1;
  54. end;
  55.  
  56. destructor TglFont.Destroy;
  57. begin
  58.   inherited destroy;
  59. end;
  60.  
  61. procedure TglFont.BuildFont (FontName: string; glFontDC: HDC); // Build Our Bitmap Font
  62. begin
  63.   if not FEnabled then
  64.     exit;
  65.   if FFont <> 0 then
  66.     KillFont;
  67.  
  68.   FFontList := glGenLists(256);             // Storage For 256 Characters
  69.   glEnable(GL_POINT_SMOOTH);
  70.  
  71.   FFont := CreateFont(FFontSize,            // Height Of Font
  72.                       FFontWidth,           // Width Of Font
  73.                       0,                    // Angle Of Escapement
  74.                       0,                    // Orientation Angle
  75.                       FW_NORMAL,            // Font Weight
  76.                       0,                    // Italic
  77.                       0,                    // Underline
  78.                       0,                    // Strikeout
  79.                       ANSI_CHARSET,         // Character Set Identifier
  80.                       OUT_TT_PRECIS,        // Output Precision
  81.                       CLIP_DEFAULT_PRECIS,  // Clipping Precision
  82.                       ANTIALIASED_QUALITY,  // Output Quality
  83.                       FF_DONTCARE or DEFAULT_PITCH, // Family And Pitch
  84.                       PCHAR(FontName));     // Font Name
  85.  
  86.   SelectObject(glFontDC, FFont);            // Selects The Font We Want
  87.  
  88.   wglUseFontOutlines(glFontDC,              // Select The wanted DC
  89.                      0,                     // Starting Character
  90.                      256,                   // Number Of Display Lists To Build
  91.                      FFontList,             // Starting Display Lists
  92.                      0.0,                   // Deviation From The True Outlines
  93.                      FFontThickness/10,     // Font Thickness In The Z Direction
  94.                      WGL_FONT_POLYGONS,     // Use Polygons, Not Lines
  95.                      @FFontgmf);            // Address Of Buffer To Recieve Data
  96. end;
  97.  
  98. procedure TglFont.KillFont;
  99. begin
  100.   if not FEnabled then
  101.     exit;
  102.   if not glIsList (FFontList) then
  103.     exit;
  104.   glDeleteLists(FFontList, 256);                   // Lösche alle 256 Zeichen
  105.   FFont := 0;
  106. end;
  107.  
  108. procedure TglFont.Print(text: pChar; V1: TGKvector);
  109. var
  110.   laenge: glfloat;
  111.   loop: integer;
  112.   V2: TGLvector;
  113. begin
  114.   if not FEnabled then
  115.     exit;
  116.   if text = '' then
  117.     exit;
  118.   if not glIsList (FFontList) then
  119.     exit;
  120.  
  121.   V2 := GK2GLvector (V1);
  122.  
  123.   // länge des texts ermitteln (für was auch immer...)
  124.   laenge := 0;
  125.   for loop:=1 to length(text)-1 do
  126.     laenge := laenge + FFontgmf[loop].gmfCellIncX;
  127.  
  128.   //glPushAttrib(GL_LIST_BIT);
  129.   glPushAttrib (GL_ALL_ATTRIB_BITS);
  130.   glListBase(FFontList);
  131.   glMatrixMode(GL_MODELVIEW);
  132.   glTranslatef(V2.x, V2.y, V2.z);
  133.   glCallLists(length(text),GL_UNSIGNED_BYTE,text);
  134.   glPopAttrib;
  135. end;
  136.  
  137. procedure Register;
  138. begin
  139.   RegisterComponents('OpenGL',[TglFont]);
  140. end;
  141.  
  142. end.
  143.  



Beispiel zur Benutzung. Hierbei wird davon ausgegangen, dass die Komponente aus der Komponentenleiste auf das aktuelle Formular gezogen wurde.

Code:
  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   ..., glFont;
  7.  
  8. type
  9.   TGLVector = packed record
  10.     x,y,z: GLfloat;
  11.   end;
  12.  
  13. type
  14.   TFMain = class(TForm)
  15.     .
  16.     .
  17.     .
  18.     glFont1: TglFont;
  19.     .
  20.     .
  21.     .
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  24.     procedure FormPaint(Sender: TObject);
  25.   private
  26.   public
  27.   end;
  28.  
  29. var
  30.   FMain: TFMain;
  31.  
  32. implementation
  33.  
  34. procedure TFMain.FormCreate(Sender: TObject);
  35. begin
  36.   glFont1.Enabled := true;
  37.   glFont1.FontSize := 12;
  38.   glFont1.FontWidth := 10;
  39.   glFont1.FontThickness := 1;
  40.   glFont1.BuildFont('Arial Black', getDC(handle));
  41. end;
  42.  
  43. procedure TFMain.FormPaint(Sender: TObject);
  44. var
  45.   pVec: TGLvector;
  46. begin
  47.   pVec.x := 0;
  48.   pVec.y := 0;
  49.   pVec.z := 0;
  50.  
  51.   glColor3f (1, 0.7, 0);
  52.   glFont1.Print('Dies ist ein 3D Text', pVec);
  53. end;
  54.  
  55. procedure TFMain.FormClose(Sender: TObject; var Action: TCloseAction);
  56. begin
  57.   glFont1.KillFont;
  58. end;
  59.  


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


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 13 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 | 14 Queries | GZIP : On ]