This topic is 4084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a tile surface that gets blitted to the screen every turn. The speed of this blit seems to depend a huge amount on the way I create the surface. If I initialise the tile surface like this:
tiles = SDL_CreateRGBSurface(SDL_SWSURFACE, lvlWid*TILEWID,lvlHgt*TILEHGT, 32, rmask, gmask, bmask, amask);

where the masks are given by:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#else
#endif

... it's a huge amount slower when I then blit the surface each frame than just initializing the surface like so:
tiles = SDL_CreateRGBSurface(SDL_SWSURFACE, lvlWid*TILEWID,lvlHgt*TILEHGT, 32, 0, 0, 0, 0);

which is technically wrong? This is rather confusing... is there any reason I'd want to use the correct version?

##### Share on other sites
Looking at the SDL source, if the RMask and Gmask and Bmask are all unspecified and the bpp as 32, you get a 24 bit surface with the following masks:

I may be wrong though, im a bit rusty with my bitwise operations.

##### Share on other sites
Ok, so that would mean no alpha in the pixel info? though presumably I can still use SDL_SetColorKey? Is there a way to speed up blitting doing it with the masks?

##### Share on other sites
Quote:
 Original post by WindhawkOk, so that would mean no alpha in the pixel info? though presumably I can still use SDL_SetColorKey? Is there a way to speed up blitting doing it with the masks?

No alpha, thats right as far as I can see.

SDL_SetColorKey should work.

Speed up with masks? I have no idea, I think thats what SDL_DisplayFormat is for, optimising a surface for blitting to the display format.

##### Share on other sites
If you're looking for a way to speed up your alpha-channel blits, you could look into using an OpenGL-based wrapper like hxRender to do the alpha-blitting for you using hardware-acceleration. It's about 15% faster than SDL's alpha-channel blitting. And the best part about it is that, by setting up your OpenGL context with SDL, you can still use SDL_mixer and SDL_image and all of your other favorite SDL libraries with it.

##### Share on other sites
Thanks, rip-off, the colorkey will do for me for now, so I'll probably just carry on using the 24 bit surface. Presumably I can define 24 bit "*mask" variables, and just use 0 for the amask to create a 24 bit surface properly? so...

#if SDL_BYTEORDER == SDL_BIGENDIAN    const Uint32 rmask = 0xff0000    const Uint32 gmask = 0x00ff00    const Uint32 bmask = 0x0000ff#else    const Uint32 rmask = 0x0000ff    const Uint32 gmask = 0x00ff00    const Uint32 bmask = 0xff0000#endif

Quote:
 Original post by samuraicrowIf you're looking for a way to speed up your alpha-channel blits, you could look into using an OpenGL-based wrapper like hxRender to do the alpha-blitting for you using hardware-acceleration. It's about 15% faster than SDL's alpha-channel blitting. And the best part about it is that, by setting up your OpenGL context with SDL, you can still use SDL_mixer and SDL_image and all of your other favorite SDL libraries with it.

Thanks, samuraicrow, it's not too vital for me at the moment, since I don't really need the alpha channel, and the colorkey will do fine for what I'm doing, but I'll look into that.