rust-osdev / bootloader

An experimental pure-Rust x86 bootloader
Apache License 2.0
1.39k stars 213 forks source link

Framebuffer Unclear #187

Open tux7k opened 3 years ago

tux7k commented 3 years ago

I know it's possible to increase the brightness of pixels but how can you change the color, I see it's possible in logger.rs but way to hard to understand. Does anyone know how to use the framebuffer?

bjorn3 commented 3 years ago

With VGA text mode, the VGA bios is responsible for turning the color codes into full rgb colors. It seems to be possible to reconfigure this pallette using a specific port write: https://forum.osdev.org/viewtopic.php?f=1&t=23753

tux7k commented 3 years ago

idk if you understand but i'm talking about the uefi framebuffer in boot_info.rs not vga text mode

bjorn3 commented 3 years ago

I see. In that case I think changing the following two lines would be enough: https://github.com/rust-osdev/bootloader/blob/bc6c1bd62de697dc090ff8e7131cc36b91a531f4/src/binary/logger.rs#L130-L131

In the first case the array values are the red, green amd blue amount padded with a 0. In the second case it is first blue, then green, then red.

tux7k commented 3 years ago

how could i create a pixel though? that's more of what i'm asking about

bjorn3 commented 3 years ago

The code I referenced is what determines the color. The pixel is written at https://github.com/rust-osdev/bootloader/blob/bc6c1bd62de697dc090ff8e7131cc36b91a531f4/src/binary/logger.rs#L136-L137

The code is a bit harder to read due to the fact that bytes_per_pixel may differ depending on the exact format the pixel data is in (rgb,bgr,greyscale), but it basically writes the pixel data to the right offset in the framebuffer slice.

tux7k commented 3 years ago

so how could i adapt that code to buffer_mut() in boot_info.rs

ethindp commented 3 years ago

I think that somebody needs to create a dedicated guide about explaining this and how it works. Yeah, the OSDev folks have an article about it, but I don't think another would hurt, particularly related to this particular bootloader. It seems like I'm not the only one tripping up on this issue.

On 7/30/21, Exeon @.***> wrote:

so how could i adapt that code to buffer_mut() in boot_info.rs

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/rust-osdev/bootloader/issues/187#issuecomment-890014199

-- Signed, Ethin D. Probst

tux7k commented 3 years ago

I found out how you can get it to work. I think I'll document it somewhere

SpanishPear commented 2 years ago

@actuallyexeon did you manage to write up that document?

tux7k commented 2 years ago

@actuallyexeon did you manage to write up that document?

What do you mean by that?

SpanishPear commented 2 years ago

Ah I was referring to

I think I'll document that somewhere

Did you end up documenting it

tux7k commented 2 years ago

Ah I was referring to

I think I'll document that somewhere

Did you end up documenting it

No, but there is a piece of code by @anellie here that you can look at for reference https://github.com/anellie/yacuri/blob/main/kernel/src/graphics/mod.rs and you can also look at this https://github.com/cherrydevs/cherrykernel/blob/master/src/video/mod.rs that I made a while back using anellies code

SpanishPear commented 2 years ago

Thanks :partying_face:

asensio-project commented 2 years ago

I tried to change the pixel colour via changing: PixelFormat::BGR => [intensity / 2, intensity, intensity, 0] But I see the colour that I put but no letters only a big line. How can I fix it?