[SDL] How to accelerate

wgkun at mailst.xjtu.edu.cn wgkun at mailst.xjtu.edu.cn
Mon Dec 8 22:26:01 PST 2003


Hello!
I have to program for a video system under linux
which gathers video data from CCD camera and displays.I
have completed the driver for gathering card. But because
 I'm a newbie to video programming, I have some difficults.
The system needs display 25-50 frames per second.Each frame can be
1024*1024 or 512*512 with 8 bits per pixel.The video data
are all grayscale.A friend introduced SDL to me.And I have
made a test.Everything is ok but the display speed.
Following are my main test codes:
...
	SDL_Color colors[256];
	for (i = 0; i < 256; i++) {
		colors[i].r = colors[i].g = colors[i].b = i;
	}

	if (SDL_Init(SDL_INIT_VIDEO)==-1) {
	   ...
	}

	screen = SDL_SetVideoMode(..., SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);

	src = SDL_CreateRGBSurface(SDL_SWSURFACE,...);

	result = SDL_SetColors(screen, colors, 0, 256);

	result =  SDL_SetColors(src[0], colors, 0, 256);
	int n = 0;
	int speed = 0;
	Uint32 stime = SDL_GetTicks();

	while(n < 1000) {
		if (SDL_MUSTLOCK(src)) {
			if (SDL_LockSurface(src)<0)
				fexit();
		}

		...mydrawingfunction which draws a frame by pixel
		with two for loop
		
		if (SDL_MUSTLOCK(src))
			SDL_UnlockSurface(src);

		SDL_BlitSurface(src, NULL, screen, NULL);

		SDL_UpdateRect(screen, 0, 0, 0, 0);
		n = SDL_GetTicks() - stime;
		speed ++;
	}

When displaying 512*512 frames, the speed can only reach 26-32 frames per second.
The SDL_GetVideoInfo() tells the hw_available and blit_* are all false and no
video_mem.
I use a nvidia geforce2 mx video card and have installed the official drvier.And
mplayer runs fluently with this card.My system is RH 9.0 and I install SDL just
with ./configure --enable-nanox-share-memory --enable-nanox-direct-fb
and make/make install.
How can I get hardware acceleration for SDL?
Or should I change the codes to accelerate?
Any help is preciated.





More information about the SDL mailing list