Giter Club home page Giter Club logo

sdl3-sample's People

Contributors

captain1947 avatar ravbug avatar robloach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sdl3-sample's Issues

How to build a SDL3 application to WebAssembly

This is my topic on the SDL forum: https://discourse.libsdl.org/t/how-to-build-a-sdl3-application-to-webassembly/48041

I use this manual to build:

Note 1. I used cmake -G "MinGW Makefiles" .. insttead of cmake ..

Note 2. This manual works for Android. Except "Ninja" app that must be installed (and added to Path, I used one from Qt: C:\Qt\Tools\Ninja) and manually changing of CMake version in the build.gradle script.

I installed the latest emsdk for the current time:

"emsdk.bat" install latest
"emsdk.bat" activate latest

I completed this task:

  1. On Windows hosts, run config-web-win.bat via the emcmdprompt.bat cmd in the emsdk root directory

This is the result:

--   SDL_X11_XSHAPE              (Wanted: ON): OFF
--   SDL_XINPUT                  (Wanted: OFF): OFF
--
--  Build Shared Library: OFF
--  Build Static Library: ON
--  Build Static Library with Position Independent Code: OFF
--
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CMAKE_C_FLAGS and CMAKE_PREFIX_PATH CMake variables correctly.
--
-- Configuring done (691.6s)
-- Generating done (0.3s)
-- Build files have been written to: E:/_Projects/SDL3/sdl3-sample/build/web

The next task is:

  1. After the build completes, use python3 -m http.server in the build directory to make the page accessible.

But the build directory looks like this:

image

This is the /build/web directory:

image

I have the http-server package to run the result but I don't see the index.html. What to do next? You should add the next step.

I ran the mingw32-make command inside of the build/web directory:

[ 95%] Building C object SDL/CMakeFiles/SDL3-static.dir/src/thread/generic/SDL_sysrwlock.c.o
[ 96%] Building C object SDL/CMakeFiles/SDL3-static.dir/src/thread/generic/SDL_syssem.c.o
[ 96%] Building C object SDL/CMakeFiles/SDL3-static.dir/src/thread/generic/SDL_systhread.c.o
[ 97%] Building C object SDL/CMakeFiles/SDL3-static.dir/src/thread/generic/SDL_systls.c.o
[ 97%] Linking C static library libSDL3.a
[ 97%] Built target SDL3-static
[ 98%] Building CXX object CMakeFiles/sdl-min.dir/src/main.cpp.o
[100%] Linking CXX executable sdl-min.html
error: linker: Undefined symbol: emscripten_webgl_get_proc_address(). Please pass -sGL_ENABLE_GET_PROC_ADDRESS at link time to link in emscripten_webgl_get_proc_address().
Error: Aborting compilation due to previous errors
em++: error: 'C:/emsdk/node/16.20.0_64bit/bin/node.exe C:\emsdk\upstream\emscripten\src\compiler.mjs C:\Users\8OBSER~1\AppData\Local\Temp\tmpwt4pmkp5.json' failed (returned 1)
mingw32-make[2]: *** [CMakeFiles\sdl-min.dir\build.make:100: sdl-min.html] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:101: CMakeFiles/sdl-min.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2

Only the sdl-min.wasm was generated but I didn't find the sdl-min.html file. I don't understand what the errors mean and how to solve them.

image

wasm-ld: error: unable to find library -landroid

If you make git clone and build to WASM it will work. But after this when you try to build to Android and try to build to WASM again you will have this error: wasm-ld: error: unable to find library -landroid I tried two times.

sdl3-sample\build\web>mingw32-make
[ 97%] Built target SDL3-static
[ 98%] Linking CXX executable sdl-min.html
wasm-ld: error: unable to find library -landroid
em++: error: 'C:/emsdk/upstream/bin\wasm-ld.exe -o sdl-min.wasm CMakeFiles/sdl-min.dir/src/main.cpp.o SDL/libSDL3.a -landroid -LC:\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr C:\Users\8OBSER~1\AppData\Local\Temp\tmp__e02cpglibemscripten_js_symbols.so --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --stack-first' failed (returned 1)
mingw32-make[2]: *** [CMakeFiles\sdl-min.dir\build.make:100: sdl-min.html] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:101: CMakeFiles/sdl-min.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2

How to add OpenGL ES support for the example to build for Android?

I try to rewrite the example to glClearColor() and glColor() to clear the background:

#include <SDL_opengles2.h>

// ...

    // draw a color
    auto time = SDL_GetTicks() / 1000.f;
    auto red = (std::sin(time) + 1) / 2.0;
    auto green = (std::sin(time / 2) + 1) / 2.0;
    auto blue = (std::sin(time) * 2 + 1) / 2.0;
    glClearColor(red, green, blue, 1.f);
    glColor(GL_COLOR_BUFFER_BIT);

    SDL_GL_SwapWindow(window);

// ...

But I have this error:

main.cpp:39:5: error: use of undeclared identifier 'glColor'

I think I should add something in config files. Please, help me to run this example.

main.cpp

#include <iostream>
#include <SDL.h>
#include <cmath>
#include <SDL_opengles2.h>
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
//On UWP, we need to not have SDL_main otherwise we'll get a linker error
#define SDL_MAIN_HANDLED
#endif
#include <SDL_main.h>
#if __EMSCRIPTEN__
#include <emscripten.h>
#endif

void SDL_Fail(){
    SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Error %s", SDL_GetError());
    exit(1);
}

static bool app_quit = false;
SDL_Window* window = nullptr;

void main_loop() {
    // Get events. If you are making a game, you probably want SDL_PollEvent instead of SDL_WaitEvent.
    // you cannot use WaitEvent on Emscripten, because you cannot block the main thread there.

    SDL_Event event;
    while (SDL_PollEvent(&event)) {
        if (event.type == SDL_EVENT_QUIT)
            app_quit = true;
        break;
    }

    // draw a color
    auto time = SDL_GetTicks() / 1000.f;
    auto red = (std::sin(time) + 1) / 2.0;
    auto green = (std::sin(time / 2) + 1) / 2.0;
    auto blue = (std::sin(time) * 2 + 1) / 2.0;
    glClearColor(red, green, blue, 1.f);
    glColor(GL_COLOR_BUFFER_BIT);

    SDL_GL_SwapWindow(window);
}

// Note: your main function __must__ take this form, otherwise on nonstandard platforms (iOS, etc), your app will not launch.
int main(int argc, char* argv[]){
    
    // init the library, here we make a window so we only need the Video capabilities.
    if (SDL_Init(SDL_INIT_VIDEO)){
        SDL_Fail();
    }
    
    // create a window
    SDL_Window* window = SDL_CreateWindow("Window", 352, 430, SDL_WINDOW_OPENGL);
    if (!window){
        SDL_Fail();
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GLContext glContext = SDL_GL_CreateContext(window);
    if (!glContext)
    {
        SDL_Fail();
    }

    // print some information about the window
    SDL_ShowWindow(window);
    {
        int width, height, bbwidth, bbheight;
        SDL_GetWindowSize(window, &width, &height);
        SDL_GetWindowSizeInPixels(window, &bbwidth, &bbheight);
        SDL_Log("Window size: %ix%i", width, height);
        SDL_Log("Backbuffer size: %ix%i", bbwidth, bbheight);
        if (width != bbwidth){
            SDL_Log("This is a highdpi environment.");
        }
    }
    
    SDL_Log("Application started successfully!");
    
#if __EMSCRIPTEN__
    // on Emscripten, we cannot have an infinite loop in main. Instead, we must
    // tell emscripten to call our main loop.
    emscripten_set_main_loop(main_loop, 0, 1);
#else
    while (!app_quit) {
        main_loop();
    }
#endif

    // cleanup everything at the end
#if !__EMSCRIPTEN__
    // SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    SDL_Log("Application quit successfully!");
#endif
    return 0;
}

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.libsdl.app/com.ravbug.sdlmin.SDLActivity}

Please, help me to solve this problem. I don't have any ideas:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.libsdl.app/com.ravbug.sdlmin.SDLActivity}: java.lang.ClassNotFoundException: Didn't find class "com.ravbug.sdlmin.SDLActivity" on path: DexPathList[[zip file "/data/app/org.libsdl.app-2/base.apk"],nativeLibraryDirectories=[/data/app/org.libsdl.app-2/lib/arm, /data/app/org.libsdl.app-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2625)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.ravbug.sdlmin.SDLActivity" on path: DexPathList[[zip file "/data/app/org.libsdl.app-2/base.apk"],nativeLibraryDirectories=[/data/app/org.libsdl.app-2/lib/arm, /data/app/org.libsdl.app-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2615)
... 9 more

Could not resolve com.android.tools.build:gradle:8.1.1

Something was changed in the build scripts because it worked a few moth ago

sdl3-sample\SDL\android-project>gradlew assembleDebug

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android-project'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:8.1.1.
     Required by:
         project :
      > No matching variant of com.android.tools.build:gradle:8.1.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.1.1' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:8.1.1 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:8.1.1 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:8.1.1 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:8.1.1 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

Info.plist.in referencing icon.png which doesn't exist

In Info.plist.in on line 36, a file called icon.png is referenced. However, there's only logo44.png, logo50.png, logo150.png and logo620x300.png in the repo. Looking through the commits, I believe this happened because XCode support was added before the logos were added, and the file name was speculative at the time.

Wrong arguments in the SDL_SetRenderDrawColor function

There are wrong arguments in in the SDL_SetRenderDrawColor function:

    // draw a color
    auto time = SDL_GetTicks() / 1000.f;
    auto red = (std::sin(time) + 1) / 2.0 * 255;
    auto green = (std::sin(time / 2) + 1) / 2.0 * 255;
    auto blue = (std::sin(time) * 2 + 1) / 2.0 * 255;
    
    SDL_SetRenderDrawColor(renderer, 0, red, green, blue);

https://wiki.libsdl.org/SDL2/SDL_SetRenderDrawColor

int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
                   Uint8 r, Uint8 g, Uint8 b,
                   Uint8 a);

It must be like this:

    // draw a color
    auto time = SDL_GetTicks() / 1000.f;
    auto red = (std::sin(time) + 1) / 2.0 * 255;
    auto green = (std::sin(time / 2) + 1) / 2.0 * 255;
    auto blue = (std::sin(time) * 2 + 1) / 2.0 * 255;
    
    SDL_SetRenderDrawColor(renderer, red, green, blue, 255);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.