Skip to content

Instantly share code, notes, and snippets.

@JohnnyonFlame
Created May 24, 2015 13:34
Show Gist options
  • Save JohnnyonFlame/2d26a7f19ac905812061 to your computer and use it in GitHub Desktop.
Save JohnnyonFlame/2d26a7f19ac905812061 to your computer and use it in GitHub Desktop.
fades between image and full white
#include <stdio.h>
#include <math.h>
#include <SDL.h>
#include <SDL_image.h>
int main(int argc, char *argv[])
{
SDL_Surface *vid = SDL_SetVideoMode(320, 240, 32, 0);
SDL_Surface *image = IMG_Load("pepe.png");
SDL_Surface *image2 = IMG_Load("spurdo.png");
image = SDL_ConvertSurface(image, vid->format, 0);
image2 = SDL_ConvertSurface(image2, vid->format, 0);
if (!vid || !image)
{
printf("Image loading/Video setting failed, faggot. %s\n", IMG_GetError());
return -1;
}
while (1)
{
SDL_Event ev;
while (SDL_PollEvent(&ev))
{
switch(ev.type)
{
case SDL_QUIT:
return 0;
default: break;
}
}
SDL_FillRect(vid, NULL, 0);
Uint32 mul_a = (Uint16)((sinf(SDL_GetTicks() / 1000.f)+1.f) * 32767.f);
Uint32 mul_b = mul_a ^ 0xFFFF;
Uint32 c;
Uint8 *dest = vid->pixels;
Uint8 *src = image->pixels;
Uint8 *src2 = image2->pixels;
int i, j;
for (i=0; i<image->h; i++)
{
for (j=0; j<image->w; j++)
{
c = *(Uint32*)src;
*(Uint32*)dest =
(((((c >> 16) & 0xFF) * mul_a) & 0xFF0000) ) | //R 1
(((((c >> 8 ) & 0xFF) * mul_a) & 0xFF0000) >> 8 ) | //G 1
(((((c ) & 0xFF) * mul_a) & 0xFF0000) >> 16); //B 1
c = ((0xFF * mul_b) & 0xFF0000);
*(Uint32*)dest += c | c >> 8 | c >> 16;
//skip color (2 bytes = 16bit)
dest += 4;
src += 4;
src2 += 4;
}
//skip line (line width - width * color depth)
dest += vid->pitch - (image->w * 4);
src += image->pitch - (image->w * 4);
src2 += image->pitch - (image->w * 4);
}
SDL_Flip(vid);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment