Is it possible to access to the framebuffer in order to put a pixel on the screen from the command line?
yes, outside X-server, in tty, try command:
cat /dev/urandom >/dev/fb0
if colourfull pixels fills the screen, then your setup is ok, and you can try playing with this small script:
#!/usr/bin/env bash
fbdev=/dev/fb0 ; width=1280 ; bpp=4
color="\x00\x00\xFF\x00" #red colored
function pixel()
{ xx=$1 ; yy=$2
printf "$color" | dd bs=$bpp seek=$(($yy * $width + $xx)) \
of=$fbdev &>/dev/null
}
x=0 ; y=0 ; clear
for i in {1..500}; do
pixel $((x++)) $((y++))
done
where function 'pixel' should be an answer... write a pixel to screen by changing byte values (blue-green-red-alpha) on x-y offset of device /dev/fbX which is frame buffer for the video-card.
or try one liner pixel draw (yellow on x:y=200:100, if width is 1024):
printf "\x00\xFF\xFF\x00" | dd bs=4 seek=$((100 * 1024 + 200)) >/dev/fb0
UPDATE: this code works even inside X-server, if we just configure X to use frame buffer. by specifying fb0 inside /usr/share/X11/xorg.conf.d/99-fbdev.conf
Related videos on Youtube
Abdul Al Hazred
Updated on September 18, 2022Comments
-
Abdul Al Hazred over 1 year
I am not sure if it is the only possible way, but I read that in order to put a single pixel onto the screen at a location of your choice one has to write something into a place called framebuffer. So I became curious, if it is possible to enter into this place and write something into it in order to display a single pixel somewhere on the screen.
-
Admin about 9 yearsYou didn't specify which OS. Linux?
-
Admin about 9 yearsYes , Linux (mint codename rebecca)
-
Admin over 7 years
-
-
robert about 9 yearsThere's a couple of dangerous things going on here: the first example appears to write random bytes to a floppy disk, for some reason. The follow up commands use
dd
which has often been called "Disk Destroy" for specific reasons ... don't go near these commands unless you know what you're doing ... -
terdon about 9 years@robert I think Omar meant
/dev/fbX
and the/dev/fd
was just a typo. And yes,dd
is dangerous but so isrm
. That doesn't mean it shouldn't be used. It just means that it should be used with care. -
Abdul Al Hazred about 9 years"yes, outside X-server, in tty, try command:" I do not understand if I got it right, so I tried just opening the terminal and writing "cat /dev/urandom > /dev/fd0" but I only got an error message : "cat: write error: no space left on device". I really do not know how to get out of the xserver.
-
Asain Kujovic about 9 years... i called it tty, but it is virtual console, non-gui thing, terminal over all screen, that you reach with ctrl-alt-f1,2,3... or "sudo chvt 1" ... 'no space left' seems like it will be ok, just you are still in X-session.
-
Asain Kujovic over 7 years@sherrellbc, "no space left" is normal because random is infinite and screen has fixed number of WxH pixels... writing to FB do not work inside X because X uses some other lower level way of communication with video-card. There is also DRM, KMS... KODI for example uses OpenMax. FrameBuffer is just one of methods and not the lowest one.
-
Asain Kujovic over 7 years@sherrellbc, ... actually now i know that it can work easily inside X, your question leaded me to above 'update'.