[SDL] Help with SDL_Convert

Lilith Calbridge lilith at dcccd.edu
Tue May 15 07:34:01 PDT 2007


Thanks for the advice.  That's what I was going for but I seem to recall
having tried such in the past and it not working.  My primary problem in
the past was that I would blit something to the "screen" surface and it
would come out in shades of grey.  Someone suggested the
SDL_ConvertSurface, which cured the problem.  Now I've started building
a static background for a game and in the test phases it doesn't come
out at all.  So I figured on trying the same solution.  I am
encapsulating much of this into classes and the problem may be tied up
in that approach.

BTW, does anyone know if there are any books published on SDL?  My
roommate swears she had one at one time but a thorough search of the
bedroom she filled with books and gaming stuff hasn't turned up an SDL
book.

Thanks,
Lilith

>>> On 5/14/2007 at 9:36 PM, "David Olsen" <jolynsbass at gmail.com>
wrote:
> Well, if your ultimate goal is to simply make your surface blit
quicker to 
> the screen because of it having the same format, I'd suggest using
the 
> SDL_DisplayFormat(surface) function, as it is simpler and directly 
> accomplishes your goal. If you have a per-pixel-alpha surface(from a
.png, 
> for instance), you should use SDL_DisplaySurfaceAlpha(surface).
> 
> You use it like so:
> SDL_Surface * temp = IMG_Load("pic.png"); //or
SDL_LoadBMP("pic.bmp");
> SDL_Surface * s = SDL_DisplayFormatAlpha(temp); //or 
> SDL_DisplayFormat(temp);
> SDL_FreeSurface(temp); //if you really don't need the original
anymore...
> 
> Voila! Your surface, s, is ready for primetime. Hope that helps!
> (really, you should check the return values from the functions, as
per good 
> programming procedure, but this will do in a pinch.)
> -Dave
> 
> ----- Original Message ----- 
> From: "Lilith Calbridge" <lilith at dcccd.edu>
> To: <sdl at lists.libsdl.org>
> Sent: Monday, May 14, 2007 2:06 PM
> Subject: Re: [SDL] Help with SDL_Convert
> 
> 
>>
>>
>>>>> On 5/14/2007 at 1:14 PM, Ulrich Eckhardt <doomster at knuut.de>
>> wrote:
>>> I'll assume you mean SDL_ConvertSurface.
>>
>> Sorry about that.  That will teach me to try to pen messages
between
>> phone calls at the office.
>>
>>> On Monday 14 May 2007 18:38:32 Lilith Calbridge wrote:
>>>> The name SDL_Convert implies that one surface is being converted
to
>>>> another's format.  But in fact it returns a new surface.
>>>
>>> Right, as the documentation says.
>>>
>>>> My situation is that I have a surface that's a fraction of the
size
>> of
>>>> my display surface.  But apparently I need to convert the surface
so
>> that
>>>> when I blit it to the display surface it matches format.
>>>
>>> I don't think so, but for performance reasons I would always
convert
>> loaded
>>> images to the display's format. Other than that, I think that you
can
>> also
>>> blit between surfaces of different formats, it then does the
>> conversion on
>>> the fly.
>>>
>>>> Does that mean that surface designated as "src" in the
documentation
>> should
>>>> be the non-display surface that I need converted to the display
>> surface
>>>> format?
>>>
>>> Yes. You call it with the surface you want to blit to the screen
but
>> with
>>> the
>>> screen's format.
>>
>> Let's say I have a surface called "terrain" and I want to convert it
to
>> the format of "screen".
>>
>> terrain2 =   SDL_Convert Surface (terrain, screen->format,
options);
>>
>> I assume that terrain2 points to a newly created surface and that
>> terrain is still pointing to a valid surface?
>>
>>> Uli
>>
>> -- 
>> Thanks,
>> Lilith
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org 
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org 
> 
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org 
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


More information about the SDL mailing list