screen flickering

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
kennethdm
Posts: 8
Joined: Tue Jan 24, 2006 3:18 am

screen flickering

Post by kennethdm »

Hi, I am currently updating my program to use background images instead of just plain rectangles filled with a certain color. I'm no psp expert on this, so I kept it simple for starters, the next piece of code just figures out what game mode the player wants, before the loop, an image is loaded and put on the screen, but for some reason, when i use an image as background, the screen flickers every time flipScreen is called, a problem which I didn't have when I just used plain rectangles (no I am not reloading the image every time, I'm not THAT stupid ;))

anyway, here's my code, any possible suggestions anyone?

P.S. the "pauze" function is just something that calls sceDisplayWaitVblankStart(); for a certain amount of time so the HOME button can be pushed

Code: Select all

#include <stdlib.h> 
#include <psppower.h> 
#include <pspdisplay.h> 
#include <pspctrl.h> 
#include <pspkernel.h> 
#include <pspdebug.h> 
#include <pspgu.h> 
#include <png.h> 
#include <stdio.h> 

#include "graphics.h" 
#include "functies.h" 

PSP_MODULE_INFO&#40;"test", 0, 1, 1&#41;; 

#define RGB&#40;r, g, b&#41; &#40;&#40;r&#41;|&#40;&#40;g&#41;<<8&#41;|&#40;&#40;b&#41;<<16&#41;&#41; 
#define MAX&#40;X, Y&#41; &#40;&#40;X&#41; > &#40;Y&#41; ? &#40;X&#41; &#58; &#40;Y&#41;&#41; 
#define RIJEN 6 
#define CIRKELS 4 

/* Exit callback */ 
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123; 
          sceKernelExitGame&#40;&#41;; 
          return 0; 
&#125; 

/* Callback thread */ 
int CallbackThread&#40;SceSize args, void *argp&#41; &#123; 
          int cbid; 

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;; 
          sceKernelRegisterExitCallback&#40;cbid&#41;; 

          sceKernelSleepThreadCB&#40;&#41;; 

          return 0; 
&#125; 

/* Sets up the callback thread and returns its thread id */ 
int SetupCallbacks&#40;void&#41; &#123; 
          int thid = 0; 

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;; 
          if&#40;thid >= 0&#41; &#123; 
                    sceKernelStartThread&#40;thid, 0, 0&#41;; 
          &#125; 

          return thid; 
&#125; 

void pauze&#40;int lengte&#41; 
&#123; 
int i = 0; 

  for&#40;i=0; i<lengte; i++&#41; &#123; 
    sceDisplayWaitVblankStart&#40;&#41;; 
  &#125;      
&#125; 

int main&#40;void&#41; &#123; 

SetupCallbacks&#40;&#41;; 
initGraphics&#40;&#41;; 

int venster = 0; 
SceCtrlData pad;  //input 

while&#40;1&#41; 
&#123; 
//begin main loop 

        if&#40;venster == 0&#41; 
        &#123; 
        //kies spelmodus 
            char buffer&#91;200&#93;; 
             Image* ourImage; 
             sprintf&#40;buffer, "test.png"&#41;; 
             ourImage = loadImage&#40;buffer&#41;; 
             int xafb = 0; 
             int yafb = 0; 

             while &#40;xafb < 480&#41; 
             &#123; 
               while &#40;yafb < 272&#41; 
               &#123; 
                  blitAlphaImageToScreen&#40;0 ,0 ,32 , 32, ourImage, xafb, yafb&#41;; 
                  yafb += 32; 
               &#125; 
               xafb += 32; 
               yafb = 0; 
             &#125; 
             flipScreen&#40;&#41;; 
              
             venster = 1; 
          
             while&#40;1&#41; 
             &#123; 
             // aantal spelers loop 
                 
           sceCtrlReadBufferPositive&#40;&pad, 1&#41;; 
           if&#40;pad.Buttons & PSP_CTRL_DOWN&#41; &#123; 
            if&#40;venster == 1&#41; &#123; 
              venster++; 
            &#125; 
            pauze&#40;10&#41;; 
           &#125; else  
           if&#40;pad.Buttons & PSP_CTRL_UP&#41; &#123; 
            if&#40;venster == 2&#41; &#123; 
              venster--; 
            &#125; 
            pauze&#40;10&#41;; 
           &#125;  else  
           if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123; 
            pauze&#40;10&#41;; 
            break; 
           &#125; 
           
           fillScreenRect&#40;RGB&#40;0,50,50&#41;,100,50,280,86&#41;; 
           printTextScreen&#40;130,60,"1 Player",RGB&#40;255,255,255&#41;&#41;; 
           printTextScreen&#40;130,80,"2 Players",RGB&#40;255,255,255&#41;&#41;; 
           if &#40;venster == 1&#41; &#123; 
            printTextScreen&#40;115,60,"->",RGB&#40;255,255,255&#41;&#41;; 
           &#125; else &#123; 
            printTextScreen&#40;115,80,"->",RGB&#40;255,255,255&#41;&#41;; 
           &#125; 
           flipScreen&#40;&#41;; 
           pauze&#40;1&#41;; 
           //einde aantal spelers loop 
          &#125; 
                 
        //einde kies spelmodus 
        &#125; 

        if&#40;venster == 1&#41; 
        &#123; 
          while&#40;1&#41; 
          &#123; 
            pauze&#40;10&#41;; 
          &#125; 
        &#125; 
        
        if&#40;venster == 2&#41; 
        &#123; 
          while&#40;1&#41; 
          &#123; 
            pauze&#40;10&#41;; 
          &#125; 
        &#125; 

//einde main loop 
&#125; 



          return 0; 
&#125;
BlackDiamond
Posts: 16
Joined: Sat Jul 02, 2005 7:31 pm
Location: Paris, FRANCE

Post by BlackDiamond »

Shouldn't you load your image in both buffers? (draw, flip, then draw again)
kennethdm
Posts: 8
Joined: Tue Jan 24, 2006 3:18 am

Post by kennethdm »

BlackDiamond wrote:Shouldn't you load your image in both buffers? (draw, flip, then draw again)
I don't think I follow you, can you elaborate your suggestion further?
Wil
Posts: 15
Joined: Wed Feb 23, 2005 7:30 pm
Location: Las Vegas
Contact:

Post by Wil »

Draw everything to a single 480x272 (or 512x512) image, and then just draw that single image to screen before you flip.
Wil
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

You're flipping the screen immediately after blitting the image, but before drawing the other output.

Wait till you've drawn everything, then flip.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

Nah, it's even simpler ;)

You have two buffers. You draw the background to one of the buffers. Then you go into the main loop and flip between those two buffers, the one with the background image and the empty/black one, that causes the screen to flicker.
The solution shouldn't be that hard to find out...

OK, a little hint: draw the background image to both buffers ;)
infj
BlackDiamond
Posts: 16
Joined: Sat Jul 02, 2005 7:31 pm
Location: Paris, FRANCE

Post by BlackDiamond »

Thanks Saotome, that's what I meant.
kennethdm
Posts: 8
Joined: Tue Jan 24, 2006 3:18 am

Post by kennethdm »

thnx all, had figured it out before reading all this, reply took too long (well, not really, but I couldn't wait :)), anyway, thnx for the effort
Post Reply