Negative coordinate blitting.

Some tips to blit at negative coordinates with SDL

SDL_BlitSurface

See version :

Dépendances (dans l'archive) :
homer.bmp

Download :

#include <sdl/sdl.h>

#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"sdlmain.lib")

SDL_Surface* Charger(const char* fic)
{
    SDL_Surface* res = SDL_LoadBMP(fic);
    if (res==NULL)
    {
        printf("Erreur chargement %s\n",fic);
        exit(-1);
    }
    return res;
}

int KeyHit()
{
    SDL_Event e;
    if (SDL_PollEvent(&e))
        if (e.type == SDL_KEYDOWN)
            return 1;
    return 0;
}

void Blit(SDL_Surface* source,SDL_Surface* dest,int x,int y)
{
    SDL_Rect R;
    R.x = x;
    R.y = y;
    SDL_BlitSurface(source,NULL,dest,&R);
}

int main(int argc,char** argv)
{
    SDL_Surface* homer,*screen;
    SDL_Rect R,copy;
    SDL_Init(SDL_INIT_VIDEO);
    screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE|SDL_DOUBLEBUF);  
    homer=Charger("homer.bmp");
    SDL_SetColorKey(homer,SDL_SRCCOLORKEY ,SDL_MapRGBA(homer->format,255,0,255,0));
    R.x = 500;
    R.y = 100;
    while(!KeyHit())
    {
        SDL_FillRect(screen,NULL,0);
        R.x--;
        SDL_BlitSurface(homer,NULL,screen,&R);
        SDL_Flip(screen);
        SDL_Delay(1);
    }
    R.x = 500;
    while(!KeyHit())
    {
        SDL_FillRect(screen,NULL,0);
        R.x--;
        copy = R;
        SDL_BlitSurface(homer,NULL,screen,&copy);
        SDL_Flip(screen);
        SDL_Delay(1);
    }
    R.x = 500;
    while(!KeyHit())
    {
        SDL_FillRect(screen,NULL,0);
        R.x--;
        Blit(homer,screen,R.x,R.y);
        SDL_Flip(screen);
        SDL_Delay(1);
    }
    SDL_FreeSurface(homer);
    SDL_Quit();
    return 0;
}



Explanations

	No explanations yet.