mirror of
https://github.com/lisk77/comet.git
synced 2025-12-16 02:28:49 +00:00
feat: ttf fonts are now loadable
This commit is contained in:
parent
9e16179df3
commit
0507703284
4 changed files with 136 additions and 54 deletions
|
|
@ -4,12 +4,14 @@ use std::{
|
|||
|
||||
use wgpu::{naga, Device, FilterMode, Queue, ShaderModule, TextureFormat, TextureUsages};
|
||||
use wgpu::naga::ShaderStage;
|
||||
use comet_log::info;
|
||||
use crate::{font, texture, Texture};
|
||||
use crate::font::Font;
|
||||
use crate::texture_atlas::{TextureAtlas, TextureRegion};
|
||||
|
||||
pub struct GraphicResourceManager {
|
||||
texture_atlas: TextureAtlas,
|
||||
fonts: HashMap<String, TextureAtlas>,
|
||||
fonts: Vec<Font>,
|
||||
data_files: HashMap<String, String>,
|
||||
shaders: HashMap<String, ShaderModule>
|
||||
}
|
||||
|
|
@ -18,7 +20,7 @@ impl GraphicResourceManager {
|
|||
pub fn new() -> Self {
|
||||
Self {
|
||||
texture_atlas: TextureAtlas::empty(),
|
||||
fonts: HashMap::new(),
|
||||
fonts: Vec::new(),
|
||||
data_files: HashMap::new(),
|
||||
shaders: HashMap::new()
|
||||
}
|
||||
|
|
@ -36,6 +38,14 @@ impl GraphicResourceManager {
|
|||
&self.data_files
|
||||
}
|
||||
|
||||
pub fn fonts(&self) -> &Vec<Font> {
|
||||
&self.fonts
|
||||
}
|
||||
|
||||
pub fn get_glyph(&self, font: &str, ch: char) -> Option<&TextureRegion> {
|
||||
self.fonts.iter().find(|f| f.name() == font).and_then(|f| f.get_glyph(ch))
|
||||
}
|
||||
|
||||
pub fn set_texture_atlas(&mut self, texture_atlas: TextureAtlas) {
|
||||
self.texture_atlas = texture_atlas;
|
||||
|
||||
|
|
@ -122,9 +132,10 @@ impl GraphicResourceManager {
|
|||
}
|
||||
|
||||
pub fn load_font(&mut self, path: &str, size: f32) {
|
||||
let font = font::Font::new(path, size);
|
||||
let atlas = TextureAtlas::from_textures(font.glyphs(), font.names());
|
||||
self.fonts.insert(font.name().to_string(), atlas);
|
||||
info!("Loading font: {}", path);
|
||||
let font = Font::new(path, size);
|
||||
info!("Font {} loaded!", font.name());
|
||||
self.fonts.push(font);
|
||||
}
|
||||
|
||||
/*pub async fn load_model(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue