Hi, I’m trying to understand how to use the assets files of an APK from SDL2 ,here is what i want to do: load a texture from assets/background.jpg, render it on each loop.
I’ve put the texture in the assets dir, I can see it when the apk is generated using an extractor, so it’s good to go, but the file can’t be read from the SDL_image function to do so…
Code:
SDL_Texture *img = NULL;
int w, h; // texture width & height
//later in the code
if (img == NULL) {
// load our image
img = IMG_LoadTexture(state->renderers[0], "background.jpg");
if (img != NULL)
{
SDL_Log("Image loaded ok -background.jpg-");
}
else
{
SDL_Log("Could not load the background.jpg");
}
}
I’m always getting the "Could not load the background.jpg , do I need to add permises to the AndroidManifest?, should i be using AssetManager from a JNI bridge from Java?
like this: http://www.concretepage.com/android/android-assetmanager-example-to-load-image-from-assets-folder
?
or maybe my sdl2_image library is not compiled ok, since i had to make my own .so version with VStudio2017 and the sources…
Thanks , the problem was that i was not using the flags USE_JPG when compiling the SDL2_image libraries, now it loads the image with a renderer, but i can’t see the image on the screen
What I do in main.cpp is:
add the include #include "SDL_image.h"
then init just the jpg:
int flags = IMG_INIT_JPG;// | IMG_INIT_PNG;
if (IMG_Init(flags) != flags)
{
SDL_Log("Could not initialize IMG JPG");
SDL_Log("IMG Load error: %s", SDL_GetError());
}
create the renderer: SDL_Renderer *imgRenderer = SDL_CreateRenderer(state->windows[0], -1, SDL_RENDERER_ACCELERATED);
then ,load the image: