CreateSubSurface

Can anyone tell me how tocreate a SDL_Surface that is a sub image of =
another SDL_Surface?
I try this but don’t work

SDL_Surface *CreateSubSurface(SDL_Surface *source, int x, int y,int w, =
int h)
{ SDL_Rect rect;
SDL_Rect app;
SDL_Surface *Prova;
Prova=3Dnew(SDL_Surface);
app.x=3Dx;=20
app.y=3Dy;
app.w=3Dw;
app.h=3Dh;
rect.x=3D0;
rect.y=3D0;
rect.w=3Dw;
rect.h=3Dh;
SDL_BlitSurface(source, &app, Prova, &rect);
SDL_UpdateRects(Prova, 1, &rect);
return Prova;
}

see you ,Matthiew

you could try SDL_CreateRGBSurface instead of new

also UpdateRects is only neccessary for updating the screen

“Marco Mattiazzo” <marco.mattiazzo at halleyveneto.it> wrote in message
news:200011012141.NAA29332 at mail.lokigames.com…> Can anyone tell me how tocreate a SDL_Surface that is a sub image of =

another SDL_Surface?
I try this but don’t work

SDL_Surface *CreateSubSurface(SDL_Surface *source, int x, int y,int w, =
int h)
{ SDL_Rect rect;
SDL_Rect app;
SDL_Surface *Prova;
Prova=3Dnew(SDL_Surface);
app.x=3Dx;=20
app.y=3Dy;
app.w=3Dw;
app.h=3Dh;
rect.x=3D0;
rect.y=3D0;
rect.w=3Dw;
rect.h=3Dh;
SDL_BlitSurface(source, &app, Prova, &rect);
SDL_UpdateRects(Prova, 1, &rect);
return Prova;
}

see you ,Matthiew

Marco Mattiazzo wrote:

Can anyone tell me how tocreate a SDL_Surface that is a sub image of =
another SDL_Surface?
I try this but don’t work

SDL_Surface *CreateSubSurface(SDL_Surface *source, int x, int y,int w, =
int h)
{ SDL_Rect rect;
SDL_Rect app;
SDL_Surface *Prova;
Prova=3Dnew(SDL_Surface);
app.x=3Dx;=20
app.y=3Dy;
app.w=3Dw;
app.h=3Dh;
rect.x=3D0;
rect.y=3D0;
rect.w=3Dw;
rect.h=3Dh;
SDL_BlitSurface(source, &app, Prova, &rect);
SDL_UpdateRects(Prova, 1, &rect);
return Prova;
}

This solution is stolen from libuta so i haven;t really tested it. Soon I
hope to implement my own version, so If this turns out not to work for you
just tell me and I’ll put that at the front of my work queue:

SDL_Surface* CreateSubSurface(SDL_Surface* source, int x, int y, int w, int
h)
{
//make a copy of the original struct
sdlSurface_ = new SDL_Surface;
*sdlSurface_ = *source;
//then set new metrics
sdlSurface_->w = w;
sdlSurface_->h = h;

  sdlSurface_->offset = (y * source->w + x) *

sdlSurface_->format->BytesPerPixel;
return sdlSurface;
}

Now keep in mind in your snip-it the source surface is copied. In the
function I included, editting the subsurface changes the source surface.
This is what I think of as a sub-surface but I am not sure if that is what
you wanted. I hope this can help…

- David Snopek
 sdlSurface_ = new SDL_Surface;
 *sdlSurface_ = *source;

Stop propagating bad code. You can create an SDL_Surface by calling
SDL_CreateRGBSurface() or SDL_CreateRGBSurfaceFrom(), or indirectly
using SDL_ConvertSurface(), SDL_DisplayFormat(), SDL_DisplayFormatAlpha(),
IMG_Load(), etc. Don’t ever construct it yourself if you don’t know
what you are doing

Fri, 03 Nov 2000 Mattias Engdeg?rd wrote:

 sdlSurface_ = new SDL_Surface;
 *sdlSurface_ = *source;

Stop propagating bad code. You can create an SDL_Surface by calling
SDL_CreateRGBSurface() or SDL_CreateRGBSurfaceFrom(), or indirectly
using SDL_ConvertSurface(), SDL_DisplayFormat(), SDL_DisplayFormatAlpha(),
IMG_Load(), etc. Don’t ever construct it yourself if you don’t know
what you are doing

As I understand it (creating a surface that represents a “window” inside
another surface, using the same physical pixel data),
SDL_CreateRGBSurfaceFrom() would be the one to use here.

(I’m using a similar trick in a simple linear framebuffer GUI toolkit in order
to avoid special cases for clip rects, windows and other stuff - there is only
one surface structure, and the only variable is that some surfaces may not own
the pixel data they represent.)

David Olofson
Programmer
Reologica Instruments AB
david.olofson at reologica.se

…- M u C o S --------------------------------. .- David Olofson ------.
| A Free/Open Multimedia | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
------------> http://www.linuxdj.com/mucos -' | Open Source Advocate | ..- A u d i a l i t y ------------------------. | Singer | | Rock Solid Low Latency Signal Processing | | Songwriter |—> http://www.angelfire.com/or/audiality -’ `-> david at linuxdj.com -’

Mattias Engdeg?rd wrote:

 sdlSurface_ = new SDL_Surface;
 *sdlSurface_ = *source;

Stop propagating bad code. You can create an SDL_Surface by calling
SDL_CreateRGBSurface() or SDL_CreateRGBSurfaceFrom(), or indirectly
using SDL_ConvertSurface(), SDL_DisplayFormat(), SDL_DisplayFormatAlpha(),
IMG_Load(), etc. Don’t ever construct it yourself if you don’t know
what you are doing

The idea is that the origanal surface “source” was created using one of these
methods you described then mearly copied and offset to the appropriate
value. Sorry, i was just trying to help…

- David Snopek

The idea is that the origanal surface “source” was created using one of these
methods you described then mearly copied and offset to the appropriate
value. Sorry, i was just trying to help…

No, my bad, I got the wrong impression. Sorry for jumping on you like that.

Mattias