Linux Framebuffer

Linux specific questions.
Roland007
Posts: 80
Joined: Oct 26, 2009 21:01

Linux Framebuffer

Postby Roland007 » Mar 18, 2020 14:01

Hi All,
There is something I try to understand.

I am trying to write a program that uses the framebuffer. Freebasic seems to support the framebuffer but how?
Each time I try to do something graphical, the compiler starts to complain that it needs libXPM (an X windows component). Including fbgfx.bi does not solve this issue.

So my questions are:
- Does it support the framebuffer in a way that you can use graphical primitives (draw, point, circle, draw string) and stuff like print?
- if yes, please show/tell me how.


Thanks!
badidea
Posts: 2079
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Linux Framebuffer

Postby badidea » Mar 18, 2020 20:45

After reading this Direct Rendering Infrastructure and this Direct Rendering Manager wikipedia article, I think that the term "the framebuffer" is a bit vague. No application (except the DRM) can (is allowed to) write to the video memory directly. If I understand correct, your application allocates memory in X pixmap format and you ask (via various freebasic graphics commands) the DRM to display that memory.

So no more peeking and poking in memory banks and possibly destroying cathode ray tubes :-)

But I am no expert in this, and I already read more than what I wanted to know on this subject.
Roland007
Posts: 80
Joined: Oct 26, 2009 21:01

Re: Linux Framebuffer

Postby Roland007 » Mar 18, 2020 22:17

badidea wrote:After reading this Direct Rendering Infrastructure and this Direct Rendering Manager wikipedia article, I think that the term "the framebuffer" is a bit vague. No application (except the DRM) can (is allowed to) write to the video memory directly. If I understand correct, your application allocates memory in X pixmap format and you ask (via various freebasic graphics commands) the DRM to display that memory.

So no more peeking and poking in memory banks and possibly destroying cathode ray tubes :-)

But I am no expert in this, and I already read more than what I wanted to know on this subject.

Its very simple: cat /dev/urandom > /dev/fb0 and there you have it. A screen filled with coloured pixels. So its not vague. Its a "kernel device" which connects to the screen memory being displayed. DRM and DRI are X windows related, they are the part I want to skip.
badidea
Posts: 2079
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Linux Framebuffer

Postby badidea » Mar 18, 2020 22:58

Freebasic documentation on framebuffer:
https://freebasic.net/wiki/wikka.php?wakka=GfxInternalFormats wrote:When a graphics mode is set via the Screen or ScreenRes functions, GfxLib creates also a framebuffer in standard system memory and sets an appropriate internal pixel format for the mode. There are basically three internal pixel formats, selected depending on the screen depth, as described in the following table: ...

All drawing operations work on this RAM framebuffer; when the actual display needs to be updated, GfxLib copies the contents of the framebuffer to the real display memory, automatically converting in the process from the current internal pixel format to whatever pixel format the real display uses. By limiting the internal pixel formats to 3, the library prevents you having to deal with the plethora of real display formats.

Via screencontrol you could try to set the driver FBDev, see: https://freebasic.net/wiki/wikka.php?wakka=GfxLib
But that does not seem to work here. It defaults to X11.
There is discussion of fbdev in viewtopic.php?f=5&t=24793&hilit=fbdev&start=90
Roland007
Posts: 80
Joined: Oct 26, 2009 21:01

Re: Linux Framebuffer

Postby Roland007 » Mar 19, 2020 8:22

Via screencontrol you could try to set the driver FBDev, see: https://freebasic.net/wiki/wikka.php?wakka=GfxLib
But that does not seem to work here. It defaults to X11.
There is discussion of fbdev in https://freebasic.net/forum/viewtopic.p ... v&start=90


Hi and thanks. I've found most of these threads on the forum and that's why I made a new post: hoping to get an answer from people that have code that works or wake-up the devs that should know its actually brolen. There is not actually a discussion: people conclude that its broken and move on. The developers do not reply to these subjects which implicitly declares this subject and functionality dead.Such is the case with free software, if a developer doesn't want to or can maintain code, it will die or become obsolete and mall-function. Nothing bad, that's just the way it is.
St_W
Posts: 1494
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Linux Framebuffer

Postby St_W » Mar 21, 2020 18:55

fbgfx supports the framebuffer device, however I don't think that you can create a fbgfx application with FreeBasic that does not depend on X libraries by default. If you run a fbgfx application not within a X environment but from a terminal it will use the framebuffer (if available). Unfortunately framebuffer support seems to get worse and worse on todays hardware and software - you can use the C snippet I wrote in this post to test whether your system supports the framebuffer device properly at all. Even on most embedded devices (that use some graphics) the framebuffer is not used anymore.
So how to use it: Just initialize graphics with SCREENRES and make sure the resolution and bit-depth match the framebuffer mode (run "fbset" to view current settings). Then you can use the build-in graphics commands like LINE, etc.
You need to have the required X libraries installed on the system, but X is not run/started. If you do not want or can (e.g. because of an embedded system with very limited resources) install X libraries you most likely have to build a custom version of fbgfx without X (DISABLE_X11, DISABLE_OPENGL) and link your application manually. Disclaimer: I haven't tried that and there may be a simpler solution.
D.J.Peters
Posts: 8038
Joined: May 28, 2005 3:28
Contact:

Re: Linux Framebuffer

Postby D.J.Peters » Mar 21, 2020 20:00

Tested on slackware (long time ago)

If your linux boot's with the frame buffer device enabled
(looks the same as a text mode but it's a gfx console often one penguin per core at top left)
then no Xlib are loaded or running any desktop manager
but i can use screenres and the frame buffer device is used for the gfx command's.

Joshy
St_W
Posts: 1494
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Linux Framebuffer

Postby St_W » Mar 21, 2020 23:25

Experimented a bit with different old and new Linux VMs: A current install of Debian 10 in VMware or VirtualBox provided a framebuffer device by default (no extra configuration necessary), but it always triggered errors (either app segfaulting or even kernel errors). An older Debian 8 install on VirtualBox didn't provide /dev/fb0 by default, but it could be activated using the steps below. Afterwards the applications using the framebuffer worked fine there (both the C code referred to in my previous post and a little FBgfx demo application).

Code: Select all

1) install v86d package

2) add uvesafb to initrd configuration:

# echo uvesafb >> /etc/initramfs-tools/modules

3) determine available video modes:

# modprobe uvesafb
# cat /sys/bus/platform/drivers/uvesafb/uvesafb.0/vbe_modes

4) configure uvesafb mode_option:

# echo options uvesafb mode_option=1024x768-32 scroll=ywrap > /etc/modprobe.d/uvesafb.conf

5) rebuild initrd:

# update-initramfs -k all -u

from: https://www.tapatalk.com/groups/refracta/framebuffer-t142.html
see also:
https://unix.stackexchange.com/questions/33596/no-framebuffer-device-how-to-enable-it
https://superuser.com/questions/143898/framebuffer-not-available-how-to-install-the-device-dev-fb-0-on-ubuntu

I'm not sure whether the code needs to be adjusted to work on Debian 10 or whether its fbdev implementation just doesn't work on VirtualBox/VMware - I won't take a deeper look now, but I'd be interested in case someone else does :-)
Roland007
Posts: 80
Joined: Oct 26, 2009 21:01

Re: Linux Framebuffer

Postby Roland007 » Mar 22, 2020 8:13

Thanks for your replies. The screen boots if FB mode. I discovered that I have a rights issue. The FB device needs root rights. So

Code: Select all

dim as integer X,Y,D
ScreenRes X,Y,D
Print X,Y,D
Sleep

gives as result
1024 768 32
after running with sudo. However graphical operatiions have no visible result.. So this code terminates with "Hello World!!"
If tried lines with colors like rgb(255,255,255) but got no results.

Code: Select all

screenres 1024,768,32

' Draw color bands in a diagonal pattern over the whole screen
For y As Integer = 0 To 200-1
    For x As Integer = 0 To 320-1
        PSet (x,y),(x + y) And 255
    Next x
Next y

' Display the text "Hello World!!" over the lines we've drawn, in the top-left hand corner
Print "Hello world!!"

' Keep the window open until the user presses a key
Sleep

Anyone got an idea where my dots have gone?
Thanks all!
D.J.Peters
Posts: 8038
Joined: May 28, 2005 3:28
Contact:

Re: Linux Framebuffer

Postby D.J.Peters » Mar 22, 2020 14:40

@Roland007 try this !

Joshy

Code: Select all

dim as integer iWidth,iHeight,iBits
screeninfo(iWidth,iHeight,iBits)
print iWidth,iHeight,iBits
 
if screenres(iWidth,iHeight,iBits) then
  print "error: screenres() !"
  beep: sleep: end 1
end if 

if iBits<15 then ' 8-bit palette
  For y As Integer = 0 To iHeight-1
    For x As Integer = 0 To iWidth-1
      PSet (x,y),(x + y) And 255
    Next x
  Next y
else
  For y As Integer = 0 To iHeight-1
    For x As Integer = 0 To iWidth-1
      PSet (x,y),RGB(rnd*255,rnd*255,rnd*255)
    Next x
  Next y
end if

draw string (0,0),"Hello world !"
Sleep

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 3 guests