AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Font erstellen Laden mit Open GL , aber wie ?
Thema durchsuchen
Ansicht
Themen-Optionen

Font erstellen Laden mit Open GL , aber wie ?

Ein Thema von Corpsman · begonnen am 17. Mai 2006 · letzter Beitrag vom 26. Mai 2007
 
Benutzerbild von Corpsman
Corpsman

Registriert seit: 8. Nov 2005
Ort: nähe Stuttgart
981 Beiträge
 
Delphi XE2 Professional
 
#1

Font erstellen Laden mit Open GL , aber wie ?

  Alt 17. Mai 2006, 16:02
Hi , Ich versuche gerade eine Klasse zu bauen die mir eine Font aus einer Datei lädt und diese dann via Opengl auf den Monitor ausgibt.

Dazu habe ich die unten augeführte Unit gebastelt.

Das Laden des Bitmap's klappt und der Rechner malt mir auch was auf den Monitor,
Allerdings sieht das alles andere als Richtig aus.

Das einzige was ich erkennen kann ist das die Anzahl der Buchstaben stimmt.

Mein Versuch ist heir einen Buchstaben 20 x 20 Pixel groß zu laden. Nur leider klappt das nicht.
nach nun über 6 h rumprobieren hab ich keine Idee mehr was ich noch bauen könnte.

Falls jemand eine Functionierende version hat die functioniert würde ich die auch nehmen.
Alles was ich gerade versuceh ist einen Text auf den OpenGL monitor aus zu geben.

Delphi-Quellcode:
Unit OpenGL_Font;

Interface

Uses
  glu,
  gl,
  glext, textures;

Type
  TOpenGLFont = Class
    mFontTexId: GLuint;
    mBaseListId: gluint;
    fbase: gluint;
    Procedure Go2d;
    Procedure exit2d;
  private
  public
    Constructor create();
    Procedure Textout(x, y: integer; fmt: String);
    Destructor destroy; override;
  End;

Implementation

Const
  NUMCHARS = 256;

Constructor TOpenGLFont.create();
Const
  bh = 20; // Height of one Letter
  bw = 20; // Width of one Letter
Var
  cx, cy: single;
  loop: integer;
Begin
  Inherited Create;
  LoadTexture('D:\Tools\Projects\Balanced\Pic400_400N.bmp', mFontTexId);
  mBaseListId := glGenLists(NUMCHARS); // Creating NUMCHARS Display Lists
  glBindTexture(GL_TEXTURE_2D, mFontTexId);
  For loop := 0 To numchars - 1 Do Begin
    cx := (loop Mod bw) / bw; // X Position Of Current Character
    cy := (loop / bh) / bh; // Y Position Of Current Character
    glNewList(mBaseListId + loop, GL_COMPILE); // Start Building A List
    glBegin(GL_QUADS); // Use A Quad For Each Character
    glTexCoord2f(cx, 1 - cy - (1 / bh)); // Texture Coord (Bottom Left)
    glVertex2i(0, 0); // Vertex Coord (Bottom Left)
    glTexCoord2f(cx + (1 / bw), 1 - cy - (1 / bh)); // Texture Coord (Bottom Right)
    glVertex2i(bw, 0); // Vertex Coord (Bottom Right)
    glTexCoord2f(cx + (1 / bw), 1 - cy); // Texture Coord (Top Right)
    glVertex2i(bw, bh); // Vertex Coord (Top Right)
    glTexCoord2f(cx, 1 - cy); // Texture Coord (Top Left)
    glVertex2i(0, bh); // Vertex Coord (Top Left)
    glEnd(); // Done Building Our Quad (Character)
    glTranslatef(bw, 0, 0); // Move To The Right Of The Character
    glEndList(); // Done Building The Display List
  End;
End;

Destructor TOpenGLFont.destroy;
Begin
  glDeleteLists(mBaseListId, NUMCHARS); // Delete All Display Lists
  // Inherited destroy; // Brauchen wir net machen da wir von TObject abgeleitet haben
End;

Procedure TOpenGLFont.Go2d();
Begin
  glMatrixMode(GL_PROJECTION);
  glPushMatrix(); // Store The Projection Matrix
  glLoadIdentity(); // Reset The Projection Matrix
  glOrtho(0, 640, 0, 480, -1, 1); // Set Up An Ortho Screen
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix(); // Store old Modelview Matrix
  glLoadIdentity(); // Reset The Modelview Matrix
End;

Procedure TOpenGLFont.Exit2d();
Begin
  glMatrixMode(GL_PROJECTION);
  glPopMatrix(); // Restore old Projection Matrix
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix(); // Restore old Projection Matrix
End;

Procedure TOpenGLFont.Textout(x, y: integer; fmt: String);
Begin
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, mFontTexId);
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND); // For transparent background
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  Go2d();
  glTranslated(x, y, 0);
  glListBase(mBaseListId - 32); // Font bitmaps starts at ' ' (space/32).
  glcolor3f(1, 0, 0);
  glCallLists(length(fmt), GL_BYTE, pchar(fmt)); // Write The Text To The Screen
  Exit2d();
  glDisable(GL_BLEND);
  glEnable(GL_DEPTH_TEST);
End;

End.
Angehängte Grafiken
Dateityp: bmp pic400_400n_894.bmp (468,8 KB, 35x aufgerufen)
Dateityp: bmp helloworld_893.bmp (24,5 KB, 38x aufgerufen)
Uwe
My Sitewww.Corpsman.de

My marble madness clone Balanced ( ca. 70,0 mb ) aktuell ver 2.01
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz