fix font alpha channel

This commit is contained in:
Alessandro Mauri 2024-12-16 13:54:53 +01:00
parent bca29c537c
commit 2e60e4c5b8
3 changed files with 38 additions and 8 deletions

View file

@ -23,6 +23,28 @@ fn void Times.print_stats(&times)
io::printfn("min=%s, max=%s, avg=%s", min, max, avg);
}
const ZString FONT_FS = `
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Output fragment color
out vec4 finalColor;
void main()
{
vec4 alpha = texture(texture0, fragTexCoord);
finalColor = colDiffuse*fragColor;
finalColor.a *= alpha.r;
}
`;
fn int main(String[] args)
{
ugui::Ctx ui;
@ -42,6 +64,7 @@ fn int main(String[] args)
time::Clock clock;
Times ui_times;
Times draw_times;
rl::Shader font_shader = rl::load_shader_from_memory(null, FONT_FS);
// Main loop
while (!rl::window_should_close()) {
@ -173,8 +196,9 @@ fn int main(String[] args)
.x = cmd.sprite.rect.x,
.y = cmd.sprite.rect.y,
};
rl::begin_shader_mode(font_shader);
rl::draw_texture_rec(font_texture, source, position, rl::WHITE);
rl::end_shader_mode();
case ugui::CmdType.CMD_SCISSOR:
if (cmd.scissor.rect.w == 0 && cmd.scissor.rect.h == 0) {
rl::end_scissor_mode();

View file

@ -61,7 +61,7 @@ struct Font {
bool should_update; // should send update_atlas command, resets at frame_end()
}
fn void! Font.load(&font, String name, String path, uint height, float scale)
fn void! Font.load(&font, String name, ZString path, uint height, float scale)
{
font.table.new_init(capacity: FONT_CACHED);
font.id = name.hash();
@ -161,7 +161,7 @@ fn void Font.free(&font)
schrift::freefont(font.sft.font);
}
fn void! Ctx.load_font(&ctx, String name, String path, uint height, float scale = 1.0)
fn void! Ctx.load_font(&ctx, String name, ZString path, uint height, float scale = 1.0)
{
return ctx.font.load(name, path, height, scale);
}