Author Topic: SDL2 Issues on 2014-05-05 Toolchain  (Read 4860 times)

Shin-NiL (OP)

  • Posts: 355
    • Shin-NiL's Personal Web Page (Brazilian Portuguese)
SDL2 Issues on 2014-05-05 Toolchain
« on: May 07, 2014, 10:02:03 pm »
Hello guys!

I was very excited with the announcement of SDL2 support in the new toolchain. The First thing I did was try to build the latest version of Solarus engine, but I found issues with the events, none seems to work (keyboard, mouse, joystick), it looks like the window doesn't get focus.

So I decided to create a smaller program as follows:
Code: [Select]
#include <SDL.h> //para uso das funcoes SDL

#define LARGURA 320 //largura da janela do Dingoo
#define ALTURA 240 //altura da janela do Dingoo

int main(int argc, char** argv) //funcao principal
{
    SDL_Surface* tela; //representa a tela do Dingoo
    SDL_Surface* imagem; //representa nossa imagem
    SDL_Rect rectImagem; //representa o retangulo de nossa imagem
    SDL_Event evento; //um evento a ser gerenciado pela SDL
    int fim = 0; //indica o fim do programa

    SDL_Init(SDL_INIT_VIDEO); //inicializa o subsistema de video da SDL
    SDL_ShowCursor(SDL_DISABLE); //não exibe cursor do mouse
   
    SDL_Window *janela = SDL_CreateWindow("Teste",
                          SDL_WINDOWPOS_UNDEFINED,
                          SDL_WINDOWPOS_UNDEFINED,
                          LARGURA, ALTURA,
                          SDL_WINDOW_FULLSCREEN | SDL_WINDOW_INPUT_FOCUS );
   
    //cria o renderer para nossa janela, usando o melhor driver e valores padrão                 
    SDL_Renderer * renderer = SDL_CreateRenderer(janela, -1, 0);

    imagem = SDL_LoadBMP("imagem.bmp");//carrega a imagem do minisd
    if (imagem == NULL)
        SDL_ShowSimpleMessageBox(0, "Erro ao carregar imagem", SDL_GetError(), janela);
   
    //cria a textura em memória da placa de vídeo
    SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, imagem);
       
    SDL_FreeSurface(imagem);
     
    rectImagem.x = 0; //zera as coordenadas x e y da imagem
    rectImagem.y = 0;
    rectImagem.w = 32;
    rectImagem.h = 32;

    while(!fim) //rodaremos até que não seja o fim
    {
        while(SDL_PollEvent(&evento)) //enquanto existir evento
        {
      if( evento.type == SDL_KEYDOWN ) { //verifica se um botão foi pressionado
         switch( evento.key.keysym.sym )
           {
            //move-se 5 pixels, dependendo da direcao
                case SDLK_LEFT: rectImagem.x = rectImagem.x - 5;
                  break;
            case SDLK_RIGHT: rectImagem.x = rectImagem.x + 5;
                  break;
            case SDLK_UP: rectImagem.y = rectImagem.y - 5;
                  break;
            case SDLK_DOWN: rectImagem.y = rectImagem.y + 5;
                  break;
            case SDLK_ESCAPE: printf("FIM\n"); //sai se select for pressionado
                    fim = 1;
                    break;
           }
      }
        }
       
        SDL_RenderClear(renderer);
//copia a textura para o vídeo
SDL_RenderCopy(renderer, texture, NULL, &rectImagem);
//exibe o conteúdo na tela
SDL_RenderPresent(renderer);
    }

    SDL_DestroyTexture(texture);   
    SDL_DestroyRenderer(renderer); 
    SDL_DestroyWindow(janela);

    SDL_Quit(); //encerra a SDL

    return 0;
}

But the issue persists :(

Another thing I noticed is that the command
Code: [Select]
/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/bin/sdl2-config --cflagsreturns
Code: [Select]
-I/usr/include/SDL2 -D_REENTRANT
Is that the expected behavior on the "experimental" SDL2 release or I'm doing something wrong?

Thanks!
« Last Edit: May 07, 2014, 10:05:56 pm by Shin-NiL »

pcercuei

  • Posts: 1731
    • My devblog
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #1 on: May 07, 2014, 11:29:34 pm »
Did you try with SDL_SetKeyboardFocus()?

I can reproduce the problem with sdl2-config, it's a bug allright.

Shin-NiL (OP)

  • Posts: 355
    • Shin-NiL's Personal Web Page (Brazilian Portuguese)
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #2 on: May 08, 2014, 01:38:42 am »
Didn't work :'(

Code: [Select]
error: ‘SDL_SetKeyboardFocus’ was not declared in this scope
As I didn't find any documentation about this function, I did a  "grep SDL_SetKeyboardFocus * -R -i"  inside /opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 but nothing was found.

pcercuei

  • Posts: 1731
    • My devblog
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #3 on: May 17, 2014, 11:15:59 am »
Bug fixed.

Shin-NiL (OP)

  • Posts: 355
    • Shin-NiL's Personal Web Page (Brazilian Portuguese)
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #4 on: May 17, 2014, 12:43:40 pm »
Thanks for your hard work, pcercuei :)

srmeier

  • Posts: 4
    • Personal site
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #5 on: July 09, 2014, 05:28:44 am »
Shin-NiL can you please explain how you resolved this issue?

None of my inputs seem to get polled and SDL_GetWindowGrab returns false, which leads me to believe I may have a similar issue as you have here.

Thanks

pcercuei

  • Posts: 1731
    • My devblog
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #6 on: July 09, 2014, 09:34:39 am »
We will release a new firmware with fixed SDL2 libs (and other things) probably next week.

srmeier

  • Posts: 4
    • Personal site
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #7 on: July 09, 2014, 12:46:32 pm »
very cool, thanks pcercuei!

Shin-NiL (OP)

  • Posts: 355
    • Shin-NiL's Personal Web Page (Brazilian Portuguese)
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #8 on: July 09, 2014, 05:18:35 pm »
Shin-NiL can you please explain how you resolved this issue?

None of my inputs seem to get polled and SDL_GetWindowGrab returns false, which leads me to believe I may have a similar issue as you have here.

Thanks
I didn't, I'm waiting for the next release too ;)

vonzippenstein

  • Posts: 49
    • vonzippenstein.com
Re: SDL2 Issues on 2014-05-05 Toolchain
« Reply #9 on: July 11, 2014, 08:36:16 pm »
We will release a new firmware with fixed SDL2 libs (and other things) probably next week.

Take your time and no pressure but YES!! I am too excited for this next release. It means Love2D!