[update] Implemented rendering font text.

This commit is contained in:
falsycat 2019-10-12 00:00:00 +00:00
parent ac37fbf3e5
commit d49aa08b45
2 changed files with 47 additions and 3 deletions

3
.bin/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*
!/.gitignore
!/fonts

View File

@ -1,7 +1,8 @@
/// License: MIT
module sj.Font;
import std.exception,
import std.conv,
std.exception,
std.format,
std.string;
@ -22,8 +23,48 @@ class Font {
}
///
Texture2DRef Render(string text, size_t px) {
assert(false);
Texture2DRef CreateTexture(
vec2i sz, string str, vec4 color, size_t px) {
auto text = sfText_create().enforce;
scope(exit) sfText_destroy(text);
sfText_setFont(text, font_);
sfText_setString(text, str.toStringz);
sfText_setCharacterSize(text, px.to!uint);
sfText_setFillColor(text, sfBlack); // TODO: change color
auto buf = sfRenderTexture_create(sz.x, sz.y, false).enforce;
scope(exit) sfRenderTexture_destroy(buf);
sfRenderTexture_drawText(buf, text, null);
auto sftex = sfRenderTexture_getTexture(buf).enforce;
auto tex = Texture2D.Create();
Texture2DAllocator allocator;
with (allocator) {
internalFormat = GL_RGBA8;
size = sz;
format = GL_RED;
type = GL_UNSIGNED_BYTE;
Allocate(tex);
}
gl.CopyImageSubData(
sfTexture_getNativeHandle(sftex),
GL_TEXTURE_2D,
0,
0,
0,
0,
tex.id,
GL_TEXTURE_2D,
0,
0,
0,
0,
sz.x, sz.y, 1
);
return tex;
}
private: