Skip to content

Text Rendering In UEFI GOP #800

@vengestone-dragoon

Description

@vengestone-dragoon

im not sure if this is the correct place. i also am not sure if this is a bug with embedded-graphics or embedded-graphics-gop. my guess would be that its an issue with embedded-graphics-gop.
regardless of what i have tried, i cannot see text rendered to the display buffer. i have hunted around and found nothing other than what i have should work, but isn't working.

I am compiling for x86_64-unknown-uefi, and can confirm that the program runs both in a vm and on real hardware, with the same issues on both.
this is my text rendering code:

    let character_style = MonoTextStyle::new(&FONT_6X10, Rgb888::new(255, 255, 255)); 
    let text_style = TextStyleBuilder::new().line_height(LineHeight::Pixels(50)).build();

    Text::with_text_style(
        "Hello, UEFI!",
        Point::new(50, 150), 
        character_style,
        text_style,
    )
        .draw(&mut display)
        .unwrap();
    display.commit().unwrap();

Embedded-graphics-gop implements the display trait, and work for rendering shapes, but text and bmp images is not working for me.
Any help either getting this to actually work or identifying the actual problem would be apreciated.
here is my full code:

#![no_main]
#![no_std]

use core::time::Duration;
use log::info;
use uefi::prelude::*;
use uefi::proto::console::gop::GraphicsOutput;
use uefi::allocator::Allocator;

use embedded_graphics_gop::*;
use embedded_graphics::{
    mono_font::{ascii::FONT_6X10, MonoTextStyle},
    pixelcolor::Rgb888,
    prelude::*,
    primitives::{Circle, PrimitiveStyle, Rectangle},
    text::Text,
    text::TextStyleBuilder,
};
use embedded_canvas::*;
use embedded_graphics::text::LineHeight;
use embedded_layout::prelude::*;
use tinybmp::*;


#[global_allocator]
static ALLOCATOR: Allocator = Allocator;


#[entry]
fn main() -> Status {
    uefi::helpers::init().unwrap();
    info!("Hello world!");

    let gop_handle = boot::get_handle_for_protocol::<GraphicsOutput>()
        .expect("Failed to get GOP handle");

    let mut gop = boot::open_protocol_exclusive::<GraphicsOutput>(gop_handle)
        .expect("Failed to open GOP");

    let mut display =  BltDrawTarget::new(&mut gop).unwrap();
    display.double_buffer(true).unwrap();

    
    display.clear(Rgb888::BLACK).unwrap();
    display.commit().unwrap();

    
    Rectangle::new(Point::new(50, 50), Size::new(50, 50))
        .into_styled(PrimitiveStyle::with_stroke(Rgb888::RED, 5))
        .draw(&mut display)
        .unwrap();
    display.commit().unwrap();
    
    Circle::new(Point::new(53, 53), 44)
        .into_styled(PrimitiveStyle::with_fill(Rgb888::BLUE))
        .draw(&mut display)
        .unwrap();
    display.commit().unwrap();
    

    let character_style = MonoTextStyle::new(&FONT_6X10, Rgb888::new(255, 255, 255)); 
    let text_style = TextStyleBuilder::new().line_height(LineHeight::Pixels(50)).build();

    Text::with_text_style(
        "Hello, UEFI!",
        Point::new(50, 150), 
        character_style,
        text_style,
    )
        .draw(&mut display)
        .unwrap();
    display.commit().unwrap();

    let bmp_data = [
        0x42, 0x4D, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28,
        0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00,
        0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00,
    ];

    if let Ok(bmp) = Bmp::<Rgb888>::from_slice(&bmp_data) {
        bmp.draw(&mut display.translated(Point::new(50, 150)))
            .unwrap();
    }
    display.commit().unwrap();
    boot::stall(Duration::from_secs(10));
    Status::SUCCESS
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions