wglUseFontBitmaps: Unterschied zwischen den Versionen

Aus DGL Wiki
Wechseln zu: Navigation, Suche
(Beispiel: Quellcode aufgeräumt)
K (Bot: konvertiere/korrigiere HTML)
Zeile 8: Zeile 8:
 
== Delphi-Spezifikation ==
 
== Delphi-Spezifikation ==
  
  <b>function</b> wglUseFontBitmaps (<b><i>DC</i></b>: HDC; <b><i>first</i></b>, <b><i>count</i></b>, <b><i>listBase</i></b>: DWORD): BOOL;
+
  '''function''' wglUseFontBitmaps ('''''DC''''': HDC; '''''first''''', '''''count''''', '''''listBase''''': DWORD): BOOL;
  
  
Zeile 51: Zeile 51:
 
=== Procedural ===
 
=== Procedural ===
  
  <b>var</b>
+
  '''var'''
 
   FontLists: Cardinal;
 
   FontLists: Cardinal;
 
  <br>
 
  <br>
  <b>procedure </b>CreateLists; <font color="#000080"><i>// Wird einmal am Anfang aufgerufen</i></font>
+
  '''procedure '''CreateLists; <font color="#000080">''// Wird einmal am Anfang aufgerufen''</font>
  <b>var</b>
+
  '''var'''
 
   CustomFont: HFont;
 
   CustomFont: HFont;
 
  <b>begin
 
  <b>begin
 
   </b>FontLists := glGenLists(<font color="#000080">256</font>);
 
   </b>FontLists := glGenLists(<font color="#000080">256</font>);
 
   <br>
 
   <br>
   <font color="#000080"><i>// CustomFont := GetStockObject (SYSTEM_FONT);</i></font>
+
   <font color="#000080">''// CustomFont := GetStockObject (SYSTEM_FONT);''</font>
   <font color="#000080"><i>// Eine Alternative mit der man die Systemschriftart zurück bekommt.</i></font>
+
   <font color="#000080">''// Eine Alternative mit der man die Systemschriftart zurück bekommt.''</font>
 
   <br>
 
   <br>
 
   CustomFont := CreateFont(
 
   CustomFont := CreateFont(
                             <font color="#000080">32</font>,                  <font color="#000080"><i>// H&ouml;he</i></font>
+
                             <font color="#000080">32</font>,                  <font color="#000080">''// H&ouml;he''</font>
                             0,                  <font color="#000080"><i>// Breite 0=Keine Vorgabe</i></font>
+
                             0,                  <font color="#000080">''// Breite 0=Keine Vorgabe''</font>
 
                             0,
 
                             0,
 
                             0,
 
                             0,
                             0,                  <font color="#000080"><i>// Fett?</i></font>
+
                             0,                  <font color="#000080">''// Fett?''</font>
                             0,                  <font color="#000080"><i>// Kursiv?</i></font>
+
                             0,                  <font color="#000080">''// Kursiv?''</font>
                             0,                  <font color="#000080"><i>// Unterstrichen?</i></font>
+
                             0,                  <font color="#000080">''// Unterstrichen?''</font>
                             0,                  <font color="#000080"><i>// Durchgestrichen?</i></font>
+
                             0,                  <font color="#000080">''// Durchgestrichen?''</font>
 
                             ANSI_CHARSET,
 
                             ANSI_CHARSET,
 
                             OUT_TT_PRECIS,
 
                             OUT_TT_PRECIS,
 
                             CLIP_DEFAULT_PRECIS,
 
                             CLIP_DEFAULT_PRECIS,
 
                             NONANTIALIASED_QUALITY,
 
                             NONANTIALIASED_QUALITY,
                             FF_DONTCARE <b>or </b>DEFAULT_PITCH,
+
                             FF_DONTCARE '''or '''DEFAULT_PITCH,
                             <font color="#FF2222">'Times New Roman'</font>);  <font color="#000080"><i>// Name der Schrift</i></font>
+
                             <font color="#FF2222">'Times New Roman'</font>);  <font color="#000080">''// Name der Schrift''</font>
 
   <br>
 
   <br>
   SelectObject(DC, CustomFont);              <font color="#000080"><i>// Font auf einen Device Context benutzen</i></font>
+
   SelectObject(DC, CustomFont);              <font color="#000080">''// Font auf einen Device Context benutzen''</font>
   wglUseFontBitmaps (DC, 0, 255, FontLists);  <font color="#000080"><i>// Mit selektiertem Font Zeichen erstellen</i></font>
+
   wglUseFontBitmaps (DC, 0, 255, FontLists);  <font color="#000080">''// Mit selektiertem Font Zeichen erstellen''</font>
  <b>end</b>;
+
  '''end''';
  
 
=== Objekt orientiert ===
 
=== Objekt orientiert ===
  
  <b>var</b>
+
  '''var'''
 
   Font: TFont;
 
   Font: TFont;
 
  <br>
 
  <br>
  <b>procedure </b>CreateLists; <font color="#000080"><i>// Wird einmal am Anfang aufgerufen</i></font>
+
  '''procedure '''CreateLists; <font color="#000080">''// Wird einmal am Anfang aufgerufen''</font>
  <b>var</b>
+
  '''var'''
 
   CustomFont: HFont;
 
   CustomFont: HFont;
 
  <b>begin
 
  <b>begin
 
   </b>FontLists := glGenLists(<font color="#000080">256</font>);
 
   </b>FontLists := glGenLists(<font color="#000080">256</font>);
 
   <br>
 
   <br>
   Font := TFont.Create;  <font color="#000080"><i>// Instanz einer Fontklasse erstellen</i></font>
+
   Font := TFont.Create;  <font color="#000080">''// Instanz einer Fontklasse erstellen''</font>
   <b>try</b>
+
   '''try'''
     Font.Name := 'Times New Roman'; <font color="#000080"><i>// Name</i></font>
+
     Font.Name := 'Times New Roman'; <font color="#000080">''// Name''</font>
     Font.Size := 32;                <font color="#000080"><i>// Schriftgröße</i></font>
+
     Font.Size := 32;                <font color="#000080">''// Schriftgröße''</font>
     Font.Style := [fsBold];        <font color="#000080"><i>// Styles (fsBold, fsItalic, ...)</i></font>
+
     Font.Style := [fsBold];        <font color="#000080">''// Styles (fsBold, fsItalic, ...)''</font>
 
     <br>
 
     <br>
     SelectObject(DC, Font.Handle);              <font color="#000080"><i>// Font auf einen Device Context benutzen</i></font>
+
     SelectObject(DC, Font.Handle);              <font color="#000080">''// Font auf einen Device Context benutzen''</font>
     wglUseFontBitmaps (DC, 0, 255, FontLists);  <font color="#000080"><i>// Mit selektiertem Font Zeichen erstellen</i></font>
+
     wglUseFontBitmaps (DC, 0, 255, FontLists);  <font color="#000080">''// Mit selektiertem Font Zeichen erstellen''</font>
   <b>finally</b>
+
   '''finally'''
     FreeAndNil(Font);  <font color="#000080"><i>// erstellte Instanz wieder frei geben</i></font>
+
     FreeAndNil(Font);  <font color="#000080">''// erstellte Instanz wieder frei geben''</font>
   <b>end</b>;
+
   '''end''';
  <b>end</b>;
+
  '''end''';
  
 
=== Bitmapfonts benutzen ===
 
=== Bitmapfonts benutzen ===
  
  <b>procedure</b> ShowText(pText: <b>String</b>);
+
  '''procedure''' ShowText(pText: '''String''');
 
  <b>begin
 
  <b>begin
     </b>glListBase(FontLists);  <font color="#000080"><i>// Liste auswählen</i></font>
+
     </b>glListBase(FontLists);  <font color="#000080">''// Liste auswählen''</font>
     glCallLists(Length(pText), GL_UNSIGNED_BYTE, Pointer(pText));  <font color="#000080"><i>// Entsprechende Listen aufrufen</i></font>
+
     glCallLists(Length(pText), GL_UNSIGNED_BYTE, Pointer(pText));  <font color="#000080">''// Entsprechende Listen aufrufen''</font>
  <b>end</b>;
+
  '''end''';
 
  <br>
 
  <br>
  <b>procedure </b>Draw;  <font color="#000080"><i>// Zeichen Routine</i></font>
+
  '''procedure '''Draw;  <font color="#000080">''// Zeichen Routine''</font>
  <b>begin</b>
+
  '''begin'''
   glClear(GL_COLOR_BUFFER_BIT <b>or </b>GL_DEPTH_BUFFER_BIT);
+
   glClear(GL_COLOR_BUFFER_BIT '''or '''GL_DEPTH_BUFFER_BIT);
   glColor3f(1,0.5,0);        <font color="#000080"><i>// Aktuelle Farbe f&uuml;r glRasterPos festlegen</i></font>
+
   glColor3f(1,0.5,0);        <font color="#000080">''// Aktuelle Farbe f&uuml;r glRasterPos festlegen''</font>
   glRasterPos3f(-0.1,0,-1);  <font color="#000080"><i>// (sichtbare) Rasterposition eintellen</i></font>
+
   glRasterPos3f(-0.1,0,-1);  <font color="#000080">''// (sichtbare) Rasterposition eintellen''</font>
 
   ShowText(<font color="#FF2222">'OpenGL '</font>);
 
   ShowText(<font color="#FF2222">'OpenGL '</font>);
   ShowText(<font color="#FF2222">'Wiki'</font>);          <font color="#000080"><i>// Steht nach &quot;OpenGL&quot; da glBitmap die Rasterposition verschiebt.</i></font>
+
   ShowText(<font color="#FF2222">'Wiki'</font>);          <font color="#000080">''// Steht nach &quot;OpenGL&quot; da glBitmap die Rasterposition verschiebt.''</font>
  <b>end</b>;
+
  '''end''';
  
 
==Siehe auch ==
 
==Siehe auch ==

Version vom 3. Dezember 2005, 19:25 Uhr

wglUseFontBitmaps


Name

wglUseFontBitmaps - Erzeugt aus der Schrifteinstellungen des Device Context eine Reihe von glBitmap Befehlen für die Buchstaben und speichert diese in Displaylisten.

Delphi-Spezifikation

function wglUseFontBitmaps (DC: HDC; first, count, listBase: DWORD): BOOL;



Parameter

DC Ein Display Context mit entsprechenden Font-Einstellungen.
first Mit welchen Zeichen soll begonnen werden
count Anzahl der zu erzeugenden Listen/Zeichen
listBase Der Name/Index der Liste für das erste Zeichen


Beschreibung

Die Schrifteinstellungen des Display Contextes werden genutzt, um mit glBitmap-Befehlen die angebenen Zeichen in Displaylisten zu speichern. Wenn ein Fehler auftritt wird statt true, false zurückgegeben und der Fehler kann über GetLastError abgerufen werden.


Hinweise

Jede Display Liste erhält logischerweise nur einen glBitmap Aufruf.

Da der glBitmap Befehl genutzt wird ändert sich die Rasterposition nach aufruf einer Liste.

Falls für ein Zeichen in der gewählten Schrift keine Daten vorliegen wird für dieses Zeichen eine leere Displayliste zurückgegeben.

Die durch diese Funktion unter Windows zur Verfügung stehende Schrift hat eine festgelegte Größe und ist logischerweise nur 2D. Möchte man eine 3D-Schrift haben so kann man dafür den Befehl wglUseFontOutlines benutzen.

Beispiel

Zum Erstellen der Bitmapfonts gibt es wie üblich mehrere Wege. Einmal den Weg direkt über die Windowsapi oder den Weg über die Delphiklasse TFont. Das Zeichnen bleibt bei beiden gleich. Aus diesem Grund ist es auch vom Rest ein wenig getrennt.

Procedural

var
  FontLists: Cardinal;

procedure CreateLists; // Wird einmal am Anfang aufgerufen var CustomFont: HFont; begin FontLists := glGenLists(256);
// CustomFont := GetStockObject (SYSTEM_FONT); // Eine Alternative mit der man die Systemschriftart zurück bekommt.
CustomFont := CreateFont( 32, // Höhe 0, // Breite 0=Keine Vorgabe 0, 0, 0, // Fett? 0, // Kursiv? 0, // Unterstrichen? 0, // Durchgestrichen? ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, FF_DONTCARE or DEFAULT_PITCH, 'Times New Roman'); // Name der Schrift
SelectObject(DC, CustomFont); // Font auf einen Device Context benutzen wglUseFontBitmaps (DC, 0, 255, FontLists); // Mit selektiertem Font Zeichen erstellen end;

Objekt orientiert

var
  Font: TFont;

procedure CreateLists; // Wird einmal am Anfang aufgerufen var CustomFont: HFont; begin FontLists := glGenLists(256);
Font := TFont.Create; // Instanz einer Fontklasse erstellen try Font.Name := 'Times New Roman'; // Name Font.Size := 32; // Schriftgröße Font.Style := [fsBold]; // Styles (fsBold, fsItalic, ...)
SelectObject(DC, Font.Handle); // Font auf einen Device Context benutzen wglUseFontBitmaps (DC, 0, 255, FontLists); // Mit selektiertem Font Zeichen erstellen finally FreeAndNil(Font); // erstellte Instanz wieder frei geben end; end;

Bitmapfonts benutzen

procedure ShowText(pText: String);
begin
   glListBase(FontLists);  // Liste auswählen
   glCallLists(Length(pText), GL_UNSIGNED_BYTE, Pointer(pText));  // Entsprechende Listen aufrufen
end;

procedure Draw; // Zeichen Routine begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glColor3f(1,0.5,0); // Aktuelle Farbe für glRasterPos festlegen glRasterPos3f(-0.1,0,-1); // (sichtbare) Rasterposition eintellen ShowText('OpenGL '); ShowText('Wiki'); // Steht nach "OpenGL" da glBitmap die Rasterposition verschiebt. end;

Siehe auch

glBitmap, glListBase, glCallLists, wglUseFontOutlines