Archived

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

JAlonso

Fade in SDL

Recommended Posts

see and software fade routine tutorial for directdraw (or non directdraw). search the forums. plenty of actual code right here, heck fade is just a speclized alpha blend. gamedev has tutorials for mmx fade and alpha blend under resources.

Share this post


Link to post
Share on other sites
The following is theoretical - I haven''t tested it nor know that it works:

Copy your screen surface into some other surface.

Now start a little loop that clears the original screen surface to black and then bilts the copied surface onto the original surface, but with a slightly lower alpha value than on the previous loop.


---
cone3d
http://cone3d.gamedev.net
My software never has any bugs - it just generates random featureshello?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I tried this, but it does not work :


SDL_Surface *tmp;

tmp = SDL_CreateRGBSurface (SDL_HWSURFACE,m_PrimarySurface->w, m_PrimarySurface->h,
m_PrimarySurface->format->BitsPerPixel, m_PrimarySurface->format->Rmask, m_PrimarySurface->format->Gmask, m_PrimarySurface->format->Bmask, m_PrimarySurface->format->Amask);

SDL_BlitSurface(m_PrimarySurface, NULL, tmp, NULL);
for (int i = 0; i < 255; i++) {
SDL_SetAlpha(tmp, SDL_SRCALPHA|SDL_RLEACCEL, i);
SDL_BlitSurface(tmp, NULL, m_PrimarySurface, NULL);
Flip();
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
go to the sdl site www.libsdl.org,
go to the games section,
find the site for Maelstrom(it''s an asteroid clone, and a good one at that),
dl the source, it fades in several instances, haven''t looked at the code myself

Share this post


Link to post
Share on other sites
JAlonso - I just went through the same thing. Here''s a bit of code that I wrote using per surface alpha that produces a "fade-out" effect. Quite useful:



Share this post


Link to post
Share on other sites
Sorry. Here's the source again:

  
void fade_out(SDL_Surface *target)
{
/*
target is our target surface, which would normally
be the screen.
*/

SDL_Surface *temp;
temp = SDL_DisplayFormat(target);
if (temp == NULL)
{
printf("SDL_DisplayFormat() failed.\n");
exit(1);
}
/*This starts it out with 50% opacity.*/

SDL_SetAlpha(temp,SDL_SRCALPHA,128);
SDL_BlitSurface(target,NULL,temp,NULL);

for (int i=128; i >= 110; i--)
{
SDL_SetAlpha(temp,SDL_SRCALPHA,i);
SDL_BlitSurface(target,NULL,temp,NULL);
SDL_FillRect(target,NULL,0x000000);
SDL_BlitSurface(temp,NULL,target,NULL);
SDL_Flip(target);
SDL_Delay(20);
}
SDL_FreeSurface(temp);
}


[edited by - dklon on July 24, 2002 1:28:59 AM]

[edited by - dklon on July 24, 2002 1:29:34 AM]

Share this post


Link to post
Share on other sites