How to use Panda3d with SDL2

In an attempt to port Panda3d to Android, I would like to use it with SDL2 in order to add input handling, audio and other platform related stuff because I know SDL so well. So how do go about it both in configuring the source, and in code ?

You would need to create a new sdldisplay back-end plug-in similar to x11display, windisplay, and cocoadisplay. You would need to follow the code of the x11display module and do something similar using the SDL APIs.

However, why would you do this? Panda3D already has an Android back-end, which supports input handling via Android’s own input APIs.

The audio plug-ins are separate from the windowing plug-ins. OpenAL should work fine on Android, however, so I don’t think there’s a reason to port Panda to use a different audio API.

The Reason I desire SDL is because it handles all features in one, instead of separate modules for display, audio etc, and it is easy and I am familiar with it.
Panda3d already has Android input back-end? I didn’t know that. I will look at the source code.

Yes, it’s in panda/src/androiddisplay, this back-end is used when you run the Android port of Panda and uses the android_app structures available with the NDK. It goes along with the code in panda/src/android which contains the main activity and entry point.

Display and audio are separate subsystems in Panda. All our current supported audio libraries are supported on Android so I don’t see a need to create a new SDL audio back-end, especially given that SDL audio is not nearly as full-featured as OpenAL.

What about input? Because someone posted an Android studio template project on github with no input handling.

Yes, it handles input, because the event loop is part of the display and windowing in Panda.

I’ve looked at the source but I don’t understand. How to make the app run a python script upon starting ? I know the code to start the Python Interpreter, set environment variables, load libraries and make it start a script, but where to put this code? In the PythonActivity.java ?
Will the display already be setup?

The Java end is in PandaActivity.java, which provides support for and runs the main C++ entry point in android_main.cxx (in panda/src/android). That android_main function sets up the environment (such as mounting the asset folder to the VFS, setting up the “main” thread, redirecting the output), and then calls main(), which for the “ppython” activity is defined in python_main.cxx, which just runs whatever it is given as argument as a Python script.

The display is set up when the application first opens a window, which happens by creating an AndroidGraphicsPipe and ultimately an AndroidGraphicsWindow. The latter also handles the main loop, input events and application lifetime events.