Einzelnen Beitrag anzeigen

Benutzerbild von Mr_T
Mr_T

Registriert seit: 7. Jun 2002
Ort: Eilsum
136 Beiträge
 
Delphi 2005 Personal
 
#7

Re: OpenGL Text | in Form einbauen

  Alt 20. Okt 2003, 12:48
Man kann mit OpenGL auch 3d Fonts erzeugen ... dafür benötigt man eine Displayliste (eine Variable vom Typ tglint wenn man OpenGl 1.2 oder 1.5 verwendet bzw. bei der Standart Delphi-Unit eine Variable vom Typ gluint) .. diese habe ich mal "base" genannt (die Variable)... denn muss man den Font erzeugen:

Delphi-Quellcode:
procedure BuildFont;          // Build Our Bitmap Font
var font: HFONT;     // Windows Font ID
    gmf : array [0..255] of GLYPHMETRICSFLOAT;      // Address Buffer For Font Storage
begin
  base := glGenLists(256);     // Storage For 96 Characters
  font := CreateFont(12,             // Height Of Font
           0,                // Width Of Font
           0,                // Angle Of Escapement
           0,                // Orientation Angle
           0,       // Font Weight
           0,              // Italic
           0,              // Underline
           0,              // Strikeout
           ANSI_CHARSET,       // Character Set Identifier
           OUT_TT_PRECIS,    // Output Precision
           CLIP_DEFAULT_PRECIS,    // Clipping Precision
           ANTIALIASED_QUALITY,       // Output Quality
           FF_DONTCARE or DEFAULT_PITCH,    // Family And Pitch
           'Arial Black');          // Font Name

  SelectObject(form1.myDC, font);           // Selects The Font We Want

  wglUseFontOutlines(   form1.myDC,            // Select The Current DC
                        0,            // Starting Character
                        255,            // Number Of Display Lists To Build
                        base,            // Starting Display Lists
                        0.0,            // Deviation From The True Outlines
                        0.2,            // Font Thickness In The Z Direction
                        WGL_FONT_POLYGONS,      // Use Polygons, Not Lines
                        @gmf);            // Address Of Buffer To Recieve Data

end;
So, diesen Code hier führt man am Anfang der Anwendung aus (am ende von Form1.oncreate aufrufen) ... Nun kann man mitdieser Prozedur Text auf den Screen bringen:

Delphi-Quellcode:
procedure glPrint(text : pchar);    // Custom GL "Print" Routine
begin
  if (text = '') then           // If There's No Text
          Exit;                // Do Nothing

  glPushAttrib(GL_LIST_BIT);            // Pushes The Display List Bits
  glListBase(base);               // Sets The Base Character
  glCallLists(length(text), GL_UNSIGNED_BYTE, text);   // Draws The Display List Text
  glPopAttrib();                              // Pops The Display List Bits
end;
Sieht zwar alles sehr schwierig aus, hoffe aber, ich konnte dir helfen (Ist kein einfaches Thema)
Mein neuer, 13 Teiliger Open GL - Kurs (Samples in Delphi):
www.dcw-group.net
Neu! Ein großer Teil der Demos nach Kylix übersetzt!
Neu! Teil 2b: Initialisierung von OpenGL unter Kylix ist fertig!
  Mit Zitat antworten Zitat