Page 1 of 1
How can I write a RGBA color to a linear frame buffer?
Posted: Wed Apr 29, 2020 4:55 pm
by mrjbom
Hi.
I'm trying to write a color with an alpha channel to LFB.
For example in my code I do this:
Code: Select all
put_pixel_lfb_mem(50, 20, 0xFFFFFF);
put_pixel_lfb_mem(51, 20, 0x3FFFFFFF);
I expect the pixels to have different colors. But they are exactly the same.
How can I draw pixels with an alpha channel?
Thanks.
Re: How can I write a RGBA color to a linear frame buffer?
Posted: Wed Apr 29, 2020 8:00 pm
by kzinti
mrjbom wrote:How can I draw pixels with an alpha channel?
You just did. But putting an alpha value in the framebuffer is not going to do anything.
What do you expect to happen? Why would the colour be different? What should it be?
Re: How can I write a RGBA color to a linear frame buffer?
Posted: Thu Apr 30, 2020 12:45 am
by Velko
kzinti wrote:What do you expect to happen? Why would the colour be different? What should it be?
You should be able to see what's behind the monitor, obviously
Re: How can I write a RGBA color to a linear frame buffer?
Posted: Thu Apr 30, 2020 6:21 am
by mrjbom
kzinti wrote:You just did. But putting an alpha value in the framebuffer is not going to do anything.
Well, how can I achieve a transparency effect?
Re: How can I write a RGBA color to a linear frame buffer?
Posted: Thu Apr 30, 2020 7:42 am
by BenLunt
mrjbom wrote:kzinti wrote:You just did. But putting an alpha value in the framebuffer is not going to do anything.
Well, how can I achieve a transparency effect?
You have to combine the two pixels yourself.
For example, even in 32-bit pixels, they are only 24-bits wide, eight each color. To create a transparent looking pixel, you have to read what is already there, then combine it with the new pixel and place it back.
Ben
-
http://www.fysnet.net/the_graphical_user_interface.htm
Re: How can I write a RGBA color to a linear frame buffer?
Posted: Thu Apr 30, 2020 1:13 pm
by Schol-R-LEA
If helps any for you when looking into how to do this, the usual terms for this are 'alpha blending' or '
alpha compositing'. Technically speaking, alpha blending is a particular type of alpha compositing, but you'll sometimes see it used for other types of alpha compositing. It is related to the broader topic of image compositing, as well as loosely related to the issue of texturing.
As Ben said, this is something you'd have to do in software, at least for a generic video framebuffer. While the current generation of GPUs used in PCs do have hardware compositing, you would need a hardware-specific driver to use that, and you'd want to have a software method as a fallback, so it makes more sense for most hobby OS devs to stick to that.
There are a number of different algorithms for different types of alpha compositing, and each has uses in different situations.
Can you give us some idea of what you are trying to accomplish? I think is smell an
XY problem in this, so more context is definitely called for.
Re: How can I write a RGBA color to a linear frame buffer?
Posted: Thu Apr 30, 2020 1:16 pm
by mrjbom
BenLunt wrote:mrjbom wrote:kzinti wrote:You just did. But putting an alpha value in the framebuffer is not going to do anything.
Well, how can I achieve a transparency effect?
You have to combine the two pixels yourself.
For example, even in 32-bit pixels, they are only 24-bits wide, eight each color. To create a transparent looking pixel, you have to read what is already there, then combine it with the new pixel and place it back.
Ben
-
http://www.fysnet.net/the_graphical_user_interface.htm
Yes, that's a good idea. I solved my problem, thank you.