Bottom screen Flickering using libctru

Discussion in '3DS - Homebrew Development and Emulators' started by Peanut42, Aug 12, 2015.

  1. Peanut42
    OP

    Peanut42 Member

    Newcomer
    30
    34
    Jun 27, 2015
    Mexico
    Hi

    Another difficult question, I have some flickering in my Paddle Puffle game. Especially when drawing to the bottom screen. I'm using libctru and a loop like this:

    Code:
    while (aptMainLoop () && !done) {
         last_time = svcGetSystemTick ();
         hidScanInput ();
         keys = hidKeysDown ();
         
         if (keys & KEY_START) {
           done = 1;
         }
         
         // Draw all the stuff to the top screen here
         
         //Wait for VBlank
         gspWaitForVBlank();
         
         gfxFlushBuffers();
         gfxSwapBuffers();
         
         // Draw all stuff to the bottom screen here
        
         // Here is the flickering !!!
         now_time = svcGetSystemTick ();
         if (now_time < last_time + FPS) svcSleepThread (last_time + FPS - now_time);
    }
    Some suggestions to avoid the bottom screen flickering?
     
  2. nop90

    nop90 GBAtemp Maniac

    Member
    1,354
    2,036
    Jan 11, 2014
    Italy
    Rome
    There is something broken in ctrulib HW rendering, and if you're using the ctulib console, it uses HW rendering.

    I had similar problems till last week, then there was a rollback on the ctrulib github to solve some HW rendering problems.

    I installed that version and most of the problems are now solved (sometime the flickering starts again, but very seldom).

    Try to update yout ctrulib to fix the problem.

    P.S. : I don't know if the latest commit works fine, i'm abroad with a very bad connection.
     
  3. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,260
    Nov 24, 2014
    Italy
    Bologna
  4. Peanut42
    OP

    Peanut42 Member

    Newcomer
    30
    34
    Jun 27, 2015
    Mexico
    That's my point, I don't know if flush buffers pushes both buffers. I found functions named gspWaitForVBlank0, gspWaitForVBlank1 and gspWaitForVBlank. The macro "gspWaitForVBlank" is an alias for "gspWaitForVBlank0". Don't know what exactly do gspWaitForVBlank1.

    After drawing both screens, should I flush buffers, Wait for VBlank (for both? the 0 and 1) and swapbuffers?
    The bottom screen uses doble buffering too?
     
  5. MRJPGames

    MRJPGames Pretty great guy

    Member
    1,090
    708
    Aug 17, 2013
    Netherlands
    The Netherlands
    gfxFlushBuffers();
    gfxSwapBuffers();
    gspWaitForEvent(GSPEVENT_VBlank0, false);
    The order I use.
     
  6. Peanut42
    OP

    Peanut42 Member

    Newcomer
    30
    34
    Jun 27, 2015
    Mexico
    This is for the Top Screen. This apply for the bottom screen too?
     
  7. MRJPGames

    MRJPGames Pretty great guy

    Member
    1,090
    708
    Aug 17, 2013
    Netherlands
    The Netherlands
    I never had any problems with this, so I would assume so.
     
  8. hippy dave

    hippy dave Butts Butts Megabutts

    Member
    2,569
    1,791
    Apr 30, 2012
    Yeah, you draw both screens, and then swap/flush/wait which does both screens.
     
    Peanut42 likes this.
  9. Peanut42
    OP

    Peanut42 Member

    Newcomer
    30
    34
    Jun 27, 2015
    Mexico
    You were right! The correct order is swap, flush, wait

    No more flickering!

    Thanks for all the responses.
     
  10. Steveice10

    Steveice10 GBAtemp Maniac

    Member
    1,101
    1,641
    Jul 19, 2009
    United States
    Just an FYI, the ctrulib console does NOT use HW rendering, it draws directly to the framebuffer in software.