SDL vsync?

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

Moderators: cheriff, TyRaNiD

Post Reply
cyberfish
Posts: 19
Joined: Mon May 19, 2008 3:39 pm

SDL vsync?

Post by cyberfish »

Hi,
I have just started experimenting with SDL on the PSP a bit, and I can't seem to get rid of the tearing if the frame rate is high. For example, with something like this:

Code: Select all

Uint32 colors[3];
	
colors[0] = SDL_MapRGB(screen->format, 0xFF, 0, 0);
colors[1] = SDL_MapRGB(screen->format, 0, 0xFF, 0);
colors[2] = SDL_MapRGB(screen->format, 0, 0, 0xFF);
	
int c = 0;
SDL_Event evt;
	
while (true) {
	if (SDL_PollEvent(&evt)) {
		switch (evt.type) {
			case SDL_KEYDOWN:
				break;
			case SDL_QUIT:
				exit(0);
		}
	}
	++c;
	c = c % 3;
	SDL_FillRect(screen, NULL, colors[c]);
	SDL_Flip(screen);
	SDL_Delay(10);
}
It should flash the screen red, green, blue, red, green, blue... at a maximum of 100fps.
However, the result looks like 4 bands of colors flash really fast (tearing). I am guessing it's something to do with vsync, but I am not experienced at all in graphics programming.

If I change SDL_Delay(10) to SDL_Delay(100), all is well.

I am calling SDL_SetVideoMode with "SDL_SWSURFACE | SDL_DOUBLEBUF". Is there anything else I can do?

Thanks for your help
Shapyi
Posts: 95
Joined: Mon Apr 25, 2005 9:31 am

Post by Shapyi »

Code: Select all

sceDisplayWaitVblankStart();
Add that before you call your flip function.
cyberfish
Posts: 19
Joined: Mon May 19, 2008 3:39 pm

Post by cyberfish »

thanks! that fixed it.

Now I see a beautiful flashing white (which is what I expected).
Post Reply