Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question]How to integrate SDL2 #14

Closed
lzhiyong opened this issue Mar 2, 2022 · 11 comments
Closed

[question]How to integrate SDL2 #14

lzhiyong opened this issue Mar 2, 2022 · 11 comments

Comments

@lzhiyong
Copy link

lzhiyong commented Mar 2, 2022

It's not an issue just asking for help, because I haven't studied your project in depth yet

I wonder if it is possible to support SDL2 with c/c++, I have seen someone using termux-gui and ffplay.py to play video.

@tareksander
Copy link
Member

I have a demo with SDL through ctypes in the python bindings tutorial. Using it directly with C/C++ should be easier, but I haven't finished the C/C++ library yet. My roadmap to that currently is:

  • add GridView and WebView
  • proper support for widgets and custom notifications
  • protocol buffers in addition to JSON as a binary protocol
  • implement the C/C++ library with protocol buffers

@lzhiyong
Copy link
Author

lzhiyong commented Mar 2, 2022

  • implement the C/C++ library with protocol buffers

Thank you for your reply, looking forward to developing games and videos directly using c/c++, such as ffmpeg and SDL2 etc.

@tareksander
Copy link
Member

If you want to develop games, I also want to include something like a direct rendering feature. Android 8.0+ supports something called Native Hardware Buffers. These are buffers that live in graphics memory and that can be passed around between programs. I want to make it possible that the plugin just continuously displays the contents of a Native Hardware Buffer and the client gets a reference and can create an OpenGL drawing surface with it. That way you can use graphics acceleration and it doesn't need any additional copying of the image.

@lzhiyong
Copy link
Author

If you want to develop games, I also want to include something like a direct rendering feature. Android 8.0+ supports something called Native Hardware Buffers. These are buffers that live in graphics memory and that can be passed around between programs. I want to make it possible that the plugin just continuously displays the contents of a Native Hardware Buffer and the client gets a reference and can create an OpenGL drawing surface with it. That way you can use graphics acceleration and it doesn't need any additional copying of the image.

Yes, your way is very flexible for debugging native graphics programs, because there is no need to compile and generate an apk every time and then install it to check the running status.

@captain1947
Copy link

captain1947 commented Jul 17, 2022

Hello, I also have some questions regarding the cpp plugin.
When the C/C++ library will be finished how will the api look? Basically what I am asking is that whether the current games made with SDL2 will run in termux without any modification ofc if the game supports gles, if the game will run with minimal modification or if the game needs to be rewritten from scrath and will only work in termux. If the first one is true then termux will get a whole bunch of open source games as most are written with SDL.

@tareksander
Copy link
Member

SDL support would either require the game to be modified (to support drawing to the provided buffer and receiving events properly) or an additional backend to be added to the SDL in the Termux repositories.

@captain1947
Copy link

How hard will be the first one? Will it be just changing a few lines or modifying every SDL call in the game.

@tareksander
Copy link
Member

Converting the plugin events to SDL events should be easy, but I don't know how exactly GLES works with SDL. SDL will probably throw an error when trying to create a window, you need to receive the buffer to draw to from the plugin as an AHardwareBuffer, get the image from that, construct a framebuffer with that image and bind GLES to that framebuffer. Keep in mind I haven't worked with GLES or SDL myself.

@tareksander
Copy link
Member

@captain1947 The C library is now mostly finished, with an example for GLES integration: https://github.com/tareksander/termux-gui-c-bindings/blob/main/tutorial/c/buffer_gl.c
Also see the tutorial and documentation.

@captain1947
Copy link

Sorry for replying late, I finally got time to check it but sadly it doesn't do what I wanted. The rendering part doesn't need to be changed and sdl can draw on the framebuffer you expose but the problem lies in the input part. The only way to get input is by using your api. The sdl input api isn't working. Instead I am looking forward to another project by you (termux-gfx-wrapper).

@tareksander
Copy link
Member

I'm also working on a custom Wayland compositor build on Termux:GUI, that will solve the input problem, and will have support for termux-gfx-wrapper. The goal is to have Linux apps integrate seamlessly into the Android experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants