Issue
Good day!
I got a project from a firm and now I need to develop an arcade cabinet with Raspberry Pi 3. It has a joystick and some external devices, which are controlled via GPIO. I have already organized the communication between the RPI 4B 8Gb and the joystick and I can already receive signals from the coin acceptor. The next trouble is performance. I create the videogame using Java and append the internal processing libraries (www.processing.org) to the project for the graphic output and GPIO interaction.
The processing-core library has two abilities to render graphics: software rendering (using parameter JAVA2D in the size() function) and hardware accelerated (using parameter P2D or P3D in the same function). The parameters P2D and P3D enable the OpenGL support and the performance of all my games on the normal desktop PC or android device is higher as the performance in the JAVA2D mode. But not on my single board computers.
On the Raspberry PI 4B 8Gb (Raspberry Pi OS 64 bit desktop) I got: 11 FPS in JAVA2D mode and 6 FPS in P2D mode. On my Khadas Vim3 pro (Ubuntu 20.04 64 bit) I got 14 FPS in JAVA2D mode and 8 FPS in P2D mode.
I don’t understand what is the trouble with the performance on the SBC? My game is pretty simple: The screen size is: 1920x1080. All the game graphic is packed in a single PNG file. I draw a images for background, than for 3 airplaines, than for bullets and than a full screen explosion. All the graphic is drawn without scaling using function:
image(source, posX, poxY, width, height, leftPixelInSource, upperPixelInSource, rightPixelInSource, lowerPixelInSource);
I need to get at least 20 FPS to complete the project.
I use Intellij IDEA (with sudo parameter) and I see in the logcat the next 3 lines when I use OpenGL (P2D parameter in the size()-function):
error: XDG_RUNTIME_DIR not set in the environment.
error: XDG_RUNTIME_DIR not set in the environment.
error: XDG_RUNTIME_DIR not set in the environment.
, but the game runs. When I close the game I receive the next messages in the logcat.
X11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 2/2, reusable (open, marked uncloseable): 0, pending (open in creation order): 2)
X11Util: Open X11 Display Connections: 2
X11Util: Open[0]: NamedX11Display[:0, 0x7f1c07cc90, refCount 1, unCloseable false]
X11Util: Open[1]: NamedX11Display[:0, 0x7f1c0a2150, refCount 1, unCloseable false]
In Java mode I haven’t any errors. I tried to launch without the sudo parameter and with the enabled P2D parameter. I have a new error and can not launch the game. The log cat shows:
Resource compiler: Error: Couldn't copy [/home/mgdsstudio/GD/Workspace/Airfight/Libs/META-INF/MANIFEST.MF] to [/home/mgdsstudio/GD/Workspace/Airfight/out/production/desktop/META-INF/MANIFEST.MF]
java.io.IOException: Couldn't copy [/home/mgdsstudio/GD/Workspace/Airfight/Libs/META-INF/MANIFEST.MF] to [/home/mgdsstudio/GD/Workspace/Airfight/out/production/desktop/META-INF/MANIFEST.MF]
at com.intellij.openapi.util.io.FileUtil.performCopy(FileUtil.java:419)
at com.intellij.openapi.util.io.FileUtil.copyContent(FileUtil.java:408)
at org.jetbrains.jps.incremental.FSOperations.copy(FSOperations.java:472)
at org.jetbrains.jps.incremental.resources.ResourcesBuilder.copyResource(ResourcesBuilder.java:123)
at org.jetbrains.jps.incremental.resources.ResourcesBuilder.lambda$build$0(ResourcesBuilder.java:67)
at org.jetbrains.jps.incremental.fs.BuildFSState.processFilesToRecompile(BuildFSState.java:374)
at org.jetbrains.jps.incremental.IncProjectBuilder$6.processDirtyFiles(IncProjectBuilder.java:1261)
at org.jetbrains.jps.incremental.resources.ResourcesBuilder.build(ResourcesBuilder.java:56)
at org.jetbrains.jps.incremental.resources.ResourcesBuilder.build(ResourcesBuilder.java:27)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTarget(IncProjectBuilder.java:1266)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1166)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1303)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1118)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:889)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:471)
at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:197)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:150)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:371)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:193)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:211)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.nio.file.AccessDeniedException: /home/mgdsstudio/GD/Workspace/Airfight/out/production/desktop/META-INF/MANIFEST.MF
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
at java.base/java.nio.file.Files.newOutputStream(Files.java:220)
at com.intellij.openapi.util.io.FileUtil.openOutputStream(FileUtil.java:452)
at com.intellij.openapi.util.io.FileUtil.performCopy(FileUtil.java:415)
... 22 more
I read some info about default OpenGL driver troubles on RPI. But I don’t understand what I must do to increase the FPS or maybe repair the OpenGL? Are there differences in the Raspberry Pi OS 32 bit between desktop and no desktop distribution? Maybe I need to try another OS distribution to get better performance?
I have made my sketch simpler. It has now only one function in the game loop:
@
Override
public void settings(){
size(1920, 1080, P2D);
}
@Override
public void setup(){}
@Override
public void draw(){
System.out.println("FPS: " + frameRate);
}
And I got the FPS not more than 13 frames per second. The game loop does nothing - only console output. When I launch glxgears programm after I have installed mesa-utils with the command:
sudo apt-get install mesa-utils
I get 75 FPS. I don’t understand why the simplest processing sketch with only console output and the not updateable screen content runs so slow
Solution
Well, I have transfered my game into LibGDX. It uses also Java as the programming language and Open GL ES for the rendering. I have got 50-60 FPS. The answer is pretty simple: Don't use Processing for creation of applications with the Open GL context running on ARM Single board computers with Linux as the operating system.
Answered By - Alexander Gorodilov Answer Checked By - Marie Seifert (WPSolving Admin)