 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
kennethdm
Joined: 24 Jan 2006 Posts: 8
|
Posted: Thu May 25, 2006 12:20 am Post subject: screen flickering |
|
|
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: |
#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("test", 0, 1, 1);
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
#define RIJEN 6
#define CIRKELS 4
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
void pauze(int lengte)
{
int i = 0;
for(i=0; i<lengte; i++) {
sceDisplayWaitVblankStart();
}
}
int main(void) {
SetupCallbacks();
initGraphics();
int venster = 0;
SceCtrlData pad; //input
while(1)
{
//begin main loop
if(venster == 0)
{
//kies spelmodus
char buffer[200];
Image* ourImage;
sprintf(buffer, "test.png");
ourImage = loadImage(buffer);
int xafb = 0;
int yafb = 0;
while (xafb < 480)
{
while (yafb < 272)
{
blitAlphaImageToScreen(0 ,0 ,32 , 32, ourImage, xafb, yafb);
yafb += 32;
}
xafb += 32;
yafb = 0;
}
flipScreen();
venster = 1;
while(1)
{
// aantal spelers loop
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_DOWN) {
if(venster == 1) {
venster++;
}
pauze(10);
} else
if(pad.Buttons & PSP_CTRL_UP) {
if(venster == 2) {
venster--;
}
pauze(10);
} else
if(pad.Buttons & PSP_CTRL_CROSS) {
pauze(10);
break;
}
fillScreenRect(RGB(0,50,50),100,50,280,86);
printTextScreen(130,60,"1 Player",RGB(255,255,255));
printTextScreen(130,80,"2 Players",RGB(255,255,255));
if (venster == 1) {
printTextScreen(115,60,"->",RGB(255,255,255));
} else {
printTextScreen(115,80,"->",RGB(255,255,255));
}
flipScreen();
pauze(1);
//einde aantal spelers loop
}
//einde kies spelmodus
}
if(venster == 1)
{
while(1)
{
pauze(10);
}
}
if(venster == 2)
{
while(1)
{
pauze(10);
}
}
//einde main loop
}
return 0;
}
|
|
|
| Back to top |
|
 |
BlackDiamond
Joined: 02 Jul 2005 Posts: 16 Location: Paris, FRANCE
|
Posted: Thu May 25, 2006 12:44 am Post subject: |
|
|
| Shouldn't you load your image in both buffers? (draw, flip, then draw again) |
|
| Back to top |
|
 |
kennethdm
Joined: 24 Jan 2006 Posts: 8
|
Posted: Thu May 25, 2006 12:47 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
Wil
Joined: 23 Feb 2005 Posts: 15 Location: Las Vegas
|
Posted: Thu May 25, 2006 3:01 am Post subject: |
|
|
Draw everything to a single 480x272 (or 512x512) image, and then just draw that single image to screen before you flip. _________________ Wil |
|
| Back to top |
|
 |
Fanjita
Joined: 28 Sep 2005 Posts: 217
|
Posted: Thu May 25, 2006 3:09 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Saotome

Joined: 03 Apr 2004 Posts: 182
|
Posted: Thu May 25, 2006 4:49 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
BlackDiamond
Joined: 02 Jul 2005 Posts: 16 Location: Paris, FRANCE
|
Posted: Thu May 25, 2006 4:58 am Post subject: |
|
|
| Thanks Saotome, that's what I meant. |
|
| Back to top |
|
 |
kennethdm
Joined: 24 Jan 2006 Posts: 8
|
Posted: Thu May 25, 2006 6:56 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|