How can I write a RGBA color to a linear frame buffer?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

How can I write a RGBA color to a linear frame buffer?

Post 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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: How can I write a RGBA color to a linear frame buffer?

Post 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?
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: How can I write a RGBA color to a linear frame buffer?

Post 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 :lol:
If something looks overcomplicated, most likely it is.
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: How can I write a RGBA color to a linear frame buffer?

Post 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?
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: How can I write a RGBA color to a linear frame buffer?

Post 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
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: How can I write a RGBA color to a linear frame buffer?

Post 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.
Last edited by Schol-R-LEA on Thu Apr 30, 2020 1:24 pm, edited 1 time in total.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: How can I write a RGBA color to a linear frame buffer?

Post 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.
Post Reply