BlitSurface question [BEGINNER]

hi to all,
i’d like to take a piece of a surface from another surface,
example:

  1. init a surface1
  2. load into it an image
  3. copy a part of surface1 and put in surface2

i written this code:

// initialize *background surface and load an image
SDL_Surface * tspr = new SDL_Surface;;
SDL_Rect take;

take.x = x1;
take.y = y1;
take.w = x2-x1;
take.h = y2-y1;

cerr << "TAKE " <<    SDL_BlitSurface(background, &take , tspr, &take) << endl;

// refresh
SDL_SaveBMP(tspr,“tmp00000.bmp”);

well this code do not work…the blitsurface returns 0 but the tmp00000.bmp has null size,
i suppose that SDL_BlitSurface(background, &take , tspr, &take) take a part of background and put it in tspr…

whats’ wrong?
thx

Fosco

// initialize *background surface and load an image
SDL_Surface * tspr = new SDL_Surface;;
SDL_Rect take;

take.x = x1;
take.y = y1;
take.w = x2-x1;
take.h = y2-y1;

cerr << "TAKE " <<    SDL_BlitSurface(background, &take , tspr, &take)

<< endl;

// refresh
SDL_SaveBMP(tspr,“tmp00000.bmp”);

You will need to initialize your new surface “tspr” with a size before
blitting on to it. "New"ing a surface doesn’t create a canvas for you to
paint on, it just gets your easel set up.

You need to call SDL_CreateRGBSurface with all of the necessary settings
to initialize tspr.

SDL is a C library, no C++ at all, that is new/delete is not used anywhere
in SDL.

/OlofOn Apr 1, 2005 4:55 PM, Todd Lang <todd.lang at kiyote.ca> wrote:

// initialize *background surface and load an image
SDL_Surface * tspr = new SDL_Surface;;
SDL_Rect take;

take.x = x1;
take.y = y1;
take.w = x2-x1;
take.h = y2-y1;

cerr << "TAKE " << SDL_BlitSurface(background, &take , tspr, &take)
<< endl;

// refresh
SDL_SaveBMP(tspr,“tmp00000.bmp”);

You will need to initialize your new surface “tspr” with a size before
blitting on to it. "New"ing a surface doesn’t create a canvas for you to
paint on, it just gets your easel set up.

You need to call SDL_CreateRGBSurface with all of the necessary settings
to initialize tspr.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl