flat assembler
Message board for the users of flat assembler.

Index > Linux > drawing in linux gui?

Author
Thread Post new topic Reply to topic
ginere



Joined: 15 Oct 2017
Posts: 13
ginere 19 Mar 2019, 22:04
What do you guys use to draw gui in assembly (64bit linux)?

I use SDL but dislike needing it to link to c library. Is there a pure assembly lib or something to draw in X?
Post 19 Mar 2019, 22:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20481
Location: In your JS exploiting you and your system
revolution 19 Mar 2019, 22:24
If you want to use the "standard" decorations that follow the user's preferences then using the lib is certainly the easiest path.

But it is also possible to use assembly to interact with X, the DRI driver, or the frame buffer..
Post 19 Mar 2019, 22:24
View user's profile Send private message Visit poster's website Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 14 Oct 2021, 11:34
I don't see any colors by typing the following command by @revolution :

Code:
dd if=/dev/urandom of=/dev/fb0 bs=4096 count=10        


As a beginner, how do I display a GUI message box like that from Windows , on Linux?


Description: How to display a simple message box like this on Linux?
Filesize: 4.41 KB
Viewed: 14104 Time(s)

Screenshot from 2021-10-14 19-29-32.png


Description: Unfortunately " Dialog" package is not GUI
Filesize: 18.68 KB
Viewed: 14104 Time(s)

Screenshot from 2021-10-14 19-26-09.png


Post 14 Oct 2021, 11:34
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1051
Location: Russia
macomics 14 Oct 2021, 13:34
ginere wrote:
I use SDL but dislike needing it to link to c library. Is there a pure assembly lib or something to draw in X?
I'm afraid you can't do without interacting with functions written in C. Most graphics libraries provide just such an interface.
FlierMate wrote:
Code:
dd if=/dev/urandom of=/dev/fb0 bs=4096 count=10    
It's just that the video buffer is redrawn by another process at a higher speed.

FlierMate wrote:
As a beginner, how do I display a GUI message box like that from Windows , on Linux?

There are only 3 elements in the dialog box. What prevents them from just drawing. But the choice of how to do it is entirely your task. Unlike Windows, in Linux, the GUI is an add-on. And at what level to interact with it is entirely your choice.
Quote:
Image
Post 14 Oct 2021, 13:34
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 14 Oct 2021, 14:20
I am much interested in the direct video rendering, or frame buffer instead of X11.... Razz

Running the following command succeeded:
Code:
cp /dev/fb0 myfile    


....but the hexdump of myfile is full of 4MB of following:
Code:
00000000  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000010  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000020  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000030  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000040  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000050  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000060  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000070  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000080  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000090  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
000000A0  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
000000B0  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
000000C0  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
000000D0  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
000000E0  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
000000F0  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................
00000100  00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00   ................    


This is the output after running @revolution's code:
Code:
boo@debian:~/fasm$ ./fasm.x64 ~/x.asm
flat assembler  version 1.73.28  (16384 kilobytes memory, x64)
4 passes, 1384 bytes.
boo@debian:~/fasm$ cd ..
boo@debian:~$ ./x
Open /dev/fb0 okay (3)
Read fb_fix_screeninfo okay
Read fb_var_screeninfo okay
frame buff  0
frame len   4325376
mem start   0
mem len     0
line length 5632
x visible   1366
y visible   768
x virtual   1366
y virtual   768
x offset    0
y offset    0
pixel bits  32
Everything is okay
boo@debian:~$ 
    


Noted the 1366x768 (32-bit ARGB) screen resolution.

Am I missing anything because I don't see colors on screen nor I see any captured graphics pattern in "myfile".

Thanks @macomics for the helpful introduction, so now I know X11 is the display server API.
Post 14 Oct 2021, 14:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20481
Location: In your JS exploiting you and your system
revolution 14 Oct 2021, 14:26
You probably need to be in virtual console display mode.

If you see the X windowing then fb0 is not active so the output is not being displayed.

On my system I can use CTRL-ALT-F1 to open a virtual console. Then fb0 is active.
Post 14 Oct 2021, 14:26
View user's profile Send private message Visit poster's website Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 14 Oct 2021, 14:45
revolution wrote:
You probably need to be in virtual console display mode.

If you see the X windowing then fb0 is not active so the output is not being displayed.

On my system I can use CTRL-ALT-F1 to open a virtual console. Then fb0 is active.


You're right, on Debian 11 (my system), I press Ctrl-Alt-F3 for virtual console. And then Ctrl+Alt+F2 to return to desktop screen.

I managed to convert portion of raw image (screenshot) of /dev/fb0 while I was at virtual console, to JPG, using online converter. (Edit: I think that is a wrong image, but they look similar anyway Surprised )

Thanks for pointing at the right direction! [/b]


Description: Yes, I get random colors!
Filesize: 43.38 KB
Viewed: 14068 Time(s)

fb.jpg


Post 14 Oct 2021, 14:45
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 14 Oct 2021, 17:04
So this is it!

Using a utility called fbgrab: https://github.com/GunnarMonell/fbgrab

Credit: angch (not on this forum)


Description: Screenshot from frame buffer
Filesize: 408.56 KB
Viewed: 14057 Time(s)

fb.png


Post 14 Oct 2021, 17:04
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 759
Ali.Z 14 Oct 2021, 21:00
FlierMate wrote:
You're right, on Debian 11 (my system), I press Ctrl-Alt-F3 for virtual console. And then Ctrl+Alt+F2 to return to desktop screen.


I think something is wrong with your installation, unless you changed some of config files.
by default debian assign tty7 (ctrl-alt-f7) to whatever desktop environment installed, and tty1-tty6 just plain console. Rolling Eyes

_________________
Asm For Wise Humans
Post 14 Oct 2021, 21:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20481
Location: In your JS exploiting you and your system
revolution 14 Oct 2021, 21:08
FlierMate wrote:
Using a utility called fbgrab: https://github.com/GunnarMonell/fbgrab
You don't need any fancy tools.

dd can copy /dev/fb0 to a file.
Code:
dd if=/dev/fb0 of=/path/to/file bs=4096 count=10    
Post 14 Oct 2021, 21:08
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1051
Location: Russia
macomics 14 Oct 2021, 22:11
revolution wrote:
You don't need any fancy tools.
This utility seems to form an image file from the data immediately. I suspect that it is necessary to say about the very basics. You have all the help built into the operating system. Try each of these commands, for example:
Code:
man dd
info X    
Post 14 Oct 2021, 22:11
View user's profile Send private message Reply with quote
st



Joined: 12 Jul 2019
Posts: 49
Location: Russia
st 16 Oct 2021, 14:16
macomics wrote:
I'm afraid you can't do without interacting with functions written in C. Most graphics libraries provide just such an interface.

Perhaps it is possible to connect (via sys_connect) to "wayland-0" or X's socket but that would be reinventing libwayland-client.so or libxcb.so.
Post 16 Oct 2021, 14:16
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1051
Location: Russia
macomics 16 Oct 2021, 15:56
st wrote:
Perhaps it is possible to connect (via sys_connect) to "wayland-0" or X's socket but that would be reinventing libwayland-client.so or libxcb.so.

So if you really want to, then you can slurp soup with a fork.
Post 16 Oct 2021, 15:56
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2582
Furs 17 Oct 2021, 19:03
st wrote:
macomics wrote:
I'm afraid you can't do without interacting with functions written in C. Most graphics libraries provide just such an interface.

Perhaps it is possible to connect (via sys_connect) to "wayland-0" or X's socket but that would be reinventing libwayland-client.so or libxcb.so.
I mean they are open source. Nothing special or magical.
Post 17 Oct 2021, 19:03
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 07 Feb 2022, 16:49
I would like to make a screen capture utility for text mode console window, but am not sure how?
(It is like what asciinema is doing, but mine is static, not animated)

There are fb, tty, vcs, and ncurses. I don't want the complete GUI, just the characters and colors.

From what I understand, ANSI escape code can define output colors, and get / set cursor position, it seems like no way for me to read the screen buffer (text mode).

Any idea?
Post 07 Feb 2022, 16:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20481
Location: In your JS exploiting you and your system
revolution 07 Feb 2022, 16:54
The screen buffer isn't in text mode, it uses graphics mode. So you only see the colour pixels in the screen memory. You could use an OCR to convert the pixels back to text. Or if you know the font then simply match each rectangle to each character to convert.

You will need to query the application directly to discover the internal text it keeps in its internal buffers.
Post 07 Feb 2022, 16:54
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 472
Location: Marseille/France
sylware 09 Feb 2022, 12:48
You should use wayland and not x11.

That said, drawing the GUI controls is actually the ez part of a GFX toolkit.
The real hard parts are:
- rendering font glyphs. It is vector rendering in C89 with benign bits of C99 done by the amazing freetype libs (hope it resists the extremely expensive languages with their insane compilers kludgyfication/sabotage train).
- text shapping. It is built on top of glyph font rendering. It will properly "assemble" rendered glyphs based on a unicode string. The only implementations are m17 in C (but it may be limited to few unicode scripts, did not check lately), harfbuzz which is a text book example why c++ is toxic as f**** (I know because I did a roman script only port of it in C of its previous C interface), and there was an equivalent in C of harfbuzz, then it was sabotaged/trashed with c++, then not point to look at it anymore (ICU was its name I think).

Some countries are doing better than all of that. Thailand has a very complexe script, then their gov is maintaining a lean C text shaper for their script: libthai.
Post 09 Feb 2022, 12:48
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2582
Furs 09 Feb 2022, 13:09
sylware wrote:
You should use wayland and not x11.
Hard disagree, don't listen to this advice. Wayland is a locked down mistake.
Post 09 Feb 2022, 13:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.