[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

SDL_Flip vs SDL_UpdateRect: what's better/smoother?



Hello, the following code make appear a pull-down menu when the user
move the mouse in the upper part of the screen (screen size =
1024x768). 
My pull-down menu is an image (1024x161) and it appear in the upper
part of the screen in the following way:

- draw last row 
- draw last two rows
- draw last three rows
...
- draw all image

The problem is that using "SDL_Flip" (line #2#) the process is slow
and not very smooth.
Instead, if I use "SDL_UpdateRect" (line #1#), each time updating only
the screen from Y=0 to Y=160, the pull-down animation is very fast and
smooth.

Why SDL_Flip is so slow? I know that it update all the screen, but
it's an hardware process, or not? Am I doing something wrong?
SDL_UpdateRect doesn't wait vertical sync, it isn't?

I also read that the sprite size should be "power of two", is it true?
How much speed I gain doing so and why?

Maybe the problem is that I can't get hardware surface?
I tried this test and it tells me that I can't get it!
Why?!

if ( (screen->flags & SDL_HWSURFACE) != SDL_HWSURFACE ) {

    printf("Can't get hardware surface\n");
    exit(1);
}

---------- Here's the code:

// screen size 1024x768
#define MAX_X 1024
#define MAX_Y 768

...

SDL_Rect raster_src;
SDL_Rect raster_dst;

...

SDL_Surface *raster_bar;
raster_bar=IMG_Load("IMG/bar_upper.png"); // image is 1024x161

...

raster_src.x=0;
raster_src.y=160;
raster_src.w=1024;
raster_src.h=1;
raster_dst.y=0;

while (raster_src.y>=0){
                                   
        SDL_BlitSurface(raster_bar,&raster_src,screen,&raster_dst);

        // #1#
        SDL_UpdateRect(screen, 0, 0, MAX_X, 160);

        // #2#
        //SDL_Flip(screen); 

        raster_src.y--;
        raster_src.h++;
}