More Hw Accelerated Sdl Problems And Questions


zacaj

void main()
Joined
Apr 3, 2007
Messages
362
Age
29
Location
NY
Website
zacaj.com
Ive been looking for more ways to speed up my game using Hardware accelerated SDL, I have a 16bpp, SDL_HWSURFACE|SDL_DOUBLEBUF SetVideoMode, and all of my small copies are 16x16 sprites. Lots of my sprites have transparent parts, and Im loading them with IMG_Load as png files. It said to convert all surfaces Im copying to the main screen to the same format, my function is this: CODE

SDL_Surface *IMG_Load3(char *str)
{
temp = IMG_Load(str);
tem2 = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return tem2;
}

But all my transparent pixels are white or black, and some have a white line on the right edge. Is there a way around this?

Also: are there any other things I can do to speed it up?
 
zacaj said:
Ive been looking for more ways to speed up my game using Hardware accelerated SDL, I have a 16bpp, SDL_HWSURFACE|SDL_DOUBLEBUF SetVideoMode, and all of my small copies are 16x16 sprites. Lots of my sprites have transparent parts, and Im loading them with IMG_Load as png files. It said to convert all surfaces Im copying to the main screen to the same format, my function is this: CODE

SDL_Surface *IMG_Load3(char *str)
{
temp = IMG_Load(str);
tem2 = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return tem2;
}

But all my transparent pixels are white or black, and some have a white line on the right edge. Is there a way around this?

Also: are there any other things I can do to speed it up?
I recommend the lazy foo tutorials if you havnt come across them already.
Thats code looks fine.

Check this out for color keying: http://lazyfoo.net/SDL_tutorials/lesson05/index.php

From the code youve shown, thats the correct method for converting the images, theres not much you can do to make that faster. You can decide when to load bitmaps, like before your game really starts and gets intensive.
 
Last edited by a moderator:
You need to use SDL_DisplayFormatAlpha instead of SDL_DisplayFormat
 
chris_r said:
You need to use SDL_DisplayFormatAlpha instead of SDL_DisplayFormat
Nah, you don't need to. You do, however, need to call SDL_DisplayFormat and then call SDL_SetColorKey with the correct color for your transparent pixels.

And regarding 16bpp w/ alpha effect: I believe you can set an over-all alpha property for an entire surface but you definitely can't have an alpha channel where each pixel has its own alpha value. I've never tried this to see, but it certainly would disallow the hardware blitter from handling blits of that surface.
 
Last edited by a moderator:
Well I actually did my first SDL project the other week and that was a problem I had with transparent pngs. SDL_DisplayFormatAlpha fixed it. As for 16 bit, that probably also need to be changed to 24 bit.

But I definitely had the same problem and that's how I fixed it.
 
SDL_DisplayFormatAlpha seems to have fixed it.... How many lines of code does the average homebrew game have?
 
chris_r said:
Well I actually did my first SDL project the other week and that was a problem I had with transparent pngs. SDL_DisplayFormatAlpha fixed it. As for 16 bit, that probably also need to be changed to 24 bit.
It only needs to be changed to 24-bit if you really do, indeed, need alpha blending in any of your blits. Key word being blending. If you change everything to 24-bit and start using alpha channels, everything is going to become quite a bit slower because you've a.) more than doubled your memory bandwidth requirements (24-bit framebuffer + 8-bit alpha channel + 1 32-bit read before every framebuffer pixel write can occur) b.) increased your cpu load c.) eliminated any chance of using the hardware blitter

On a real PC, it wouldn't be much of an issue because the 2D accelerator in your graphics card knows how to accelerate alpha-channel 32bpp blits. Your GP2X has no idea what to do with them, however, and everything must be done in software and it is dog-slow.

Now, if you really do need alpha blending, by all means, use it. I do use it occasionaly for stuff like menus when there is no action taking place. If all you need is color-keyed blits, as implied by the first post, and speed is an issue, as also implied by the first post, you need to not use SDL_DisplayFormatAlpha and instead start to figure out how SDL_SetColorKey works:

This is code assuming that your colorkey pixel value is magenta:

CODE

// SOME CODE WHERE YOU LOAD A PNG INTO SDL_Surface *temp;
// BLAH BLAH

dest = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
if (!dest)
die("%s", SDL_GetError());
SDL_SetColorKey(dest, SDL_SRCCOLORKEY, SDL_MapRGB(dest->format, 255, 0, 255));



If you are still having problems, I think you should make sure your sprite .PNGs are flattened, and don't have alpha channels, just a solid colorkey background color like magenta.
 
Last edited by a moderator:
SQuack I think you picked up this. Transparecy with bitmaps can two things. Either completly transparent (which is color keying) and semi-tranparent(which is alpha blending).
In my stuff ive never bothered to use alpha as like SQuack said everything becomes software driven (which is slow).
 
Senor Quack said:
Explanation
I see, thanks for that. I only made a game for the pc so obviously speed wasn't an issue, but if I ever make a game for the gp2x then I will take that into consideration.
 
Last edited by a moderator:
Sphinxter said:
I just don' t see that big a performance hit in 24 bit color vs. 16, totally worth it.
also consider too the more bits means more memory. You may never run into this sense it sounds like its a 2d game.
 
Last edited by a moderator:
Back
Top