Cutting images into tiles

Hi!

I got this code.

human = IMG_Load(“sprites/warrior.png”);
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}

In my program it is just transparent even though warrior.png is full of nice colors and stuff. :slight_smile:

Hello.

This code should work:

SDL_Surface *human = IMG_Load(“sprites/warrior.png”);
SDL_Rect cut, paste;

paste.x = 0;
paste.y = 0;
paste.w = 40;
paste.h = 40;

cut.x = 0;
cut.y = 0;
cut.w = 40;
cut.h = 40;

for(int i = 0; i < 10; i++)
{
SDL_BlitSurface(human, &cut, SDL_GetVideoSurface(), &paste);
cut.x += 40;
paste.x += 40;
}

SDL_Flip(SDL_GetVideoSurface());

What is that back[i] surface? In the code above, I’m blitting all tiles
in a row onto the screen.

Bernhard

Br?nnum-Hansen wrote:> Hi!

I got this code.

human = IMG_Load(“sprites/warrior.png”);
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}

In my program it is just transparent even though warrior.png is full of nice colors and stuff. :slight_smile:


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

Well, I was in a hurry and did not write what I wanted the code to do…
I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the first 40x40 pixels on back[0] then the next 40x40 in back[1] and so on.
Then later in the program I use back[0] to back [9] for an animation.

So, contents from human should be blitted into back.

Christian

Bernhard Bliem <bernhard.bliem at chello.at> wrote:> Hello.

This code should work:

SDL_Surface *human = IMG_Load(“sprites/warrior.png”);
SDL_Rect cut, paste;

paste.x = 0;
paste.y = 0;
paste.w = 40;
paste.h = 40;

cut.x = 0;
cut.y = 0;
cut.w = 40;
cut.h = 40;

for(int i = 0; i < 10; i++)
{
SDL_BlitSurface(human, &cut, SDL_GetVideoSurface(),
&paste);
cut.x += 40;
paste.x += 40;
}

SDL_Flip(SDL_GetVideoSurface());

What is that back[i] surface? In the code above, I’m
blitting all tiles
in a row onto the screen.

Bernhard

Br?nnum-Hansen wrote:

Hi!

I got this code.

human = IMG_Load(“sprites/warrior.png”);
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}

In my program it is just transparent even though
warrior.png is full of nice colors and stuff. :slight_smile:


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


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

Ok… That can be a bit more hairy, at least if you want to use alpha
and/or colorkey blitting.

How did you initialize the back[] array of surfaces? You have to
create a surface for each index in advance, and you may have to set
up colorkey and/or alpha before and/or after the “cut” blit, to get
the desired final result.

Check the documentation for SDL_BlitSurface() for details on
blending/colorkeying semantics. (Not always what you’d expect…)

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 29 March 2004 15.17, Br?nnum-Hansen wrote:

Well, I was in a hurry and did not write what I wanted the code to
do… I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the first 40x40
pixels on back[0] then the next 40x40 in back[1] and so on. Then
later in the program I use back[0] to back [9] for an animation.

So, contents from human should be blitted into back.

Well I don’t think it contains the stuff you mention but I’ve uploaded the file to www.caturn.dk/warrior.png
Maybe it explains more.

David Olofson wrote:> On Monday 29 March 2004 15.17, Br?nnum-Hansen wrote:

Well, I was in a hurry and did not write what I wanted the
code to
do… I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the first
40x40
pixels on back[0] then the next 40x40 in back[1] and so
on. Then
later in the program I use back[0] to back [9] for an
animation.

So, contents from human should be blitted into back.

Ok… That can be a bit more hairy, at least if you want to
use alpha
and/or colorkey blitting.

How did you initialize the back[] array of surfaces? You
have to
create a surface for each index in advance, and you may have
to set
up colorkey and/or alpha before and/or after the “cut” blit,
to get
the desired final result.

Check the documentation for SDL_BlitSurface() for details on

blending/colorkeying semantics. (Not always what you’d
expect…)

//David Olofson - Programmer, Composer, Open Source
Advocate

.- Audiality
-----------------------------------------------.
| Free/Open Source audio engine for games and multimedia.
|
| MIDI, modular synthesis, real time effects, scripting,…
|
`-----------------------------------> http://audiality.org
-’
http://olofson.nethttp://www.reologica.se


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

Hi

What about this?

struct
{
int pos_x,
pos_y,
width, /* width of 1 frame /
height, /
height of 1 frame /
frame; /
number of current frame */
} player;

void DrawPlayer(SDL_Surface surface) / surface is warrior.png */
{
SDL_Rect src, dest;

src.x = player.frame * player.width;
src.y = 0;
src.w = player.width;
src.h = player.height;

dest.x = player.pos_x;
dest.y = player.pos_y;

SDL_BlitSurface(surface, &src, SDL_GetVideoSurface(), &dest);

}

Br?nnum-Hansen wrote:> Well I don’t think it contains the stuff you mention but I’ve uploaded the file to www.caturn.dk/warrior.png

Maybe it explains more.

David Olofson wrote:

On Monday 29 March 2004 15.17, Br?nnum-Hansen wrote:

Well, I was in a hurry and did not write what I wanted the

code to

do… I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the first

40x40

pixels on back[0] then the next 40x40 in back[1] and so

on. Then

later in the program I use back[0] to back [9] for an

animation.

So, contents from human should be blitted into back.

Ok… That can be a bit more hairy, at least if you want to
use alpha
and/or colorkey blitting.

How did you initialize the back[] array of surfaces? You
have to
create a surface for each index in advance, and you may have
to set
up colorkey and/or alpha before and/or after the “cut” blit,
to get
the desired final result.

Check the documentation for SDL_BlitSurface() for details on

blending/colorkeying semantics. (Not always what you’d
expect…)

//David Olofson - Programmer, Composer, Open Source
Advocate

.- Audiality
-----------------------------------------------.
| Free/Open Source audio engine for games and multimedia.
|
| MIDI, modular synthesis, real time effects, scripting,…
|
`-----------------------------------> http://audiality.org
-’
http://olofson.nethttp://www.reologica.se


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


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

Doesn’t seem to have an alpha channel, but it has transparency, so I
guess you want colorkey == #000000 (black) for that. The colorkey
value is obviously stored in the file (GIMP understands what should
be transparent despite the lack of an alpha channel), but AFAIK
SDL_image won’t handle that automatically.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 29 March 2004 21.52, Br?nnum-Hansen wrote:

Well I don’t think it contains the stuff you mention but I’ve
uploaded the file to www.caturn.dk/warrior.png Maybe it explains
more.

[…blitting directly to the screen…]

Fine if you SDL_DisplayFormat() the image after loading it, without
using RLE acceleration. However, this image has transparency, which
means s/w blitting performance can be improved by using RLE
acceleration.

So, you probably want the RLE acceleration - and then you should avoid
clipping. RLE clipping has a performance penalty (the blitter needs
to skip and split spans, which means scanning through data just to
ignore it), but most of it can be avoided by keeping each sprite
image in it’s own surface.

That is, the original idea; an array of sprite surfaces, is the right
way to do it most of the time. It’s the best bet in nearly all
situations, as it maximizes RLE performance, is simple enough, and
doesn’t hurt performance when you get hardware accelerated blits.

Just remember the SDL_RLEACCEL flag and SDL_DisplayFormat*(). :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 29 March 2004 22.29, Bernhard Bliem wrote:

Hi

What about this?

This is a paletted PNG file, with an explicit color key (keyed to a palette
index, not a color), which SDL_image does set automatically. I loaded this
file in StepMania, which uses SDL_image, and the transparency worked fine.On Mon, Mar 29, 2004 at 11:48:38PM +0200, David Olofson wrote:

On Monday 29 March 2004 21.52, Br?nnum-Hansen wrote:

Well I don’t think it contains the stuff you mention but I’ve
uploaded the file to www.caturn.dk/warrior.png Maybe it explains
more.

Doesn’t seem to have an alpha channel, but it has transparency, so I
guess you want colorkey == #000000 (black) for that. The colorkey
value is obviously stored in the file (GIMP understands what should
be transparent despite the lack of an alpha channel), but AFAIK
SDL_image won’t handle that automatically.


Glenn Maynard

Hi

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

Thx

LesHauSs.

Les HauSsebons wrote:

Hi

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

Thx

LesHauSs.


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

The library SDL_gfx performs this function, with bilinear filtering too.

-TomT64

— TomT64 wrote:

Les HauSsebons wrote:

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT

The library SDL_gfx performs this function, with bilinear filtering
too.

Or, to put it another way, no. SDL does not contain a function to
scale, rotate, or otherwise transform a surface. Many libraries that
extend SDL contain methods to perform such functions (of which SDL_gfx
is one, of many).

                                                        NBarnes__________________________________

Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.

Les HauSsebons wrote:

Hi

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

Thx

LesHauSs.

You can use SDL_SoftStretch, as defined in SDL_video.h, but I don’t think the SDL people want you to.
This function is described as “private”, and it requires the surfaces to be of the same format (SDL_ConvertSurface could be useful there).
Also, I don’t think it does clipping.

Why SDL doesn’t officially provide stretched blitting I do not know…
Also, I made a post a few days ago asking about this which seems to have been ignored :(.
It also asked why SDL doesn’t support multiple windows, and pointed out a potential memory leak in SDL_CreateRGBSurfaceFrom.

Chris E.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040330/9ce31255/attachment.pgp

Les HauSsebons wrote:

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

I have done it in my game Scalar, grab the source and read :slight_smile:
http://scalar.sourceforge.net

You are interested in function: StrechDraw() in file scalar.cpp

HTH–
Milan Babuskov
http://njam.sourceforge.net

Chris E. wrote:

Les HauSsebons wrote:

Hi

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

Thx

LesHauSs.

You can use SDL_SoftStretch, as defined in SDL_video.h, but I don’t
think the SDL people want you to.
This function is described as “private”, and it requires the surfaces to
be of the same format (SDL_ConvertSurface could be useful there).
Also, I don’t think it does clipping.

Check http://sdl-stretch.sourceforge.net/ which exports the fast
stretchblit functions including variants with clipping. It is also
referenced in the libsdl.org list of sdl add-on libraries. If there are
any problems please mail me. – guido>

Why SDL doesn’t officially provide stretched blitting I do not know…
Also, I made a post a few days ago asking about this which seems to have
been ignored :(.
It also asked why SDL doesn’t support multiple windows, and pointed out
a potential memory leak in SDL_CreateRGBSurfaceFrom.

Chris E.


– guido http://google.de/search?q=guidod
GCS/E/S/P C++/++++$ ULHS L++w- N++@ s+:a d(±) r+@>+++ y++ 5++X- (geekcode)

I thought changing the mail subject would be enough to start a new
thread ! So I apologize

Meanwhile, I’ve been liked to :
http://sdl-stretch.sourceforge.net/
http://www.ferzkopp.net/~aschiffler/Software/SDL_gfx-2.0/

sge does the truetype thing to, so is it redundant with SDL_ttf ?

and, are all the scaling / rotation functions the same ?
of course I guess that they will do the same, on the screen, but are
some faster ? well tought ? ( no chance for a bug or non portability ? )

How can I figure this and compare , as a newbie :), all thoses librairies ?

Must I use several small librairies and provide a release with 50 DLLs
or try to find one that makes the more things I need and then use only
one dll ?

Thx

Glenn Maynard a ?crit :> On Tue, Mar 30, 2004 at 11:25:26AM +0200, Les HauSsebons wrote:

Hi

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

This post has nothing to do with “Cutting images into tiles”, which it
was a reply to. I suggest reading
http://www.catb.org/~esr/faqs/smart-questions.html in full, which says:

"Do not simply hit reply to a list message in order to start an entirely
new thread. This will limit your audience. Some mail readers, like mutt,
allow the user to sort by thread and then hide messages in a thread by
folding the thread. Folks who do that will never see your message.

Changing the subject is not sufficient. Mutt, and probably other mail
readers, looks at other information in the email’s headers to assign it
to a thread, not the subject line. Instead start an entirely new email."

Thanks.

That’s three questions.

(a) comparing scaling libraries

  • sdl-stretch has only fast scaleblit (based on sdl_softblit) that is good
    for onscreen scaling directly from source to screen surface
  • sdl-gfx has rotozoom in its core - but functions are slower and it is
    recommend to rotozoom to offscreen surface first and blit the
    intermediate surface later to your screen surface
  • sge is C++ while sdl-gfx and sdl-ttf are plain C - using C is still
    better for dll compatibility and wrapping into higher order layers.
    (b) dll distribution
    the question is only relevant for win32 dll hell, and there are multiple
    solutions to handle it. The unix people have ldso which allows to just
    ship and install the needed stuff and ldso will do the rest. With win32
    you should check your favourite installer program how to handle
    third party runtime dlls or just ship them all along where the exe is.
    © one or many dlls
    using one big dll has the advantage of using one big api - it makes
    the initial setup calls shorter and data handles can be easily pushed
    around. The higher order api makes any extension more complicated
    and often a lot of functionality is unused making for bloat, and
    switching over to another api gets more and more unlikely. That’s
    where the slogan of do one thing and do it well comes from.

just my 3 cent :wink:
– guido http://google.de/search?q=guidod

Les HauSsebons wrote:> I thought changing the mail subject would be enough to start a new

thread ! So I apologize

Meanwhile, I’ve been liked to :
http://sdl-stretch.sourceforge.net/
http://www.ferzkopp.net/~aschiffler/Software/SDL_gfx-2.0/
http://freshmeat.net/projects/sge/

sge does the truetype thing to, so is it redundant with SDL_ttf ?

and, are all the scaling / rotation functions the same ?
of course I guess that they will do the same, on the screen, but are
some faster ? well tought ? ( no chance for a bug or non portability ? )

How can I figure this and compare , as a newbie :), all thoses librairies ?

Must I use several small librairies and provide a release with 50 DLLs
or try to find one that makes the more things I need and then use only
one dll ?

Thx

Glenn Maynard a ?crit :

On Tue, Mar 30, 2004 at 11:25:26AM +0200, Les HauSsebons wrote:

Hi

I guess this must have been already asked, but I cant find it in
archives, explained as I want it.

I’d like to know how to scale pictures ( and sprites … ) with SDL

Is there a function of SDL_Image performing so ? I didnt find it.

Must there be a scaleRect definition somewhere to use with the BLIT
function ?

Can someone lead me to a clue how to perform this ?

This post has nothing to do with “Cutting images into tiles”, which it
was a reply to. I suggest reading
http://www.catb.org/~esr/faqs/smart-questions.html in full, which says:

"Do not simply hit reply to a list message in order to start an
entirely
new thread. This will limit your audience. Some mail readers, like
mutt,
allow the user to sort by thread and then hide messages in a thread by
folding the thread. Folks who do that will never see your message.

Changing the subject is not sufficient. Mutt, and probably other mail
readers, looks at other information in the email’s headers to assign it
to a thread, not the subject line. Instead start an entirely new
email."

Thanks.


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

Okay, now you know my problem.
The graphic is at www.caturn.dk/warrior.png
The code is this:

SDL_Surface *human, *back[10];
SDL_Rect cut, paste;

human = IMG_Load(“sprites/warrior.png”);
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}

Why does this put a completely transparent picture in all “back” surfaces.
How would you do?

Kind regards,
Christian

Bernhard Bliem <bernhard.bliem at chello.at> wrote:> Hi

What about this?

struct
{
int pos_x,
pos_y,
width, /* width of 1 frame /
height, /
height of 1 frame /
frame; /
number of current frame */
} player;

void DrawPlayer(SDL_Surface surface) / surface is
warrior.png */
{
SDL_Rect src, dest;

src.x = player.frame * player.width;
src.y = 0;
src.w = player.width;
src.h = player.height;

dest.x = player.pos_x;
dest.y = player.pos_y;

SDL_BlitSurface(surface, &src, SDL_GetVideoSurface(),
&dest);
}

Br?nnum-Hansen wrote:

Well I don’t think it contains the stuff you mention but
I’ve uploaded the file to www.caturn.dk/warrior.png
Maybe it explains more.

David Olofson wrote:

On Monday 29 March 2004 15.17, Br?nnum-Hansen wrote:

Well, I was in a hurry and did not write what I wanted
the

code to

do… I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the first

40x40

pixels on back[0] then the next 40x40 in back[1] and so

on. Then

later in the program I use back[0] to back [9] for an

animation.

So, contents from human should be blitted into back.

Ok… That can be a bit more hairy, at least if you want
to

use alpha
and/or colorkey blitting.

How did you initialize the back[] array of surfaces? You
have to
create a surface for each index in advance, and you may
have

to set
up colorkey and/or alpha before and/or after the "cut"
blit,

to get
the desired final result.

Check the documentation for SDL_BlitSurface() for details
on

blending/colorkeying semantics. (Not always what you’d
expect…)

//David Olofson - Programmer, Composer, Open Source
Advocate

.- Audiality
-----------------------------------------------.
| Free/Open Source audio engine for games and multimedia.

|
| MIDI, modular synthesis, real time effects,
scripting,…

|
`----------------------------------->
http://audiality.org

-’
http://olofson.nethttp://www.reologica.se


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


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


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

How do I blit from one file into another? It works fine when blitting to the screen.

Please help me.
Christian.

Br?nnum-Hansen <@Christian_Bronnum-Ha> wrote:> Okay, now you know my problem.

The graphic is at www.caturn.dk/warrior.png
The code is this:

SDL_Surface *human, *back[10];
SDL_Rect cut, paste;

human = IMG_Load(“sprites/warrior.png”);
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}

Why does this put a completely transparent picture in all
"back" surfaces.
How would you do?

Kind regards,
Christian

Bernhard Bliem <bernhard.bliem at chello.at> wrote:

Hi

What about this?

struct
{
int pos_x,
pos_y,
width, /* width of 1 frame /
height, /
height of 1 frame /
frame; /
number of current frame */
} player;

void DrawPlayer(SDL_Surface surface) / surface is
warrior.png */
{
SDL_Rect src, dest;

src.x = player.frame * player.width;
src.y = 0;
src.w = player.width;
src.h = player.height;

dest.x = player.pos_x;
dest.y = player.pos_y;

SDL_BlitSurface(surface, &src, SDL_GetVideoSurface(),

&dest);
}

Br?nnum-Hansen wrote:

Well I don’t think it contains the stuff you mention
but
I’ve uploaded the file to www.caturn.dk/warrior.png

Maybe it explains more.

David Olofson wrote:

On Monday 29 March 2004 15.17, Br?nnum-Hansen wrote:

Well, I was in a hurry and did not write what I wanted
the

code to

do… I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the
first

40x40

pixels on back[0] then the next 40x40 in back[1] and
so

on. Then

later in the program I use back[0] to back [9] for an

animation.

So, contents from human should be blitted into back.

Ok… That can be a bit more hairy, at least if you
want
to

use alpha
and/or colorkey blitting.

How did you initialize the back[] array of surfaces?
You

have to
create a surface for each index in advance, and you may
have

to set
up colorkey and/or alpha before and/or after the "cut"
blit,

to get
the desired final result.

Check the documentation for SDL_BlitSurface() for
details
on

blending/colorkeying semantics. (Not always what you’d
expect…)

//David Olofson - Programmer, Composer, Open Source
Advocate

.- Audiality
-----------------------------------------------.
| Free/Open Source audio engine for games and
multimedia.

|
| MIDI, modular synthesis, real time effects,
scripting,…

|
`----------------------------------->
http://audiality.org

-’
http://olofson.nethttp://www.reologica.se



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


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


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


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

How do I blit from one surface into another? It works fine when blitting to the screen.

Please help me.
Christian.

Br?nnum-Hansen <@Christian_Bronnum-Ha> wrote:> Okay, now you know my problem.

The graphic is at www.caturn.dk/warrior.png
The code is this:

SDL_Surface *human, *back[10];
SDL_Rect cut, paste;

human = IMG_Load(“sprites/warrior.png”);
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}

Why does this put a completely transparent picture in all
"back" surfaces.
How would you do?

Kind regards,
Christian

Bernhard Bliem <bernhard.bliem at chello.at> wrote:

Hi

What about this?

struct
{
int pos_x,
pos_y,
width, /* width of 1 frame /
height, /
height of 1 frame /
frame; /
number of current frame */
} player;

void DrawPlayer(SDL_Surface surface) / surface is
warrior.png */
{
SDL_Rect src, dest;

src.x = player.frame * player.width;
src.y = 0;
src.w = player.width;
src.h = player.height;

dest.x = player.pos_x;
dest.y = player.pos_y;

SDL_BlitSurface(surface, &src, SDL_GetVideoSurface(),

&dest);
}

Br?nnum-Hansen wrote:

Well I don’t think it contains the stuff you mention
but
I’ve uploaded the file to www.caturn.dk/warrior.png

Maybe it explains more.

David Olofson wrote:

On Monday 29 March 2004 15.17, Br?nnum-Hansen wrote:

Well, I was in a hurry and did not write what I wanted
the

code to

do… I declared this:
SDL_Surface *human *back[10];
SDL_Rect cut, paste;

Then the code I wrote before which should put the
first

40x40

pixels on back[0] then the next 40x40 in back[1] and
so

on. Then

later in the program I use back[0] to back [9] for an

animation.

So, contents from human should be blitted into back.

Ok… That can be a bit more hairy, at least if you
want
to

use alpha
and/or colorkey blitting.

How did you initialize the back[] array of surfaces?
You

have to
create a surface for each index in advance, and you may
have

to set
up colorkey and/or alpha before and/or after the "cut"
blit,

to get
the desired final result.

Check the documentation for SDL_BlitSurface() for
details
on

blending/colorkeying semantics. (Not always what you’d
expect…)

//David Olofson - Programmer, Composer, Open Source
Advocate

.- Audiality
-----------------------------------------------.
| Free/Open Source audio engine for games and
multimedia.

|
| MIDI, modular synthesis, real time effects,
scripting,…

|
`----------------------------------->
http://audiality.org

-’
http://olofson.nethttp://www.reologica.se



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


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


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


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