UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    C++ and SDL with Clickable. A little help please.

    Scheduled Pinned Locked Moved App Development
    linkc++appsdl2sdl
    32 Posts 10 Posters 8.8k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • CraigC Offline
        Craig
        last edited by

        I've written a program in C++ and SDL2 and would like to publish it to the Ubuntu Touch open store. I have installed clickable and I've gotten the "Hello World" screen on my tablet. I added the SDL dependencies to the clickable.json file.

        Could someone be kind enough to tell me how/where to put my C++ files and what settings to make in the CMakeLists.txt file? I have four .cpp and four .h files. I wont need to use Qml.

        When I run clickable it almost compiles, but it appears to not be able to link to the SDL libraries.

        Thanks!

        advocatuxA lduboeufL 3 Replies Last reply Reply Quote 4
        • advocatuxA Offline
          advocatux @Craig
          last edited by

          @craig hi, I've pinged some people who can help you 😉

          1 Reply Last reply Reply Quote 1
          • WendigoW Offline
            Wendigo
            last edited by

            I'm interested in this too. SDL seems to be the only way to get GPU acceleration on Ubuntu Touch currently. A step by step tutorial on how to set up an SDL project would be awesome.

            1 Reply Last reply Reply Quote 2
            • lduboeufL Offline
              lduboeuf @Craig
              last edited by

              I remember a great app witch uses SDL2 , but seems not using clickable wrapper

              https://github.com/pseuudonym404/tuxracer-touch

              1 Reply Last reply Reply Quote 1
              • CraigC Offline
                Craig
                last edited by

                Thanks to all for your input and suggestions so far. I ran searches online for "CMakeLists.txt SDL tutorial", and read many tutorials. This is what I have so far that seems to almost work:

                1. sudo apt install libsdl2-dev
                  clickable create
                  I chose option [7] main-cpp - C++/QML App (built using CMake with a main.cpp)

                2. I replaced the main.cpp file in my project directory with a very small 512 byte SDL test program. It just produces a blank screen for 5 seconds and then quits. I compiled and tested it with the Code::Blocks IDE and it works fine there.

                3. I added these lines to my CMakeLists.txt file in my project directory and finally I got it to link up with the SDL library:
                  add_executable(${PROJECT_NAME} main.cpp)
                  find_package(SDL2 REQUIRED)
                  include_directories(${SDL2_INCLUDE_DIRS})
                  set(SDL2_LIBRARIES "-lSDL2")
                  target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

                4. I run clickable from my project directory and it compiles the program just fine and sends it to my Ubuntu Touch tablet where I see the logo.svg flash on the screen for only 1 second. Finally, no error messages not being able to link up with SDL. However, I don't get the expected blank screen for 5 seconds. The logo.svg shows on the screen along with my project name for only 1 second, but it seems to quit before running the program which should show a blank screen for 5 seconds. On my tablet I now have the logo.svg icon displayed as one of my apps. When I click on it the icon shows along with the app name for about 1 second and then closes.

                Does anyone know what I need to tweak to get SDL to run on UT through clickable? Then, like Wendigo said, we will have a working SDL recipe for UT/clickable for other app developers.

                1 Reply Last reply Reply Quote 3
                • CraigC Offline
                  Craig
                  last edited by Craig

                  Here's the source of the main.cpp:

                  #include <SDL.h>

                  int main(int argc, char *argv[])
                  {
                  SDL_Init(SDL_INIT_VIDEO);

                  SDL_Window *window = SDL_CreateWindow( "SDL2Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0 );

                  SDL_SetWindowFullscreen( window, SDL_TRUE );

                  SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
                  SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
                  SDL_RenderClear(renderer);
                  SDL_RenderPresent(renderer);

                  SDL_Delay(5000);

                  SDL_DestroyWindow(window);
                  SDL_Quit();

                  return 0;
                  }

                  1 Reply Last reply Reply Quote 1
                  • lduboeufL Offline
                    lduboeuf @Craig
                    last edited by

                    @Craig any news regarding your port of SDL game ?

                    1 Reply Last reply Reply Quote 0
                    • Z Offline
                      zubozrout
                      last edited by

                      Some of you may find these demos usable:
                      https://gitlab.com/zub2/SDLDemo
                      https://gitlab.com/zub2/MirGLESDemo

                      However with the Mir upgrade things should become a bit easier as regular Wayland-compiled SDL stuff should start working there. That is if I understand it correctly.

                      lduboeufL mymikeM 2 Replies Last reply Reply Quote 4
                      • bhdouglassB Offline
                        bhdouglass
                        last edited by

                        @Craig I just came across this thread and tried out what you mentioned. You'll need to bundle sdl2 with your app to be able to use it (Ubuntu Touch doesn't have it preinstalled). But it looks like @zubozrout 's demo might be a good place to start for that.

                        open-store.io && bhdouglass.com

                        1 Reply Last reply Reply Quote 3
                        • lduboeufL Offline
                          lduboeuf @zubozrout
                          last edited by

                          @zubozrout thanks for sharing, it works nicely. I've compiled sdl2 also in a project that only requires audio, i will post the source link here whenever i will publish it

                          lduboeufL 1 Reply Last reply Reply Quote 1
                          • lduboeufL Offline
                            lduboeuf
                            last edited by

                            for reference, it helps understand about clickable and dependencies : https://docs.ubports.com/en/latest/appdev/guides/dependencies.html

                            CraigC 1 Reply Last reply Reply Quote 0
                            • CraigC Offline
                              Craig @lduboeuf
                              last edited by

                              @lduboeuf
                              Thank you for your response. I ran "clickable create" and entered this option:
                              [7] main-cpp - C++/QML App (built using CMake with a main.cpp)
                              My project name is "mytest". I ran "clickable" and my USB connected tablet running Ubuntu Touch shows the app with "Hello World!". Good!

                              Next, I changed the main.cpp file so that is has the SDL test C++ code that you see in this posting. Also, I tried to make changes to the clickable.json file so the dependencies can be met, like so:

                              {
                              "template": "cmake",
                              "dir": "build/app",
                              "libraries": {
                              "SDL2": {
                              "template": "cmake"
                              }
                              },
                              "dependencies_target": [
                              "libsdl2-dev"
                              ]
                              }

                              I saw clickable downloading the SDL2 files for armhf architecture. Looked good. But I get these error messages:

                              [ 90%] Linking CXX executable mytest
                              CMakeFiles/mytest.dir/main.cpp.o: In function main': main.cpp:(.text+0xc): undefined reference to SDL_Init'
                              main.cpp:(.text+0x2e): undefined reference to `SDL_CreateWindow'
                              etc...

                              What should I adjust to get this test SDL test program working? Thanks!

                              lduboeufL 1 Reply Last reply Reply Quote 0
                              • lduboeufL Offline
                                lduboeuf @Craig
                                last edited by

                                @Craig have you looked at @zubozrout example for SDL2 ?

                                1 Reply Last reply Reply Quote 0
                                • mymikeM Offline
                                  mymike @zubozrout
                                  last edited by

                                  https://gitlab.com/zub2/SDLDemo

                                  I managed to build this fine (getting some warnings btw) but the app won't start. I get

                                  Command 'echo "sleep 1s && ubuntu-app-launch zub.sdldemo_SDLDemo_0.2" | ssh phablet@ubuntu-phablet' returned non-zero exit status 255.
                                  

                                  And I can neither grab any log (neither with clickable logs nor with Logviewer) as the log file doesn't exist.

                                  lduboeufL 1 Reply Last reply Reply Quote 0
                                  • lduboeufL Offline
                                    lduboeuf @mymike
                                    last edited by

                                    @mymike not sure but i had that also, try replacing in apparmor file 1.3 with 16.04

                                    mymikeM 1 Reply Last reply Reply Quote 2
                                    • mymikeM Offline
                                      mymike @lduboeuf
                                      last edited by

                                      @lduboeuf thanks https://gitlab.com/mymike00/SDLDemo this works for me!

                                      bhdouglassB 1 Reply Last reply Reply Quote 1
                                      • bhdouglassB Offline
                                        bhdouglass @mymike
                                        last edited by

                                        @mymike what do you think about turning your demo into a template for clickable? It could be really great way to get more people creating/porting SDL apps.

                                        open-store.io && bhdouglass.com

                                        mymikeM 1 Reply Last reply Reply Quote 4
                                        • mymikeM Offline
                                          mymike @bhdouglass
                                          last edited by

                                          @bhdouglass of course! but I don't know how that app work, neither how to make a clickable template. I'll may have a look at it when I'll find some time, but if someone else wants to do it before me, no problem, just do it!

                                          lduboeufL joniusJ 2 Replies Last reply Reply Quote 1
                                          • lduboeufL Offline
                                            lduboeuf @mymike
                                            last edited by lduboeuf

                                            @mymike yes maybe @zubozrout ? who did the hard work with SDL2 template

                                            1 Reply Last reply Reply Quote 1
                                            • lduboeufL Offline
                                              lduboeuf @lduboeuf
                                              last edited by lduboeuf

                                              @lduboeuf just for sharing, published a sample app that using only SDL2 audio https://github.com/lduboeuf/sfxr-qt. I've used template from @zubozrout SDL2 and it works fine.
                                              On my device, sounds are not good quality ( some noises ) , not sure if it is hardware pb or something in-between ( on Desktop it plays fine ).

                                              1 Reply Last reply Reply Quote 0
                                              • First post
                                                Last post