Fixed ???
Some files have been renamed
This commit is contained in:
@@ -151,6 +151,8 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
|
||||
|
||||
rect->texture = opts->texture;
|
||||
|
||||
F32 w, h;
|
||||
|
||||
rect->x = opts->p.x;
|
||||
rect->y = opts->p.y;
|
||||
|
||||
@@ -177,11 +179,19 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
|
||||
}
|
||||
|
||||
if (opts->flags & D_RECT_IGNORE_ASPECT) {
|
||||
rect->w = opts->dim.w;
|
||||
rect->h = opts->dim.h;
|
||||
w = opts->dim.w;
|
||||
h = opts->dim.h;
|
||||
}
|
||||
else {
|
||||
Vk_Image *image = &draw->images[opts->texture].image;
|
||||
Vk_Image *image = 0;
|
||||
if (opts->texture >= draw->n_images) {
|
||||
// @hack: first font texture
|
||||
//
|
||||
image = &draw->fonts->image;
|
||||
}
|
||||
else {
|
||||
image = &draw->images[opts->texture].image;
|
||||
}
|
||||
|
||||
F32 width = cast(F32) image->width;
|
||||
F32 height = cast(F32) image->height;
|
||||
@@ -191,53 +201,42 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
|
||||
height *= (opts->uv.max.y - opts->uv.min.y);
|
||||
}
|
||||
|
||||
F32 aspect_w = (width > height) ? (width / height) : 1.0f;
|
||||
F32 aspect_h = (width > height) ? 1.0f : (height / width);
|
||||
F32 aspect_w = (width > height) ? 1.0f : (width / height);
|
||||
F32 aspect_h = (width > height) ? (height / width) : 1.0f;
|
||||
|
||||
rect->w = opts->scale * aspect_w;
|
||||
rect->h = opts->scale * aspect_h;
|
||||
w = opts->scale * aspect_w;
|
||||
h = opts->scale * aspect_h;
|
||||
}
|
||||
|
||||
if (opts->flags & D_RECT_FLIP_X) { w *= -1.0f; }
|
||||
if (opts->flags & D_RECT_FLIP_Y) { h *= -1.0f; }
|
||||
|
||||
rect->w = w;
|
||||
rect->h = h;
|
||||
|
||||
draw->n_rects += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void D_Text(D_Context *draw, D_Font *font, Str8 text, F32 x, F32 y) {
|
||||
F32 xoff = x;
|
||||
local_persist B32 done = 0;
|
||||
|
||||
// @Todo: control scale
|
||||
F32 scale = 1.0f / (font->ascent - font->descent);
|
||||
|
||||
for (S64 it = 0; it < text.count; ++it) {
|
||||
if (text.data[it] >= ' ' && text.data[it] <= '~') {
|
||||
D_Glyph *glyph = &font->glyphs[text.data[it] - ' '];
|
||||
|
||||
V2f size;
|
||||
size.w = (glyph->box.max.x - glyph->box.min.x);
|
||||
size.h = (glyph->box.max.y - glyph->box.min.y);
|
||||
F32 image_scale = scale * Max(glyph->dim.w, glyph->dim.h);
|
||||
F32 advance = scale * glyph->advance;
|
||||
|
||||
V2f dim;
|
||||
V2f offset = V2f_Scale(glyph->offset, scale);
|
||||
|
||||
F32 scale = 150.0f / (font->ascent - font->descent);
|
||||
|
||||
if (size.w > size.h) {
|
||||
dim.w = scale * (size.w / size.h);
|
||||
dim.h = scale;
|
||||
}
|
||||
else {
|
||||
dim.w = scale;
|
||||
dim.h = scale * (size.h / size.w);
|
||||
}
|
||||
|
||||
// @Hardcode: need font index in font struct
|
||||
D_Rect(draw, xoff, y, .texture = 0, .c = V4F(0, 1, 1, 1), .dim = dim, .flags = D_RECT_IGNORE_ASPECT);
|
||||
D_Rect(draw, xoff, y, .texture = draw->n_images, .uv = glyph->box, .dim = dim, .flags = D_RECT_IGNORE_ASPECT);
|
||||
xoff += (1.05f * dim.w); // glyph->advance; //+ glyph->offset.x;
|
||||
|
||||
if (!done) { printf(" %f (%f, %f)", xoff, dim.w, dim.h); }
|
||||
D_Rect(draw, xoff + offset.x, y + offset.y, .texture = font->id, .uv = glyph->box, .scale = image_scale, .flags = D_RECT_UV_ASPECT);
|
||||
xoff += advance;
|
||||
}
|
||||
}
|
||||
|
||||
if (!done) { printf("\n"); }
|
||||
done = true;
|
||||
}
|
||||
|
||||
void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
@@ -252,7 +251,7 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
stbtt_fontinfo info = { 0 };
|
||||
stbtt_InitFont(&info, font_data.data, 0);
|
||||
|
||||
F32 scale = stbtt_ScaleForPixelHeight(&info, 20);
|
||||
F32 scale = stbtt_ScaleForPixelHeight(&info, 256);
|
||||
|
||||
U32 w = 512;
|
||||
U32 h = 512;
|
||||
@@ -268,14 +267,12 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
|
||||
D_Font *font = M_ArenaPush(draw->arena, D_Font);
|
||||
|
||||
font->px = size;
|
||||
|
||||
S32 asc, desc, line;
|
||||
stbtt_GetFontVMetrics(&info, &asc, &desc, &line);
|
||||
|
||||
font->line_advance = cast(F32) line;
|
||||
font->ascent = cast(F32) asc;
|
||||
font->descent = cast(F32) desc;
|
||||
font->line_advance = cast(F32) (scale * line);
|
||||
font->ascent = cast(F32) (scale * asc);
|
||||
font->descent = cast(F32) (scale * desc);
|
||||
|
||||
font->glyphs = M_ArenaPush(draw->arena, D_Glyph, .count = count);
|
||||
|
||||
@@ -286,10 +283,14 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
S32 left, width;
|
||||
stbtt_GetCodepointHMetrics(&info, ' ' + it, &width, &left);
|
||||
|
||||
glyph->box = R2F(V2F(chr->x0 / (F32) w, chr->y0 / (F32) h), V2F(chr->x1 / (F32) w, chr->y1 / (F32) h));
|
||||
glyph->box.min = V2F(chr->x0 / (F32) w, chr->y0 / (F32) h);
|
||||
glyph->box.max = V2F(chr->x1 / (F32) w, chr->y1 / (F32) h);
|
||||
|
||||
glyph->advance = glyph->box.max.x - glyph->box.min.x; //chr->xadvance * scale;
|
||||
glyph->offset = V2F(chr->xoff * scale, chr->yoff * scale);
|
||||
glyph->advance = chr->xadvance;
|
||||
glyph->dim.w = cast(F32) (chr->x1 - chr->x0);
|
||||
glyph->dim.h = cast(F32) (chr->y1 - chr->y0);
|
||||
glyph->offset.x = (0.5f * glyph->dim.w) + chr->xoff;
|
||||
glyph->offset.y = (0.5f * glyph->dim.h) + chr->yoff;
|
||||
}
|
||||
|
||||
Vk_Buffer *staging = &draw->staging;
|
||||
@@ -302,6 +303,8 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
|
||||
Vk_CommandBuffer *cmds = Vk_CommandBufferPush();
|
||||
|
||||
font->id = draw->n_images + draw->n_fonts;
|
||||
|
||||
font->image.width = w;
|
||||
font->image.height = h;
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
typedef struct D_Glyph D_Glyph;
|
||||
struct D_Glyph {
|
||||
F32 advance;
|
||||
|
||||
V2f offset;
|
||||
V2f dim;
|
||||
|
||||
R2f box;
|
||||
};
|
||||
|
||||
@@ -14,13 +17,13 @@ typedef struct D_Font D_Font;
|
||||
struct D_Font {
|
||||
D_Font *next;
|
||||
|
||||
F32 px;
|
||||
U32 id;
|
||||
|
||||
F32 line_advance;
|
||||
F32 ascent;
|
||||
F32 descent;
|
||||
|
||||
F32 *kerning;
|
||||
F32 *kerning; // @incomplete: we don't load this
|
||||
D_Glyph *glyphs;
|
||||
|
||||
Vk_Image image;
|
||||
@@ -108,6 +111,8 @@ enum D_RectFlags {
|
||||
D_RECT_IGNORE_ASPECT = (1 << 0), // by default only width is used as a "dimension"
|
||||
D_RECT_PER_VERTEX_COLOUR = (1 << 1), // split colours per vertex
|
||||
D_RECT_UV_ASPECT = (1 << 2), // get the aspect from the uv rect rather than the full image
|
||||
D_RECT_FLIP_X = (1 << 3),
|
||||
D_RECT_FLIP_Y = (1 << 4)
|
||||
};
|
||||
|
||||
typedef struct D_RectOpts D_RectOpts;
|
||||
|
||||
Reference in New Issue
Block a user