diff --git a/src/gfx/Text.zig b/src/gfx/Text.zig index ccbf77ec..b4db3ffd 100644 --- a/src/gfx/Text.zig +++ b/src/gfx/Text.zig @@ -209,10 +209,10 @@ fn updatePipeline( // defer font.deinit(allocator); const font_size = text_style.get(style, .font_size).?; + const font_color = text_style.get(style, .font_color) orelse vec4(0, 0, 0, 1.0); // TODO(text): respect these style parameters // const font_weight = text_style.get(style, .font_weight).?; // const italic = text_style.get(style, .italic).?; - // const color = text_style.get(style, .color).?; // Create a text shaper var run = try gfx.TextRun.init(); @@ -274,6 +274,7 @@ fn updatePipeline( .size = size.divScalar(px_density), .text_index = num_texts, .uv_pos = vec2(@floatFromInt(r.x), @floatFromInt(r.y)), + .font_color = font_color, }); origin_x += glyph.advance.x(); } diff --git a/src/gfx/TextPipeline.zig b/src/gfx/TextPipeline.zig index 7f7713cc..3351c805 100644 --- a/src/gfx/TextPipeline.zig +++ b/src/gfx/TextPipeline.zig @@ -107,6 +107,9 @@ pub const Glyph = extern struct { /// Which text this glyph belongs to; this is the index for transforms[i], colors[i]. text_index: u32, + + /// Color of the glyph + color: math.Vec4, }; const GlyphKey = struct { diff --git a/src/gfx/TextStyle.zig b/src/gfx/TextStyle.zig index a73979a8..0252e804 100644 --- a/src/gfx/TextStyle.zig +++ b/src/gfx/TextStyle.zig @@ -11,10 +11,9 @@ pub const components = .{ // \\ TODO(text): this is not currently implemented // }, - // e.g. 12 * mach.gfx.px_per_pt // 12pt .font_size = .{ .type = f32, .description = \\ Font size in pixels - \\ TODO(text): this is not currently implemented + \\ e.g. 12 * mach.gfx.px_per_pt for 12pt font size }, // // e.g. mach.gfx.font_weight_normal @@ -29,11 +28,11 @@ pub const components = .{ // \\ TODO(text): this is not currently implemented // }, - // // e.g. vec4(0, 0, 0, 1.0) - // .color = .{ .type = math.Vec4, .description = - // \\ Fill color - // \\ TODO(text): this is not currently implemented - // }, + .font_color = .{ .type = math.Vec4, .description = + \\ Fill color of text + \\ e.g. vec4(0.0, 0.0, 0.0, 1.0) // black + \\ e.g. vec4(1.0, 1.0, 1.0, 1.0) // white + }, // TODO(text): allow user to specify projection matrix (3d-space flat text etc.) }; diff --git a/src/gfx/text.wgsl b/src/gfx/text.wgsl index e9b34f07..ec5fe35c 100644 --- a/src/gfx/text.wgsl +++ b/src/gfx/text.wgsl @@ -7,6 +7,9 @@ struct VertexOutput { // UV coordinate @location(0) fragUV : vec2, + + // Color of the glyph + @location(1) color : vec4, }; // Our vertex shader will recieve these parameters @@ -30,6 +33,9 @@ struct Glyph { // Which text this glyph belongs to; this is the index for transforms[i], colors[i] text_index: u32, + + // Color of the glyph + color: vec4, } @group(0) @binding(0) var uniforms : Uniforms; @@ -96,10 +102,11 @@ fn vertMain( @fragment fn fragMain( @location(0) fragUV: vec2 + @location(1) color: vec4 ) -> @location(0) vec4 { var c = textureSample(glyphTexture, glyphSampler, fragUV); if (c.a <= 0.0) { discard; } - return c; + return c * color; } \ No newline at end of file