Archived

This topic is now archived and is closed to further replies.

sdlprorammer

about 2 SDL functions

Recommended Posts

I have read the documentation, but i don''t understand the difference between: SDL_Displayformat() and SDL_BlitSurface(); ??????? since both of the copy an image ( surface ) from somewhere to somewhere else. So, what''s their difference? thanks in advance...

Share this post


Link to post
Share on other sites
Blit surface blits the surface... simple ebough. Display Format changes the color information of the surface into the format that the buffer uses. Doing so ahead of time saves time on the actual blitting.

for more info, carefully read the sdl docs. They are simple and well explained. They will answer most of your questions.

http://www.libsdl.org/intro/toc.html

Share this post


Link to post
Share on other sites
SDL_DisplayFormat() is essentially a shortcut for SDL_ConvertSurface() followed by a SDL_BlitSurface(). It automatically converts the surface into a surface with the format of the display surface and then copies the image onto the new display-compatible surface. This is probably something you want to do just once after you load a bitmap onto a surface.

Otherwise you would have to query the format of the display surface, give the format information to SDL_ConvertSurface(), and do a SDL_BlitSurface() to get the image onto the converted surface.

SDL_DisplayFormat() will take longer than SDL_BlitSurface(), because there is new surface generation and format conversion going on as well.

[edited by - MonkeyCookie on May 26, 2004 12:17:06 PM]

[edited by - MonkeyCookie on May 26, 2004 12:19:11 PM]

Share this post


Link to post
Share on other sites
i don''t understand :..( i read the docs

" Display Format changes the color information of the surface into the format that the buffer uses. "
what do u mean??????????????????????????? and what do you mean with "format"????

blit surface will color each pixel from one surface with the color of each pixel from the other surface. right? isn''t that what displayFormat will do too???
thanks...

Share this post


Link to post
Share on other sites
from the docs:
SDL_BlitSurface — This performs a fast blit from the source surface to the destination surface.
blit means something like drawing, it ''draws'' the pixels from source surface on the destination surface (ie:from image to screen)


from the docs:
"SDL_DisplayFormat() — Convert a surface to the display format"
display format in this case is color depth of your video surface

.. so if you have, say, an 8bit (256 colors) bitmap which you load with SDL_LoadBMP() and draw it on your screen (with SDL_BlitSurface()), SDL will have to convert those 8bit color values into 32bit before drawing on screen (or some other surface wich has different color depth) and that takes some time - thats where SDL_DisplayFormat() comes in handy, it will convert your surface to the same color depth used by your video display, move the surface in video memory if you set the SDL_HWSURFACE flag in SDL_SetVideoMode()... so in your image loading routine do something like:
...
temp=SDL_LoadBMP( file );
surf=SDL_DisplayFormat( temp );
SDL_FreeSurface( temp );
...
so SDL doesn''t have to convert to a different format at drawing, which takes some time..


SDL_BlitSurface() is for ''drawing'' surfaces onto other surfaces, SDL_DisplayFormat() is for changing the color depth of the surface to the one used by the video display, which makes drawing on screen faster.

hope this helps

Share this post


Link to post
Share on other sites