View Full Version : SDL questions
Robert Cummings
05-03-2006, 02:55 AM
Hiya,
Based on what svero said, I thought it would be wise to get SDL in as a safety measure. My current game platform is Blitzmax which is hw accelerated quads. I'll be using SDL to fall back on.
However SDL is no picnic! I would appreciate it if someone would be kind enough to give me a few pointers on how to do stuff faster. Tips and tricks are welcome!
Also not sure how to switch from windowed to fullscreen and vice versa. WM_WINDOWED is broken in windows :)
Mainly looking for speed tips and general "gotchas" in SDL that can catch a man unawares.
Thanks in advance!
PeterM
05-03-2006, 05:05 AM
There's a SDL_ToggleFullscreen or something, that unfortunately just doesn't work on Windows. You have to create a new window manually.
I only use software surfaces, because alpha blending using hardware ones is slow (DirectDraw doesn't support alpha).
In my experience, palettised surfaces are fastest to blit from, though YMMV.
Robert Cummings
05-03-2006, 05:26 AM
If its no trouble, could you please post a little snippet as to what you mean by "palettised surfaces are fastest to blit from, though YMMV" - I'd like to try this out and I am just beginning with SDL, many thanks!
PeterM
05-03-2006, 05:32 AM
No snippet needed, just ensure that the image file you're loading isn't true colour, but 8-bit palettised instead.
Many sites recommend converting surfaces to the display format using SDL_DisplayFormat, but I would recommend only doing that for surfaces which for some reason you can't have a palettised version of instead.
To be honest though, if you're new to SDL don't worry quite yet about getting optimal performance - just get things working first.
Hope this helps,
Pete
Robert Cummings
05-03-2006, 05:38 AM
Thanks for the advice! I've got the basic display up and running. All my source media are 32bit PNG with alpha (for the 3D engine) but what happens is, my game caches these as 640x480x32bit and saves as png. I might as well go the next step and save the cached version as 8bit?
If SDL opens a 32 bit screen and blits an 8bit palletised texture, will I still recieve that speed gain?
PeterM
05-03-2006, 05:48 AM
If your surfaces have an alpha channel, and not just color key, you will be better using a surface format with alpha (SDL_DisplayFormatAlpha), because you will probably lose the alpha channel on conversion to 8-bit.
But plain surfaces (no alpha channel) will be fastest as palettised, regardless of the screen type. This is because the savings in memory bandwidth trump the cost of the on-the-fly conversion from 8-bit to your display format.
Gilzu
05-03-2006, 05:55 AM
Make sure that every surface you blit from will be of the same format you're blitting to.
Blitting a surface of the same format (and from the same memory type - hw/sw) is about 10000% faster.
My code ran at about 12 FPS, and when I used that simple snippet to change *every* surface i intend to blit from to the main surface's format, it jumped to 100 FPS.
SDL_Surface *LoadSpriteDF(const char *FileName)
{
SDL_Surface *tempSurface;
SDL_Surface *AnotherSurface;
tempSurface = SDL_LoadBMP(FileName);
if (tempSurface == NULL)
return NULL;
SDL_SetColorKey(tempSurface,SDL_SRCCOLORKEY|SDL_RL EACCEL,SDL_MapRGB(tempSurface->format,255,128,0));
AnotherSurface = SDL_DisplayFormat(tempSurface);
SDL_FreeSurface(tempSurface);
return AnotherSurface;
}
Robert Cummings
05-20-2006, 04:03 PM
Thank you for your kind support. I have my game running at a healthy 30fps now on the target hardware. Would be nice to go higher, but I guess we'll make do :)
Robert Cummings
05-20-2006, 05:40 PM
Hi...
I just tried saving 256 colour PNGs instead (just to test) with pink as the mask colour and it seems to be a bit slower, contrary to the advice I got at the top of this thread?
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.