Bad colors when testing simple code in android phone

Hello
I am testing this very simple SDL2 code in an android phone (Samsung Galaxy S III)

The code runs perfectly in win32. However in the Galaxy S3:

1st appears the color BLUE (the right color) for less than 1 second and then immediately it changes to YELLOW.

The same thing happens when I try other colors. Never shows the right color.
I am using SDL2-2.0.8 and ubuntu 16.04

What I is wrong ?

#include <SDL.h>

int main(int args, char* argvs[])
{
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;
    int isRunning = 1;
    SDL_Event event;
     int dx = 800, dy = 600;

    if (SDL_Init( SDL_INIT_EVERYTHING ) != -1) {

          if (SDL_GetCurrentDisplayMode(0, &displayMode) == 0) {
               dx = displayMode.w;
               dy = displayMode.h;
          }

          window = SDL_CreateWindow( "SDL 2 Test",
                      SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                      dx, dy, SDL_WINDOW_SHOWN );

          if (window != NULL) {

               renderer = SDL_CreateRenderer( window, -1,
                       SDL_RENDERER_ACCELERATED );

               if (renderer != NULL) {

                    while (isRunning) {

                         if (SDL_PollEvent( &event )) {
                              if (event.type == SDL_QUIT)
                                   isRunning = 0;
                         }

                        /*  Must show BLUE color.  However after less then 1 second it turns to YELLOW */
                         SDL_SetRenderDrawColor( renderer, 0, 0, 255,    SDL_ALPHA_OPAQUE );   
                         SDL_RenderClear( renderer );

                         SDL_RenderPresent( renderer );

                         SDL_Delay( 100 );
                    }
                    SDL_DestroyRenderer( renderer );
               }
               SDL_DestroyWindow( window );
          }
          SDL_Quit( );
     }
     return (0);
}

Could it be this (which seems to affect specifically Samsung devices)? If so, some people report finding that this code provides a solution (added before the call to SDL_CreateWindow()):

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

Thanks! It works. I had the same problem when displaying a texture and this solve it, too.

1 Like