MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / draw_text_ex

Method draw_text_ex

native/shared/src/text_renderer.rs:247–309  ·  view source on GitHub ↗
(
        &mut self,
        renderer: &mut Renderer,
        font_idx: usize,
        text: &str,
        x: f64,
        y: f64,
        size: u32,
        spacing: f32,
        r: f64, g: f64, b: f

Source from the content-addressed store, hash-verified

245 }
246
247 pub fn draw_text_ex(
248 &mut self,
249 renderer: &mut Renderer,
250 font_idx: usize,
251 text: &str,
252 x: f64,
253 y: f64,
254 size: u32,
255 spacing: f32,
256 r: f64, g: f64, b: f64, a: f64,
257 ) {
258 let idx = if font_idx < self.fonts.len() { font_idx } else { 0 };
259
260 // Ensure all glyphs are rasterized first
261 for ch in text.chars() {
262 self.rasterize_glyph(idx, ch, size);
263 }
264
265 // Upload atlas if dirty
266 self.ensure_atlas_uploaded(renderer);
267
268 let atlas_bg = match self.atlas_bind_group_idx {
269 Some(idx) => idx,
270 None => return,
271 };
272
273 let color = [
274 (r / 255.0) as f32,
275 (g / 255.0) as f32,
276 (b / 255.0) as f32,
277 (a / 255.0) as f32,
278 ];
279
280 let aw = self.atlas_width as f32;
281 let ah = self.atlas_height as f32;
282
283 let mut cursor_x = x as f32;
284 let mut first = true;
285 for ch in text.chars() {
286 if !first && spacing != 0.0 {
287 cursor_x += spacing;
288 }
289 first = false;
290 let key = (idx, ch, size);
291 if let Some(glyph) = self.glyph_cache.get(&key) {
292 let gx = cursor_x + glyph.x_offset;
293 let gy = y as f32 - glyph.y_offset - glyph.height as f32 + size as f32;
294 let gw = glyph.width as f32;
295 let gh = glyph.height as f32;
296
297 if gw > 0.0 && gh > 0.0 {
298 let u0 = glyph.atlas_x as f32 / aw;
299 let v0 = glyph.atlas_y as f32 / ah;
300 let u1 = (glyph.atlas_x + glyph.width) as f32 / aw;
301 let v1 = (glyph.atlas_y + glyph.height) as f32 / ah;
302
303 renderer.draw_textured_quad(gx, gy, gw, gh, u0, v0, u1, v1, color, atlas_bg);
304 }

Callers 8

bloom_draw_text_exFunction · 0.80
bloom_draw_text_exFunction · 0.80
bloom_draw_text_exFunction · 0.80
bloom_draw_text_exFunction · 0.80
draw_textMethod · 0.80
bloom_draw_text_exFunction · 0.80
bloom_draw_text_ex_strFunction · 0.80
bloom_draw_text_exFunction · 0.80

Calls 4

rasterize_glyphMethod · 0.80
ensure_atlas_uploadedMethod · 0.80
draw_textured_quadMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected