Simple font loading and rendering

This commit is contained in:
Matt Thorson
2020-06-15 00:56:01 -07:00
parent 2a9940d7bd
commit de0146e4e5
5 changed files with 113 additions and 26 deletions

View File

@ -99,5 +99,18 @@ namespace Strawberry
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None);
}
static public void Text(Strawberry.Font font, String text, Point position, Color color)
{
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
let surface = SDLTTF.RenderUTF8_Blended(font.Font, text, color);
let texture = SDL.CreateTextureFromSurface(Game.Renderer, surface);
SDL.Rect srcRect = .(0, 0, surface.w, surface.h);
SDL.Rect destRect = .((int32)position.X, (int32)position.Y, surface.w, surface.h);
SDL.RenderCopy(Game.Renderer, texture, &srcRect, &destRect);
SDL.FreeSurface(surface);
SDL.DestroyTexture(texture);
}
}
}