Starting a graphical application using sfml on Raspberry Pi boot - arm

I would like to make a Graphical interface for a home-made program using SFML on Raspberry Pi2. I am using Raspbian. I recompiled the graphical lib
It works fine unsing startx first, then using my application, which wors perfectly fine.
But I can't figure if it is possible or how to launch my application directly after boot without launching startx (just to optimise the cpu of the Raspberry).
Starting my program direcly after boot, I get the following error:
Failed to open X11 display: make sure the DISPLAY environnement variable is set correctly.
Aborted.
I already tested the classic export DISPLAY=:0.0 but without sucess.
I interested myself in x and xinit, but I am not sure that would even do it.
Where should I start looking? I don't need a complete solution, even a hint or an idea would be nice!

I checked to see if it was possible to open a graphical app without the X desktop environment and as that answer states, with Firefox at least, you need the X server which SFML also probably needs in order to create a window.
The answer states:
Basically something like:
$ X
Then you just start Firefox in this X server:
$ DISPLAY=:0 firefox
You can switch from the X server and the framebuffer by using
CTRL+ALT+F1 and CTRL+ALT+F7.
You could try that and see if it helps.
Also, still searching, I found a forum post on the sfml website about what you're trying to accomplish stating somewhere:
SFML requires OpenGL, so as far as I know you need at least X running,
but you probably don't need gnome, KDE or a similar Desktop
Environment on top.
The forum guy asking for help seems to have managed to get X11 and a SFML basic render window to work on Ubuntu server after someone posted a link to xinitrc. I guess, that's the route to go from here.

Related

WebkitGtk application is not loading file URL

I am building a kiosk application using webkitgtk on the raspberry pi 4.
This application will not be connected to the internet and all the html,css, javascript for the UI are all located on the local filesystem.
I am using buildroot to setup the Linux system, starting with the pi 4 defconfig provided in buildroot.
I have enabled all the packages needed to get webkitgtk running.
Also, the kiosk application has been tested on my desktop, using the same software stack and it works
However, when i try to launch the application on the raspberry pi, a blank page pops up. I have played around with the WebKitWebSettings object associated with my WebKitWebView by enabling local file access. It still shows up a blank screen.
Also included in my pi4 application bundle is a simple gtk3+ application. This launches successfully!
I will really appreciate some pointers as to why this is happening as i have sort of reached a dead end
UPDATE
I enabled the MiniBrowser app that comes with the Webkitgtk package.
Entering the local url, The page does not load. It only gives me a message at the top saying "Successfully downloaded".
It seems to be treating my input as a download
UPDATE 2
After some more experimenting, i was finally able to get webkitgtk working on the pi 4.
The problem seems to originate from using the webkit_web_view_load_uri() api.
It does not seem to recognize my html document as a web page.
I got around it using the webkit_web_view_load_html() call. This included some hacks by first reading in the contents of the html doc into a character buffer, and passing it to webkit_web_view_load_html().
You also have to provide a base path to this function call to be able to resolve all the urls (scripts, css, images etc) in your html document.
Another problem i haven't been able to work around is, SVG images are not loading in webkitgtk. I have used jpg formats and they work. I suspect this my be due to a configuration switch in building webkigtk
It's hard for me to figure out what might be happening without having access to your environment and settings. My gut feeling is that pages are showing blank because perhaps some shared libraries are missing. You can check that with:
$ ldd WebKitBuild/GTK/Release/bin/MiniBrowser
I am using buildroot to setup the Linux system, starting with the pi 4 defconfig provided in buildroot.
There's a buildroot repository for building WPE for RPi. WPE (WebPlatform for Embeded) is like WebKitGTK but doesn't depend on GTK toolkit. Another important difference is that WPE runs natively on Wayland.
If you're interested in having a webapp embedded in a browser running in a device with limited capabilities, WPE is a better choice than WebKitGTK. The buildroot repo for building WPE for RPi is here:
https://github.com/WebPlatformForEmbedded/buildroot
There's is also this very interesting step-by-step guide on how to build WPE for RPi3:
https://samdecrock.medium.com/building-wpe-webkit-for-raspberry-pi-3-cdbd7b5cb362
I'm not sure whether the buildroot recipe would work for RPi4. It seems to work for all previous versions, so you might be stepping in new land if you try to build WPE on RPi4.
If you have an RPi3 available I'd try to build WPE for RPi3 first, and make sure that works. Then try for RPi4.

How to run c code(on codeblocks) without desktop on raspberry?(Like work of omxplayer)

Sorry my bad English. I work 3d shape with opengl on raspberry pi3(debian) for a while. I want to run my code don't use on desktop(or window). I searched but puzzled my mind. In a nutshell I want to run my code as well as in image below.
enter image description here
When I searched this topic, I have seen about EGL library but I don't know if I can use this.
If you used OpenMAX library before you know openmax doesn't use window. All image or video can run on console mode. You don't need any dosktop. I wonder this Is there a way I can use Opengl in this way ?(Can Opengl run like OpenMAX library or not) If there is any way How should I build my code ? I want render my image without desktop. I want use console mode.
Thanks your time. Best Regards.
The most straightforward solution would be to just create a fullscreen window, that has no border and no decorations (titlebar, buttons, etc.). If you want actual graphic output, there's nothing wrong with using X11. Despite some hearsay thrown around on the Internet the Xorg X11 servers are actually pretty lightweight.
If you really want to go without X11, then you should look at things like the kmscube demo https://cgit.freedesktop.org/mesa/kmscube/tree/ which does OpenGL directly to the display, without a graphics server or windowing system in between.
If you want it to be a little more abstracted, then have a look at how Wayland compositors talk to the display. The developers of the Sway Wayland compositor developed a nice abstraction library for this: https://github.com/swaywm/wlroots
You need to start display server first.
What you need could work with "xinit" which would manualy start xorg server, after that I suspect you should start "openbox" which is window manager. This way your desktop application should run as is, no changes needed.
Best practice is to create shell script for starting your application which could look like this:
set -e
xset s off
xset -dpms
xset s noblank
openbox &
cd /home/your_applicaton_directory
your_executable 2>/dev/null >/dev/null
Save this script and mark it executable whith
chmod +x
Then try to run this:
xinit /full_path_to_above_script
Hope this helps a bit... :)
Qt has a platform backend called eglfs, which lets your application run fullscreen on a single screen by using EGL and kms with very little overhead. Should work nicely with whatever OpenGL stuff you want to do.
You would just program a Qt application like normal, and launch it with ./myapp -platform eglfs from a tty.
http://doc.qt.io/qt-5/embedded-linux.html#eglfs

Is it a good idea to use a Screensaver on a raspberry pi as digital signage?

I asked this question in the Raspberry PI section, so please forgive me for posting this here again. Its just there doesn't seem to be as active as this section of the forum. So, onto my question...
I have an idea and I'm working on it right now. I just wanted to see what the community's thought was on using a screensaver as digital signage. Every tutorial I've read shows someone using chromium in kiosk mode, and while that's fine and works well for some uses, it doesn't work for what I need. I have successfully completed a chromium kiosk, and it was cool. But the signage that I need to create now, has to work without internet. I've thought about installing LAMP locally on the PI, and still using chromium. I still may have to if this idea doesn't pan out. All I need from the signage is a Title Message in the top center, and a message body underneath it, with roughly 300-400 character limit. My idea is to write a screensaver module, in C, that will work with a screensaver such as xscreensaver. The module would need to be able to load messages from a directory on the pi. Then for my clients to update their signage text, I would write a simple client that sent commands as well as the text via SSH to the pi. I want to know what other people think about this. Is it a good idea? Bad idea? Should I "waste" my time doing something like this?
Thanks in advance.
I am already using a rPi as digital signage, just over a year. I am using two different setups:
version 1 uses Raspian loading xdesktop and qiv image viewer to cycle images stored on the Pi itself, synchronized with a remote server. The problem I found was power and SD stability, when the power fails, which it will do no matter what, just when... The Sd card can become corrupt due to all the writing that Raspian does all the time. Certainly does not really need to write to SD.
version 2 uses a RO-filesystem and a command line image tool. Uses the same process to show images from local, and sync with server. But power fail causes no ill effects.
I am not using screensaver to display images, that seemed redundant to me, and unnecessary to wait for the SS to start just to display the images.
Some of the images are created using imagemagik, which is nicely dynamic where needed.

Make netbeans use virtual box guest installation of phpunit

We use netbean's phpunit / unit testing plugins for all our testing. We used to use xampp and point netbeans at our our .bat file from the xampp installation. We recently started using vagrant and are now running our dev environment in virtual box. I would like to make netbeans use the installation of phpunit within the virtual machine. This would save us from having to have both installed. Is this even possible? Netbeans seems to want a file location and I am stumped as to how I can go about doing this.
[EDIT] I've created a custom batch file that uses vbox guestconrols to forward the commands to the VMs installation of phpunit. I am going to then point netbeans at my custom .bat file. My problem is, now, that guestcontrols doesn't seem to be forwarding --bootstrap. It seems to be trying to take it and use it, rather than forward it along. The docs say that all the additional arguments will just be passed on, but that doesn't seem to be the case. Here is what I am using in my my_phpunit.bat :
[my_phpunit.bat]
#echo off
if "%VBoxManage%" == "" set VBoxManage=C:\Program Files\Oracle\VirtualBox\VBoxManage.exe
"%VBoxManage%" "--nologo" "guestcontrol" "<my_vm_name>" "execute" "--image" "/usr/bin/php5" "/usr/bin/phpunit" "--verbose" "--username" "<user>" "--password" "<pass>" "--wait-stdout" "--wait-stderr" "CustomNetbeansTestSuite" "<path/to/test/suite>" "--bootstrap" "<path/to/bootstrap>" %7
I am almost there, as running the bat file without the bootstrap option at the end takes me to the unit test. I am getting exceptions because of some autoloader issues(no bootstrap), but if I can figure out a better way to forward these command line arguments to
[EDIT 2]
I think I've finally solved this, but I need to get some issues with my guest OS in order. Once I've been able to test it a bit more, I'll post the final solution. I solved the Vbox guest control issue by adding "--" before I actually sent the parameters that should be forwarded. It said to do so in the docs, but it wasn't entirely clear to me at first.
I just wanted to update that I never actually got the .bat file to work. I think I got pretty close, but I was hung up on some linux CLI output that I couldn't suppress. The .bat file that I ended up with was:
# .bat example
https://pastebin.com/BX1xnL3q
I ended up moving to PhpStorm and everything worked out of the box. So, if you're still using netbeans, you can try and give that a shot. Maybe someone with more unix / linux experience can fix the issues I was having. I feel I was like 99% there with it.

Launch OpenGL app straight from a windowless Linux Terminal

How exactly would one go about getting an OpenGL app to run fullscreen straight from the terminal (Ubuntu Server 9.04)? I've developed an application for visual diagnostics on my server, but, I'm not totally sure the best way to get it to run in a windowless environment.
Ideally, I would run my program:
./visualdiagnostics
and have that launch the OpenGL app. Then, via a simple Ctrl+X key binding, I'll kill the app and go back to the terminal.
Do I need to install X11 and then somehow launch it from within the program? What would be the best way to detect if it's already running and, start/stop it if necessary?
And FYI: No, I'm not trying to get this to run over Putty or anything... I have a monitor hooked straight up to the server. The server has proper video drivers installed.
There are several parts to your task. Keep in mind that some of this can be very distro-specific; but since you said Ubuntu we'll talk Ubuntu!
Also you tagged this question C however I am starting off with a common Linux pattern: a native application with a Bash shell script wrapper. Perhaps once you get things working well you might fold that functionality into C if you have to.
Detecting whether X is running
Being root can help a lot. Some things that work.
pgrep Xorg
Check whether /var/lib/gdm/:0.Xauth exists. This will be there even if nobody has logged in but GDM is running.
ls -l /home/*/.Xauthority (Even if you're not root you can at least confirm whether you are running X.
Piggybacking an existing X session
You did not specifically mention it but if you are root at the console, or if you want to run the app as the same user who is already logged in, it's pretty easy.
You have to get the DISPLAY and XAUTHORITY environment variables right, and once you do you can use the existing X display.
For DISPLAY you might just assume :0 or you could find an existing X program (x-session-manager is the GNOME standard) and read its environment from /proc/PID/environ. Variables are in key=value format delimited by a null byte. For example, if its PID is 12345:
cat /proc/12345/environ \
| ruby -ne 'puts $_.split("\0").select {|e| e.starts_with? "DISPLAY=" }'
For XAUTHORITY you could get it the same way. Or if you prefer guessing, it's almost always /home/whoever/.Xauthority
Once you have those two variables, running X code is easy, for example:
env DISPLAY=:0 XAUTHORITY=/home/brian/.Xauthority ./visualdiagnostics
Stopping X
This one is easy if you're root: /etc/init.d/gdm stop. killall Xorg will work too.
If you are a user, kill your own Xorg or x-session-manager process. (I'd welcome input from others for the canonical way to do this. Maybe some dbus-send message?)
Starting X
I would recommend xinit whose goal in life is to fire X and run exactly one program.
For example: xinit ./visualdiagnostics
You can also tell xinit what resolution to run X at which may or may not be important to you. (This becomes important in the full-screen section below.)
The problem with this is you will have no window manager— no maximize and minimize buttons. It's not just cosmetic. Usually an app is useless because a popup window cannot be moved or you cannot focus on the right input field. However if you have a special app it could be sufficient (see full-screen below).
The next step would be my answer to everything: another shell script wrapper! Something simple that starts the window manager and then becomes your program should work.
#!/bin/bash
#
# Start visualdiagnostics once xinit calls me.
/usr/bin/metacity& # Or ratpoison, or fluxbox, or compiz, etc.
exec ./visualdiagnostics
It's important to exec (become) the main program because once that first program exits, X will shut down.
Running fullscreen
I am not 100% certain on this. Some ideas:
Try the standard X -geometry parameters to set 0,0 as the upper-left corner and +x+y for your horizontal and vertical size. How do you know the size? Either you hard-coded it when you launched xinit or you could ask the X server. xwininfo -root will tell you and there is an xlib API call that would do that too—check the xwininfo source I guess.
Your app itself can request maximization and/or resizing to fill the screen. I'm not familiar but it is definitely in the X API.
Some of the more configurable window managers can be pre-configured to run you maximized already. This is probably what I personally would check first. Your wrapper script could create a $HOME/.fluxboxrc just by echoing some hard-coded configs > the file.
Summary
The others are right. X is not strictly necessary sine OpenGL can run against a framebuffer. However considering how ubiquitous X is and how much work has gone into automating it for distributions, I would probably invest my effort into the X route as it might be easier long-term even though it's a little convoluted.
(By the way, I sincerely hope when you say "terminal" you mean you are at the text console, not gnome-terminal that would be awful! :)
Well I am clearly not sure my answer might help you out.
Long ago when I was student, I manage to do so (launching an openGL app from a terminal only linux installation) by installing frame buffer. As long as I remember I needed to recompile my kernel (as framebuffer was/is a kernel module).
This was maybe 5 years ago on a debian distrib, and I don't know how does it work now for up-to-date debian distrib as Ubuntu. Maybe framebuffer is compiled statically in the binary kernel provided by default with Ubuntu. May be not. Maybe framebuffer is irrelevant now... Or I may be totally wrong and not remembering every details of my own adventure 5 years ago now ..
Have a look on Google ! ;-)
Hope it will help...
**
Update:
**
What is frame buffer ?
How to install it? Here or there
As yves pointed out, you can avoid running the X server if you use the framebuffer. Actually, the framebuffer modules are often yet available (for example, they are used to have the tux logo during the kernel start or a text terminal with fancy images in the background), this anyway depends on the distribution and the settings you are using.
The kernel side is quite primitive so I'd suggest to use some higher level library such as DirectFB. The framebuffer is usable without problems but don't expect the same maturity level than a full blown X server.
Are you trying to have the video be on the monitor connected directly to the computer?
Is X running on the server?
If X is running, you can do
export DISPLAY=:0.0
which tells X apps to connect to the X server at localhost, rather than where' you're coming from.
If you're actually logging in locally (from a direct terminal) ... yes, you need X installed and running.

Resources