Sorry for double post. But i have one more question. When i change display method on sdl_opengl, my ttf unit doesn't work.
Code:
unit fonts;
interface
uses
sdl in 'lib/sdl.pas',
sdl_image in 'lib/sdl_image.pas',
sdl_ttf in 'lib/sdl_ttf.pas',
classes,
sysUtils;
type
TFonts = class
private
fOffset : tsdl_rect;
fFont : pttf_font;
fFontColor : tsdl_color;
fFontSurface : psdl_surface;
fScreen : psdl_surface;
fAlign : integer;
function getX : integer;
function getY : integer;
procedure setX(ax : integer);
procedure setY(ay : integer);
public
property x : integer read getX write setX;
property y : integer read getY write setY;
property offset : tsdl_rect read fOffset write fOffset;
property fontColor : tsdl_color read fFontColor write fFontColor;
property align : integer read fAlign write fAlign;
constructor create(aScreen : psdl_surface);
procedure loadFont(aFile : string; aSize : integer);
procedure drawText(Atext : string);
end;
const
ALIGN_LEFT = 1;
ALIGN_CENTER = 2;
ALIGN_RIGHT = 3;
implementation
uses globals;
function TFonts.getX: integer;
begin
result := fOffset.x;
end;
function TFonts.getY: integer;
begin
result := fOffset.y;
end;
procedure TFonts.setX(ax: integer);
begin
fOffset.x := ax;
end;
procedure TFonts.setY(ay: integer);
begin
fOffset.y := ay;
end;
constructor TFonts.create(aScreen: psdl_surface);
begin
fScreen := aScreen;
fAlign := ALIGN_LEFT;
fontColor.r := 255;
fontColor.g := 255;
fontColor.b := 255;
if ttf_init < 0 then writeln('Could not load font');
end;
procedure TFonts.loadFont(aFile: string; aSize: integer);
begin
fFont := ttf_openFont(pChar(aFile), aSize);
end;
procedure TFonts.drawText(aText: string);
var
_tempOffset : tsdl_rect;
begin
fFontSurface := ttf_renderText_solid(fFont, pChar(aText), fFontColor);
case fAlign of
ALIGN_LEFT:
_tempOffset.x := 0;
ALIGN_CENTER:
_tempOffset.x := -fFontSurface^.w div 2;
ALIGN_RIGHT:
_TempOffset.x := -FFontSurface^.w;
end;
_tempOffset.x := _tempOffset.x + fOffset.x;
_tempOffset.y := fOffset.y;
sdl_blitSurface(fFontSurface, nil, fScreen, @_tempOffset);
sdl_freeSurface(fFontSurface);
end;
end.
I am pwned by opengl
Bookmarks