summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bitmap.rs43
-rw-r--r--src/gl_renderer.rs50
2 files changed, 49 insertions, 44 deletions
diff --git a/src/bitmap.rs b/src/bitmap.rs
index d9ec391..120f9d1 100644
--- a/src/bitmap.rs
+++ b/src/bitmap.rs
@@ -186,7 +186,7 @@ impl BitmapManager {
if len < 16 {
bail!("ART does not contain a valid header.");
}
-
+
let mut data = Cursor::new(data);
let mut bitmaps = Vec::new();
@@ -334,6 +334,47 @@ impl BitmapManager {
}
}
+// FIXME: This documentation is bare and undescriptive.
+/// Loads a font blob into a Bitmap.
+pub fn load_font(font: &[u8]) -> Bitmap {
+ // TODO: There is no error checking, as I plan to dynamically generate a
+ // number of glyphs and appropriate dimensions from the size of 'data'.
+
+ // FIXME: Width and height constants are arbitrary and should ideally be
+ // dynamically calculated for a set of glyphs with arbitrary length.
+ let width = 128;
+ let height = 256;
+
+ let mut data = vec![0; height * width];
+
+ // FIXME: Again, this MAX_GLYPH, which isn't even referred to by a static
+ // constant, should be dynamically calculated.
+ for glyph in 0..256 {
+ let x_off = (glyph % 32) * 8;
+ let y_off = (glyph / 32) * 8;
+
+ for i in 0..8 {
+ for j in 0..8 {
+ let byte = font[(glyph * 8 + i) as usize];
+ let bit = 2 << (7 - j);
+
+ if byte & bit != 0 {
+ // The font files don't convey any color information, just
+ // the pixel that's set, so we default to a plain white.
+ let pixel = 0xffffffff;
+
+ let x = x_off + i;
+ let y = y_off + j;
+
+ data[x * width + y] = pixel;
+ }
+ }
+ }
+ }
+
+ Bitmap { width: width as u16, height: height as u16, data }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/gl_renderer.rs b/src/gl_renderer.rs
index bc38889..97ecc86 100644
--- a/src/gl_renderer.rs
+++ b/src/gl_renderer.rs
@@ -19,62 +19,26 @@ extern crate simple_error;
use std::error::Error;
-use bitmap::Bitmap;
+use bitmap::{Bitmap, load_font};
use grp::GroupManager;
/// Renderer using the OpenGL library.
pub struct GLRenderer;
impl GLRenderer {
+ /// Instantiate a new instance of the renderer.
pub fn new(groups: &GroupManager) -> Result<GLRenderer, Box<Error>> {
- let _font = GLRenderer::load_font(groups);
-
- Ok(GLRenderer { })
- }
-
- // TODO: Document this.
- // TODO: Wouldn't this make more sense in the 'bitmap' module?
- fn load_font(groups: &GroupManager) -> Result<Bitmap, Box<Error>> {
let tables = match groups.get("TABLES.DAT") {
Some(tables) => tables,
None => bail!("GRP does not contain a TABLES.DAT"),
};
- // <= ?
- if tables.len() < 7424 {
- bail!("TABLES.DAT does not contain a font.");
- }
-
- let font = &tables[5376..7424];
-
- let width = 128;
- let height = 256;
- let mut data = vec![0; height * width];
+ // TODO: Separate bitmaps for textfont and smalltextfont?
+ let data = &tables[5376..7424];
- // TODO: Replace '256' with a static 'MAX_GLYPH'.
- for glyph in 0..256 {
- let x_off = (glyph % 32) * 8;
- let y_off = (glyph / 32) * 8;
+ // TODO: The BitmapManager should maintain the font.
+ let _font: Bitmap = load_font(data);
- for i in 0..8 {
- for j in 0..8 {
- let byte = font[(glyph * 8 + i) as usize];
- let bit = 2 << (7 - j);
-
- if byte & bit != 0 {
- // The font doesn't carry any color information, it's
- // just white.
- let pixel = 0xffffffff;
-
- let x = x_off + i;
- let y = y_off + j;
-
- data[x * width + y] = pixel;
- }
- }
- }
- }
-
- Ok(Bitmap { width: width as u16, height: height as u16, data })
+ Ok(GLRenderer { })
}
}