Browse Source

Fix bugs

master
Jens Pitkänen 1 year ago
parent
commit
e0adc32231
6 changed files with 31 additions and 20 deletions
  1. +3
    -2
      examples/sdl.rs
  2. +7
    -3
      src/api/graphics_context.rs
  3. +5
    -3
      src/renderer.rs
  4. +5
    -2
      src/text/fonts/rusttype.rs
  5. +9
    -8
      src/text/glyph_cache.rs
  6. +2
    -2
      src/text/mod.rs

+ 3
- 2
examples/sdl.rs View File

@ -35,8 +35,9 @@ fn main() {
break 'game_loop;
}
Event::Window { win_event, .. } => match win_event {
WindowEvent::SizeChanged(width, height) => unsafe {
fae::gl::Viewport(0, 0, width, height);
WindowEvent::Resized(_, _) => unsafe {
let (width, height) = window.drawable_size();
fae::gl::Viewport(0, 0, width as i32, height as i32);
},
_ => {}
},


+ 7
- 3
src/api/graphics_context.rs View File

@ -113,7 +113,11 @@ impl Context {
}
}
/// Renders the frame with the given `width` and `height`.
/// Renders the frame with the given `width`, `height` and
/// `clear_color`.
///
/// The `clear_color` is defined between 0.0 and 1.0, and the
/// components are (red, green, blue, alpha).
///
/// See
/// [`Context::start_frame`](struct.Context.html#method.start_frame)
@ -123,8 +127,8 @@ impl Context {
/// This should generally be called after
/// [`GraphicsContext::finish_frame`](struct.GraphicsContext.html#method.finish_frame),
/// but can also be used to redraw the previous frame.
pub fn render(&mut self, width: f32, height: f32) {
self.renderer.render(width, height);
pub fn render(&mut self, width: f32, height: f32, clear_color: (f32, f32, f32, f32)) {
self.renderer.render(width, height, clear_color);
}
}


+ 5
- 3
src/renderer.rs View File

@ -276,7 +276,7 @@ impl Renderer {
}
/// Renders the queued draws.
pub(crate) fn render(&mut self, width: f32, height: f32) {
pub(crate) fn render(&mut self, width: f32, height: f32, clear_color: (f32, f32, f32, f32)) {
let m00 = 2.0 / width;
let m11 = -2.0 / height;
let matrix = [
@ -288,7 +288,7 @@ impl Renderer {
}
unsafe {
gl::ClearColor(1.0, 1.0, 1.0, 1.0);
gl::ClearColor(clear_color.0, clear_color.1, clear_color.2, clear_color.3);
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
}
@ -503,7 +503,9 @@ impl Renderer {
new_height: i32,
) -> bool {
let (old_width, old_height) = self.calls[call.index].texture_size;
if new_width >= old_width && new_height >= old_height {
if self.legacy {
false
} else if new_width >= old_width && new_height >= old_height {
resize_texture(
&self.calls[call.index].texture,
old_width,


+ 5
- 2
src/text/fonts/rusttype.rs View File

@ -173,6 +173,9 @@ fn get_font_name(font: &Font) -> String {
})
.collect::<Vec<(&str, u16)>>();
font_name_parts.dedup_by(|(_, a), (_, b)| a == b);
debug_assert!(font_name_parts.len() == 1);
font_name_parts[0].0.to_string()
if font_name_parts.len() > 0 {
font_name_parts[0].0.to_string()
} else {
"<font name not found>".to_owned()
}
}

+ 9
- 8
src/text/glyph_cache.rs View File

@ -28,15 +28,16 @@ pub(crate) struct GlyphCache {
}
impl GlyphCache {
pub fn new(renderer: &mut Renderer, width: i32, height: i32, smoothed: bool) -> GlyphCache {
pub fn new(renderer: &mut Renderer, smoothed: bool) -> GlyphCache {
let mut max_size = 0 as GLint;
unsafe { gl::GetIntegerv(gl::MAX_TEXTURE_SIZE, &mut max_size) };
let size = if renderer.legacy {
max_size
} else {
64.min(max_size)
};
let cache_image = Image::with_null_texture(
(width as i32).min(max_size),
(height as i32).min(max_size),
gl::RED,
);
let cache_image = Image::with_null_texture(size, size, gl::RED);
let mut shaders = Shaders::default();
shaders.shader_110.fragment_shader = TEXT_FRAGMENT_SHADER_110.to_string();
@ -55,8 +56,8 @@ impl GlyphCache {
);
let cache = GlyphCache {
call,
width,
height,
width: size,
height: size,
max_size,
column_cursor: GLYPH_CACHE_GAP,
columns: Vec::with_capacity(1),


+ 2
- 2
src/text/mod.rs View File

@ -44,7 +44,7 @@ pub(crate) struct TextRenderer {
impl TextRenderer {
#[cfg(feature = "font8x8")]
pub(crate) fn with_font8x8(renderer: &mut Renderer, smoothed: bool) -> TextRenderer {
let cache = GlyphCache::new(renderer, 64, 64, smoothed);
let cache = GlyphCache::new(renderer, smoothed);
TextRenderer::with_params(cache, Box::new(fonts::Font8x8Provider::new()))
}
@ -53,7 +53,7 @@ impl TextRenderer {
renderer: &mut Renderer,
ttf_data: Vec<u8>,
) -> Result<TextRenderer, rusttype::Error> {
let cache = GlyphCache::new(renderer, 64, 64, true);
let cache = GlyphCache::new(renderer, true);
let font = Box::new(fonts::RustTypeProvider::new(ttf_data)?);
Ok(TextRenderer::with_params(cache, font))
}


Loading…
Cancel
Save