[SDL] Why does the rectangle move so slowly and blink?
newbie
beginmail at 126.com
Tue Aug 3 16:44:04 PDT 2004
And when my test code was executed,most of mem(swap+physical mem) was used!
What should I do?
On 16:02 Tue 03 Aug , Donny Viszneki wrote:
> Well I don't know anything about your hardware so I can't really judge
> what the performance SHOULD be like, however you might want to try
> creating the rectangle on a separate surface and blitting it. I don't
> believe SDL_FillRect offers any sort of acceleration (someone please
> correct me if I'm wrong.)
>
> Also, you probably don't want to update two rects separately, that is
> the source of your blinking. Instead of using SDL_UpdateRect, use
> SDL_UpdateRects. Or one better, actually use the backbuffer you
> requested with SDL_DOUBLEBUF, and call SDL_Flip some time!
>
> On Aug 3, 2004, at 3:47 PM, newbie wrote:
>
> >For movement,I use SDL_FillRect to fill the current rect in new color
> >then
> >background color.Although the usleep function was commented,the
> >rectangle
> >still moved very slowly and blinked greatly.What should I do to speed
> >up it and eliminate the blinking?
> >gentoo linux,libsdl-1.2.7-r2,kernel 2.6.7.
> >here is test code:
> >-----------------------------------------------------------------------
> >------
> >#include <stdlib.h>
> >#include <unistd.h>
> >#include <SDL/SDL.h>
> >
> >/*
> > * Return the pixel value at (x, y)
> > * NOTE: The surface must be locked before calling this!
> > */
> >Uint32 getpixel(SDL_Surface *surface, int x, int y)
> >{
> > int bpp = surface->format->BytesPerPixel;
> > /* Here p is the address to the pixel we want to retrieve */
> > Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
> >
> > switch(bpp) {
> > case 1:
> > return *p;
> >
> > case 2:
> > return *(Uint16 *)p;
> >
> > case 3:
> > if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
> > return p[0] << 16 | p[1] << 8 | p[2];
> > else
> > return p[0] | p[1] << 8 | p[2] << 16;
> >
> > case 4:
> > return *(Uint32 *)p;
> >
> > default:
> > return 0; /* shouldn't happen, but avoids warnings */
> > }
> >}
> >
> >main(int argc, char *argv[])
> >{
> >
> > SDL_Surface *screen;
> > int W = 640,H = 480,bpp = 8;
> > int x,y;
> > SDL_Rect dstrect;
> > Uint32 color;
> >
> > /* Initialize the SDL library */
> > if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
> > fprintf(stderr,
> > "Couldn't initialize SDL: %s\n", SDL_GetError());
> > exit(1);
> > }
> >
> > /* Clean up on exit */
> > atexit(SDL_Quit);
> >
> > /*
> > * Initialize the display in a 640x480 bpp-bit palettized mode,
> > * requesting a software surface
> > */
> > /* Have a preference for bpp-bit, but accept any depth */
> > screen = SDL_SetVideoMode(W, H, bpp,
> > SDL_HWSURFACE|SDL_ANYFORMAT|SDL_DOUBLEBUF);
> > if ( screen == NULL ) {
> > fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
> > SDL_GetError());
> > exit(1);
> > }
> >
> >
> > for(x = 0,y = 0;(x<W) && (y<H);x++){
> > dstrect.x = x;
> > dstrect.y = y;
> > dstrect.w = 100;
> > dstrect.h = 100;
> > color=getpixel(screen,x,y);
> > SDL_FillRect(screen,&dstrect,0xfa9d31);
> > SDL_UpdateRect(screen,x,y,100,100);
> > SDL_Flip(screen);
> > //usleep(1e2);
> > SDL_FillRect(screen,&dstrect,color);
> > SDL_UpdateRect(screen,x,y,100,100);
> > y ++;
> > }
> >
> >}
> >-----------------------------------------------------------------------
> >-------
> >Best Regards,
> >
> >
> >
> >_______________________________________________
> >SDL mailing list
> >SDL at libsdl.org
> >http://www.libsdl.org/mailman/listinfo/sdl
> >
> >
> - Donny Viszneki
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list