Emulation of false colors.

How to create some false colors due to illusion.

Dithering

See version :

Pas de dépendances

Download :

#include <sdl/sdl.h>

#ifdef WIN32
#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"sdlmain.lib")
#endif

void waitkey()            // attend qu'on appuie sur ESC
{
    SDL_Event event;
    while(1)            // boucle
    {
        while(SDL_PollEvent(&event))        // aquisition d'evenement
        {
            if (event.type == SDL_KEYDOWN)  // on appuie sur une touche ?
            {
                if (event.key.keysym.sym == SDLK_ESCAPE) return;  // c'est "ESC" ?
            }
        }
        SDL_Delay(1);
    }
}

void SDL_PutPixel32(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
    Uint8 *p = (Uint8*)surface->pixels + y * surface->pitch + x * 4;
    *(Uint32*)p = pixel;
}

void Dithering(SDL_Surface *surface, int x, int y)
{
    unsigned long couleur1 = 0xFF0000;
    unsigned long couleur2 = 0xFFFFFF;
    int i,j;
    for(j=0;j<200;j++)
        for(i=0;i<x;i++)
        {
            SDL_PutPixel32(surface,i,j,couleur1);
        }
    for(j=200;j<400;j++)
        for(i=0;i<x;i++)
        {
            if ((i+j)%2)
                SDL_PutPixel32(surface,i,j,couleur1);
            else
                SDL_PutPixel32(surface,i,j,couleur2);
        }
    for(j=400;j<y;j++)
        for(i=0;i<x;i++)
        {
            SDL_PutPixel32(surface,i,j,couleur2);
        }
}

int main(int argc,char** argv)
{
    SDL_Surface* screen;
    SDL_Init(SDL_INIT_VIDEO);
    screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE|SDL_DOUBLEBUF);  
    if (SDL_MUSTLOCK(screen))
        SDL_LockSurface(screen);
    Dithering(screen,800,600);
    if (SDL_MUSTLOCK(screen))
        SDL_UnlockSurface(screen);        
    SDL_Flip(screen);
    waitkey();
    return 0;
}



Explanations

	No explanations yet.