Hardware surfaces Again

Hi Guys
I have implemented some code to make hardware surfaces, but i am
not sure if i have it right so could someone look at this for me, also I
have had to use SDL_DisplayFormatAlpha or everything that moved on the
screen left trails which all though they looked good, they were
obviously not right. I also remember i think it was Torsten saying don’t use
SDL_DisplayFormatAlpha so whats right whats wrong and what can i do to make
use of the hardware for blitting with and without alpha channels)

SDL_Surface * LoadSurfaceVideoMem(char * FileName)
{
SDL_Surface * VideoMemSurface;
// load the image
SDL_Surface * TempSurface =
SDL_DisplayFormatAlpha(IMG_Load(FileName));
// create a hardware surface
VideoMemSurface =
SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA
|SDL_ASYNCBLIT | SDL_HWACCEL , TempSurface->w, TempSurface->h, 32, RMASK,
GMASK, BMASK ,AMASK));
// copy the surface pixels
CopySurface(TempSurface, VideoMemSurface);
SDL_FreeSurface(TempSurface);
return VideoMemSurface;
}

Thanks in advance, the past and the present,

Trish x

“Patricia Curtis” <patricia.curtis at gmail.com> wrote:

also I have had to use SDL_DisplayFormatAlpha or everything that
moved on the screen left trails which all though they looked good,
they were obviously not right.

this is most likely due to a very common error not to
delete/refresh/whatever the background and has nothing to do with
alphablending in the first place. unless i misundersand things here.

I also remember i think it was Torsten
saying don’t use SDL_DisplayFormatAlpha so whats right whats wrong
and what can i do to make use of the hardware for blitting with and
without alpha channels)

the real question is if SDL_DisplayFormatAlpha() will always return an
SWSURFACE even you feed it a SDL_HWSURFACE. the procedure torsten
suggested was create an RGBA hardware surface with

SDL_CreateRGBASurface(SDL_HWSURFACE, w, h, 0, 0, 0, 0);
(let SDL figure the last four parameters)

and blit the surface returned form LoadImage onto your newly created
one, but switch off per pixel alpha blending first, otherwise the blit
will deploy the alpha instead of copying it. IIRC this is documented
rather well in the SDL online docu.

hope this helps …
clemens

I think that will leak memory =). SDL_DisplayFormatAlpha copies a
surface, so this function has 2 places where a surface is copied but
the original is never freed. In addition to which you pass the
HW_SURFACE you create back to SDL_DisplayFormatAlpha again, thus you
cannot be sure its in video memory (depending on what
DisplayFormatAlpha does internally). Finally you have no guarantees
that SDL_CreateRGBSurface will return a HW_SURFACE anyway. You can
check by inspecting surface->flags.

An quick peek at surface.c in the SDL source (1.2) says that unless
the SDL_VideoInfo says that we have hardware accelerated alpha blits
(blit_hw_A) then the surface will go in system memory.
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fVideoInfo

You have been warned that SDL (1.2 again) (allegedly) does not have
support for hardware accelerated alpha blits? You could see a slow
down by having any of your surfaces in video memory if you are
blending with them.

Bob Pendleton’s articles on SDL are must reads, in your case take a
look at the hardware surface one in particular:
http://www.oreillynet.com/articles/author/1205

Have you tested and compared performance when surfaces are in and out
of video memory, and the effect SDL_DisplayFormatAlpha has in each
case?

If your program depends heavily on fast alpha blending then you may
find that opengl would probably be more suitable.

Hope this is helpful…On 08/08/07, Patricia Curtis <patricia.curtis at gmail.com> wrote:

Hi Guys
I have implemented some code to make hardware surfaces, but i am
not sure if i have it right so could someone look at this for me, also I
have had to use SDL_DisplayFormatAlpha or everything that moved on the
screen left trails which all though they looked good, they were obviously
not right. I also remember i think it was Torsten saying don’t use
SDL_DisplayFormatAlpha so whats right whats wrong and what can i do to make
use of the hardware for blitting with and without alpha channels)