- procedure TGL2DTextureFont.BuildFont(aDC : HDC; const aTexture : String; aWidth : Integer = -1);
- var
- iList : Integer;
- ix, iy : Integer;
- cx, cy : TGLFloat;
- cwx, cwy : TGLFloat;
- iWidth, iHeight : Integer;
- begin
- if not FileExists(aTexture) then begin
- raise Exception.CreateFmt('Font "%s" nicht gefunden!', [aTexture]);
- end;
- fTexture.LoadFromFile(aTexture);
- if fHasAlphaColor then begin
- fTexture.AddAlphaFromColorKey(fAlphaRed, fAlphaGreen, fAlphaBlue);
- end;
- iWidth := fTexture.Width div fColCount;
- iHeight := fTexture.Height div fRowCount;
- fTexture.BuildMipMaps := False;
- fTexture.SetFilter(GL_LINEAR, GL_LINEAR);
- fTexture.FlipVert;
- fTexture.GenTexture();
- // Creating Display Lists
- fBase := glGenLists(fColCount * fRowCount);
- fTexture.Bind;
- cwx := ((1.0 * iWidth) / fTexture.Width);
- cwy := ((1.0 * iHeight) / fTexture.Height);
- iList := 0;
- for iy := 0 to Pred(fRowCount) do begin
- for ix := 0 to Pred(fColCount) do begin
- cx := ix * cwx; // X Position Of Character
- cy := 1 - iy * cwy; // Y Position Of Character
- glNewList(fBase + iList, GL_COMPILE);
- glBegin(GL_QUADS);
- glTexCoord2f(cx, cy - cwy); // Texture Coord (Bottom Left)
- glVertex2i(0, 0); // Vertex Coord (Bottom Left)
- glTexCoord2f(cx + cwx, cy - cwy); // Texture Coord (Bottom Right)
- glVertex2i(iWidth, 0); // Vertex Coord (Bottom Right)
- glTexCoord2f(cx + cwx, cy); // Texture Coord (Top Right)
- glVertex2i(iWidth, iHeight); // Vertex Coord (Top Right)
- glTexCoord2f(cx, cy); // Texture Coord (Top Left)
- glVertex2i(0, iHeight); // Vertex Coord (Top Left)
- glEnd();
- if (aWidth > 0) then begin
- glTranslated(aWidth, 0, 0);
- end else begin
- glTranslated(iWidth, 0, 0);
- end;
- glEndList();
- Inc(iList);
- end;
- end;
- end;