fix font alpha channel
This commit is contained in:
parent
bca29c537c
commit
2e60e4c5b8
16
TODO
16
TODO
@ -1,32 +1,38 @@
|
|||||||
# TODOs, semi-random sorting
|
# TODOs, semi-random sorting
|
||||||
|
|
||||||
[x] Implement glyph draw command
|
[x] Implement glyph draw command
|
||||||
[x] Implement div.view and scrollbars
|
[x] Implement div.view and scrollbars
|
||||||
[ ] Port font system from C to C3 (rewrite1)
|
[x] Port font system from C to C3 (rewrite1)
|
||||||
[ ] Update ARCHITECTURE.md
|
[ ] Update ARCHITECTURE.md
|
||||||
[ ] Write a README.md
|
[ ] Write a README.md
|
||||||
[ ] Use an arena allocator for cache
|
[ ] Use an arena allocator for cache
|
||||||
[ ] Do not redraw if there was no update (no layout and no draw)
|
[ ] Do not redraw if there was no update (no layout and no draw)
|
||||||
[ ] Better handling of the active and focused widgets, try
|
[ ] Better handling of the active and focused widgets, try
|
||||||
to maintain focus until mouse release (fix scroll bars)
|
to maintain focus until mouse release (fix scroll bars)
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
[x] rect commads should have:
|
[x] rect commads should have:
|
||||||
* border width
|
_ border width
|
||||||
* border radius
|
_ border radius
|
||||||
[x] add a command to update an atlas
|
[x] add a command to update an atlas
|
||||||
|
|
||||||
## Atlases
|
## Atlases
|
||||||
|
|
||||||
[ ] Add an interface to create, destroy, update and get atlases based on their ids
|
[ ] Add an interface to create, destroy, update and get atlases based on their ids
|
||||||
[ ] Implement multiple font atlases
|
[ ] Implement multiple font atlases
|
||||||
|
|
||||||
## Fonts
|
## Fonts
|
||||||
[ ] Fix the missing alpha channel
|
|
||||||
|
[x] Fix the missing alpha channel
|
||||||
[x] Fix the alignment
|
[x] Fix the alignment
|
||||||
|
|
||||||
## Raylib
|
## Raylib
|
||||||
|
|
||||||
[ ] Implement type (Rect, Color, Point) conversion functions between rl:: and ugui::
|
[ ] Implement type (Rect, Color, Point) conversion functions between rl:: and ugui::
|
||||||
[x] Implement pixel radius rounding for border radius
|
[x] Implement pixel radius rounding for border radius
|
||||||
|
|
||||||
## Widgets
|
## Widgets
|
||||||
|
|
||||||
[ ] Dynamic text box to implement an fps counter
|
[ ] Dynamic text box to implement an fps counter
|
||||||
[ ] Button with label
|
[ ] Button with label
|
||||||
|
26
src/main.c3
26
src/main.c3
@ -23,6 +23,28 @@ fn void Times.print_stats(×)
|
|||||||
io::printfn("min=%s, max=%s, avg=%s", min, max, avg);
|
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)
|
fn int main(String[] args)
|
||||||
{
|
{
|
||||||
ugui::Ctx ui;
|
ugui::Ctx ui;
|
||||||
@ -42,6 +64,7 @@ fn int main(String[] args)
|
|||||||
time::Clock clock;
|
time::Clock clock;
|
||||||
Times ui_times;
|
Times ui_times;
|
||||||
Times draw_times;
|
Times draw_times;
|
||||||
|
rl::Shader font_shader = rl::load_shader_from_memory(null, FONT_FS);
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!rl::window_should_close()) {
|
while (!rl::window_should_close()) {
|
||||||
@ -173,8 +196,9 @@ fn int main(String[] args)
|
|||||||
.x = cmd.sprite.rect.x,
|
.x = cmd.sprite.rect.x,
|
||||||
.y = cmd.sprite.rect.y,
|
.y = cmd.sprite.rect.y,
|
||||||
};
|
};
|
||||||
|
rl::begin_shader_mode(font_shader);
|
||||||
rl::draw_texture_rec(font_texture, source, position, rl::WHITE);
|
rl::draw_texture_rec(font_texture, source, position, rl::WHITE);
|
||||||
|
rl::end_shader_mode();
|
||||||
case ugui::CmdType.CMD_SCISSOR:
|
case ugui::CmdType.CMD_SCISSOR:
|
||||||
if (cmd.scissor.rect.w == 0 && cmd.scissor.rect.h == 0) {
|
if (cmd.scissor.rect.w == 0 && cmd.scissor.rect.h == 0) {
|
||||||
rl::end_scissor_mode();
|
rl::end_scissor_mode();
|
||||||
|
@ -61,7 +61,7 @@ struct Font {
|
|||||||
bool should_update; // should send update_atlas command, resets at frame_end()
|
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.table.new_init(capacity: FONT_CACHED);
|
||||||
font.id = name.hash();
|
font.id = name.hash();
|
||||||
@ -161,7 +161,7 @@ fn void Font.free(&font)
|
|||||||
schrift::freefont(font.sft.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);
|
return ctx.font.load(name, path, height, scale);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user