2

I'm experimenting with android SDL 2.0, however I encountered a problem that I just can't solve. My problem is that I try to make a 1080*1920 picture as the background of my application. I create it in photoshop, but whenever I try to start the app on my phone, the image quality is much worse.

Here's an example.You can't really see on the picture how bad it is, but looking on my phone screen, it is way worse:

The picture

The picture on my phone

The code I'm using:

int main(int argc, char *argv[])
{
  int w, h;
  KEP kep;
  SDL_Window *window;
  SDL_Renderer *renderer;
  SDL_Surface *surface;
  SDL_CreateWindowAndRenderer(0, 0, 0, &window, &renderer);
  SDL_GetWindowSize(window, &w, &h);


  surface = IMG_Load("hatter.png");
  kep.w = w;
  kep.h = h;
  kep.texture=SDL_CreateTextureFromSurface(renderer, surface);
  SDL_FreeSurface(surface);
  SDL_Rect destination={0, 0, kep.w, kep.h};

  SDL_RenderClear(renderer);
  SDL_RenderCopy(renderer, kep.texture, NULL, &destination);
  SDL_RenderPresent(renderer);
  return 0;
}

The "kep" is just a structure with the texture, width, and height of the picture, declared earlier. I'm using SDL_image extension right now, but it didn't work with the SDL_LoadBMP() either.

What can I do to don't end up in such a bad quality?

Thanks a lot!

Martin G
  • 17,357
  • 9
  • 82
  • 98
Daniel
  • 21
  • 1

1 Answers1

1

I answered something similarly recently that should help with this as well; here it is:

First off make sure that the image is in a small file type format like "PNG". Second when blitting the image make sure that you are not adding the transparency color to the background image is it is pointless and takes up a LOT of cpu cycles. Here's an example of code I've written a long time ago as a wrapper for image loading

SDL_Surface* altSDL::load_image(std::string filename)  
{
    SDL_Surface* loadedImage = NULL;

    SDL_Surface* optimizedImage = NULL;

    loadedImage = IMG_Load( filename.c_str() );

    if( loadedImage != NULL )
    {
        optimizedImage = SDL_DisplayFormat( loadedImage );        
        SDL_FreeSurface( loadedImage );
    }
    else
    {
        Failure* fail;
        fail = Failure::getInstance();
        fail->failLog(filename);
    }

    if( optimizedImage != NULL )
    {
        Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0xFF, 0, 0xFF );
        SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
    }

    return optimizedImage;
}

In this code you will be able to pass all your images into this to be optimized very seamlessly, but in the case of background/Large images you would need to make sure that this last block of code is changed to something more along the lines of something like this:

//Added some Sudo code

    if( loadedImage != NULL && !isBigImage)
            {
                optimizedImage = SDL_DisplayFormat( loadedImage );        
                SDL_FreeSurface( loadedImage );
            }
            else if(!isBigImage)
            {
                Failure* fail;
                fail = Failure::getInstance();
                fail->failLog(filename);
            }

the isBigImage is the sudo code i added and is a parameter passed in; in certain cases.This will make all your images optimized, smaller(Should make sure they are png files) and will make it so the transparency is only added to small image files so your background does not solw your fps