How to copy sdl_Surface from pointer c++

I see!On Monday, August 25, 2003, at 10:57 AM, Atrix Wolfe wrote:

Max, you ever try painting?

when you paint a square and then let it dry and paint a circle
partialy over
the square, doesnt the circle apear over the square?

This is the same reason when you draw one image after another, it
apears
above the other image.

----- Original Message -----
From: “Max Countryman” <@Max_Countryman>
To:
Sent: Monday, August 25, 2003 10:37 AM
Subject: Re: [SDL] Layers

Ok, now I am really confused. No, I am running a double buffered main
surface. But what you are saying makes absolutely no sense at all! Why
should one image appear over the other? Where and how do you define
this??? As far as I can see, there is NO reason for one image to
appear
over the other…

Max
On Sunday, August 24, 2003, at 11:09 PM, NBarnes wrote:

— Max Countryman <@Max_Countryman> wrote:

Ok… I still don’t understand why one image should appear above
another. Right now my two images are fighting to be on top of
one-another. Causing a horrible flicker. I thought that I should
need
to somehow tell one image to be on top of the other…

That sounds like you might not be using a double buffered surface
as your main display and then calling SDL_Flip(mainDisplay) to
change the view. Updating the surface when it’s being displayed
can cause effects like you describe.

                                                       NBarnes

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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

Hmm, still this doesn’t work…

Why not take the code I gave you and show me what I have to do inorder
to get one image to appear over the other. And don’t forget, both these
images must be updated inorder to scroll…On Monday, August 25, 2003, at 10:57 AM, Atrix Wolfe wrote:

Max, you ever try painting?

when you paint a square and then let it dry and paint a circle
partialy over
the square, doesnt the circle apear over the square?

This is the same reason when you draw one image after another, it
apears
above the other image.

----- Original Message -----
From: “Max Countryman” <@Max_Countryman>
To:
Sent: Monday, August 25, 2003 10:37 AM
Subject: Re: [SDL] Layers

Ok, now I am really confused. No, I am running a double buffered main
surface. But what you are saying makes absolutely no sense at all! Why
should one image appear over the other? Where and how do you define
this??? As far as I can see, there is NO reason for one image to
appear
over the other…

Max
On Sunday, August 24, 2003, at 11:09 PM, NBarnes wrote:

— Max Countryman <@Max_Countryman> wrote:

Ok… I still don’t understand why one image should appear above
another. Right now my two images are fighting to be on top of
one-another. Causing a horrible flicker. I thought that I should
need
to somehow tell one image to be on top of the other…

That sounds like you might not be using a double buffered surface
as your main display and then calling SDL_Flip(mainDisplay) to
change the view. Updating the surface when it’s being displayed
can cause effects like you describe.

                                                       NBarnes

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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

Max Countryman wrote:

Hmm, still this doesn’t work…
Why not take the code I gave you and show me what I have to do inorder
to get one image to appear over the other. And don’t forget, both
these images must be updated inorder to scroll…

i guess you are starting to upset some people here. i suggest you should
do your homework first. don’t expect peaople to write your programms.
have you read the SDL tutorial/FAQ whatever?

regards …
clemens

Why would you think that? Everyone’s been very helpful. We just haven’t
been able to tackle my problem yet. ;)On Monday, August 25, 2003, at 12:16 PM, Clemens Kirchgatterer wrote:

Max Countryman <@Max_Countryman> wrote:

Hmm, still this doesn’t work…
Why not take the code I gave you and show me what I have to do inorder
to get one image to appear over the other. And don’t forget, both
these images must be updated inorder to scroll…

i guess you are starting to upset some people here. i suggest you
should
do your homework first. don’t expect peaople to write your programms.
have you read the SDL tutorial/FAQ whatever?

regards …
clemens


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

Yea, that’s what I’ve been doing… Still, even if the sprite is blitted
before the background the conflict, as if they were on the same layer,
well they are on the same surface… the screen…On Monday, August 25, 2003, at 05:48 AM, Juan Ignacio Carniglia wrote:

What I meant, is that if your sprite didn?t change in position, then
you don?t have to redraw it, which seemed what Max was doing.

Of course, the more objects you have on screen, the more Blits you will
end up doing. You can only hope for them to be small and fast (with
RLEACCEL).

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On
Behalf Of NBarnes
Sent: Monday, August 25, 2003 9:21 AM
To: sdl at libsdl.org
Subject: RE: [SDL] Layers

— Juan Ignacio Carniglia wrote:

Once you drew the “topmost” image, you just stop
blitting… The fewer
Blits, the smoother your app gets. Also try to blit small areas, if
possible. The just blit faster.

It seems to me that ‘fewer blits’ is really a relative term,
though. Running something like an advanced side-scroller
(Raiden or similar) would involve two or three dozen blits
per frame of game, yes? For my game, I’m absolutely planning
on having up to four PCs, between one and fifteen enemy
combatants, random non-character objects, and further SFX
onscreen at once, which would easily account for several
dozen blits per frame. Small blits, to be sure, but lots of them.

                                                          NBarnes

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design
software http://sitebuilder.yahoo.com


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

What do you suggest I do? I have to update both images constantly, that
way they appear to move…

It is definitely double buffered.On Sunday, August 24, 2003, at 11:09 PM, NBarnes wrote:

— Max Countryman <@Max_Countryman> wrote:

Ok… I still don’t understand why one image should appear above
another. Right now my two images are fighting to be on top of
one-another. Causing a horrible flicker. I thought that I should need
to somehow tell one image to be on top of the other…

That sounds like you might not be using a double buffered surface
as your main display and then calling SDL_Flip(mainDisplay) to
change the view. Updating the surface when it’s being displayed
can cause effects like you describe.

                                                       NBarnes

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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

— Max Countryman wrote:

Here are my two blits, you tell me how to make one blit appear over
the other:

/* Blit the player sprite to the screen. */

SDL_BlitSurface ( sprite, NULL, screen, &spriteLocation );

spriteLocation.y = spritePosition_y;
spriteLocation.x = spritePosition_x;

SDL_SetColorKey( sprite, SDL_SRCCOLORKEY, 0);
SDL_SetAlpha( sprite, SDL_SRCALPHA, 255 );

/* Scroll the the level background… */

SDL_BlitSurface ( background, &pictureLocation, screen, NULL );
scrollPosition–;

pictureLocation.y = scrollPosition;

SDL_Flip( screen );

The first thing that I would note is that you don’t need to do
SDL_SetColorKey and SDL_SetAlpha every time through your render
loop. You just need to do them once, when the SDL_Surface containing
the sprite’s image data is created.

Also, this block strikes me as wrong on the grounds that you are
first blitting the sprite to the screen and then blitting the
background on top of the sprite (first a blit from sprite to screen,
and then a blit from background to screen). That would cause the
background to be painted on top of the sprite, neatly covering it up.

It is important (and there are some rather sophisticated routines in
my current project to handle it) that things be drawn in the correct
order so that they overlap properly. This can be tricky when dealing
with complex scenes of mobile components (breaking a single laser
beam line down into sub-sections so some can be drawn in front of
some other things and others can be drawn behind yet more things can
be non-trivial).

                                                          NBarnes__________________________________

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

First, you draw the background. Once it is painted, you con draw
things over it, and mess it up. It’s like setting a table, first,
there was the table, then, the mantel or piece of cloth, and then
you put the plates, forks, glasses… The big cheese pizza… and
all… :slight_smile:

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On
Behalf Of Max Countryman
Sent: Monday, August 25, 2003 6:58 PM
To: sdl at libsdl.org
Subject: Re: [SDL] Layers

Yea, that’s what I’ve been doing… Still, even if the sprite
is blitted
before the background the conflict, as if they were on the
same layer,
well they are on the same surface… the screen…

On Monday, August 25, 2003, at 05:48 AM, Juan Ignacio Carniglia wrote:

What I meant, is that if your sprite didn?t change in
position, then
you don?t have to redraw it, which seemed what Max was doing.

Of course, the more objects you have on screen, the more Blits you
will end up doing. You can only hope for them to be small and fast
(with RLEACCEL).

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]
On Behalf Of NBarnes Sent: Monday, August 25, 2003 9:21 AM To: sdl at libsdl.org Subject: RE: [SDL] Layers Juan Ignacio Carniglia <@Juan_Ignacio_Carnigl> wrote:

Once you drew the “topmost” image, you just stop
blitting… The fewer
Blits, the smoother your app gets. Also try to blit small
areas, if

possible. The just blit faster.

It seems to me that ‘fewer blits’ is really a relative
term, though.

Running something like an advanced side-scroller (Raiden
or similar)

would involve two or three dozen blits per frame of game,
yes? For

my game, I’m absolutely planning on having up to four PCs, between
one and fifteen enemy combatants, random non-character
objects, and

further SFX onscreen at once, which would easily account
for several

dozen blits per frame. Small blits, to be sure, but lots of them.

NBarnes


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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

— Max Countryman wrote:

Ok, now I am really confused. No, I am running a double buffered
main surface. But what you are saying makes absolutely no sense at
all! Why should one image appear over the other? Where and how do
you define this??? As far as I can see, there is NO reason for one
image to appear over the other…

It really is as simple as order of operations, at least in my
experience. If you blit spriteFoo and then blit spriteBar, spirteBar
will appear to overlap and cover whatever of spriteFoo it conflicts
with. If you blit spriteBar and then spriteFoo, spriteFoo will be on
top. Blitting a background over the entire display surface and then
blitting sprites over the top of that shoud cause the sprites to
display cleanly on top of the background every time.

Mind you, my experience (and I’ve done some relatively complex things
to ensure that certain graphic effects overlap and are overlapped
correctly) is only with double buffered main displays. Due to my
exclusive use of double buffered surfaces, I don’t have any
experience with SDL_UpdateRect or SDL_UpdateRects.

                                                          NBarnes

P.S. - If anybody does have insight into SDL_UpdateRect/s, is my
impression correct that they are only really necessary/useful when
dealing with non-double buffered displays? That is to say,
SDL_UpdateRect/s and SDL_Flip are exclusive in their utility and you
would not need to do one or the other?__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

Take a look at the aliens demo on the SDL website. It’s a good example
of very simple blit layering.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Ok, but it seems to mess this process up when I have to constantly
update the background, yes? Because the order doesn’t seem to matter in
this case. Both sprite and bg are being updated as often a possible,
thus allowing clean scrolling and movement.On Monday, August 25, 2003, at 03:14 PM, Juan Ignacio Carniglia wrote:

First, you draw the background. Once it is painted, you con draw
things over it, and mess it up. It’s like setting a table, first,
there was the table, then, the mantel or piece of cloth, and then
you put the plates, forks, glasses… The big cheese pizza… and
all… :slight_smile:

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On
Behalf Of Max Countryman
Sent: Monday, August 25, 2003 6:58 PM
To: sdl at libsdl.org
Subject: Re: [SDL] Layers

Yea, that’s what I’ve been doing… Still, even if the sprite
is blitted
before the background the conflict, as if they were on the
same layer,
well they are on the same surface… the screen…

On Monday, August 25, 2003, at 05:48 AM, Juan Ignacio Carniglia wrote:

What I meant, is that if your sprite didn?t change in
position, then
you don?t have to redraw it, which seemed what Max was doing.

Of course, the more objects you have on screen, the more Blits you
will end up doing. You can only hope for them to be small and fast
(with RLEACCEL).

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]
On Behalf Of NBarnes Sent: Monday, August 25, 2003 9:21 AM To: sdl at libsdl.org Subject: RE: [SDL] Layers Juan Ignacio Carniglia wrote:

Once you drew the “topmost” image, you just stop
blitting… The fewer
Blits, the smoother your app gets. Also try to blit small
areas, if

possible. The just blit faster.

It seems to me that ‘fewer blits’ is really a relative
term, though.

Running something like an advanced side-scroller (Raiden
or similar)

would involve two or three dozen blits per frame of game,
yes? For

my game, I’m absolutely planning on having up to four PCs, between
one and fifteen enemy combatants, random non-character
objects, and

further SFX onscreen at once, which would easily account
for several

dozen blits per frame. Small blits, to be sure, but lots of them.

NBarnes


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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

Thank you. :slight_smile: I think I understand how it should work, but for whatever
reason it does not work on my code. I think it is because of the
constant updating that must take place inorder for the bg to scroll,
and the sprite to move.On Monday, August 25, 2003, at 03:11 PM, Sam Lantinga wrote:

Take a look at the aliens demo on the SDL website. It’s a good example
of very simple blit layering.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


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

Thank you. :slight_smile: I think I understand how it should work, but for
whatever reason it does not work on my code. I think it is because of
the constant updating that must take place inorder for the bg to
scroll, and the sprite to move.

So if you make scroller you just first blit the background and after
that you need to blit the sprites from furthest to nearest order.
After that you flip the buffers.

Have you verfied that you do this and nothing else?On Tuesday 26 August 2003 01:17, Max Countryman wrote:

On Monday, August 25, 2003, at 03:11 PM, Sam Lantinga wrote:

Take a look at the aliens demo on the SDL website. It’s a good
example of very simple blit layering.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


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

Yes, I have.

If you’d like to see my code, please, let me know.On Monday, August 25, 2003, at 03:28 PM, Sami N??t?nen wrote:

On Tuesday 26 August 2003 01:17, Max Countryman wrote:

Thank you. :slight_smile: I think I understand how it should work, but for
whatever reason it does not work on my code. I think it is because of
the constant updating that must take place inorder for the bg to
scroll, and the sprite to move.

So if you make scroller you just first blit the background and after
that you need to blit the sprites from furthest to nearest order.
After that you flip the buffers.

Have you verfied that you do this and nothing else?

On Monday, August 25, 2003, at 03:11 PM, Sam Lantinga wrote:

Take a look at the aliens demo on the SDL website. It’s a good
example of very simple blit layering.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


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

P.S. - If anybody does have insight into SDL_UpdateRect/s, is my
impression correct that they are only really necessary/useful when
dealing with non-double buffered displays? That is to say,
SDL_UpdateRect/s and SDL_Flip are exclusive in their utility and you
would not need to do one or the other?

Yes, that’s correct.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Max Countryman wrote:

Thank you. :slight_smile: I think I understand how it should work, but for whatever
reason it does not work on my code. I think it is because of the
constant updating that must take place inorder for the bg to scroll,
and the sprite to move.

-Sprites are drawn in the order you blit them. That means what you blit
first will be below subsequent sprites. ie. blitted pixels replace
whatever was below.

-Be sure to call SDL_Flip just once per frame after you have rendered
your sprites.

-When you have double buffers you -might- have two surfaces which get
swapped with every flip (instead of one back surface copied to the
actual screen surface). If you blit some sprites to one surface, flip,
and others to the other surface, flip and repeat, it will most likely
flicker. If you’re using fullscreen double-buffered hardware surfaces,
at least under windows (someone please correct me if I’m wrong) this is
probably what is happening to you.

-Usually (unless you want the same sprite at several places on screen)
you render each sprite only once per frame, and then just flip. The
updated image won’t show up until you flip.

Drirr.

Max Countryman wrote:

Thank you. :slight_smile: I think I understand how it should work, but for
whatever reason it does not work on my code. I think it is because of
the constant updating that must take place inorder for the bg to
scroll, and the sprite to move.

-Sprites are drawn in the order you blit them. That means what you
blit first will be below subsequent sprites. ie. blitted pixels
replace whatever was below.

-Be sure to call SDL_Flip just once per frame after you have rendered
your sprites.

-When you have double buffers you -might- have two surfaces which get
swapped with every flip (instead of one back surface copied to the
actual screen surface). If you blit some sprites to one surface, flip,
and others to the other surface, flip and repeat, it will most likely
flicker. If you’re using fullscreen double-buffered hardware surfaces,
at least under windows (someone please correct me if I’m wrong) this
is probably what is happening to you.

-Usually (unless you want the same sprite at several places on screen)
you render each sprite only once per frame, and then just flip. The
updated image won’t show up until you flip.

Drirr.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdlOn Monday, August 25, 2003, at 04:28 PM, Drirr Cat wrote:

Whoops, sorry about that last blank e-mail.

Ok, this sounds like it could be the problem, but I think I’m only
rendering my sprite once a frame… If that is so, this couldn’t be the
problem, correct? Thanks again, and I’d be happy to show you my code,

MaxOn Monday, August 25, 2003, at 04:28 PM, Drirr Cat wrote:

Max Countryman wrote:

Thank you. :slight_smile: I think I understand how it should work, but for
whatever reason it does not work on my code. I think it is because of
the constant updating that must take place inorder for the bg to
scroll, and the sprite to move.

-Sprites are drawn in the order you blit them. That means what you
blit first will be below subsequent sprites. ie. blitted pixels
replace whatever was below.

-Be sure to call SDL_Flip just once per frame after you have rendered
your sprites.

-When you have double buffers you -might- have two surfaces which get
swapped with every flip (instead of one back surface copied to the
actual screen surface). If you blit some sprites to one surface, flip,
and others to the other surface, flip and repeat, it will most likely
flicker. If you’re using fullscreen double-buffered hardware surfaces,
at least under windows (someone please correct me if I’m wrong) this
is probably what is happening to you.

-Usually (unless you want the same sprite at several places on screen)
you render each sprite only once per frame, and then just flip. The
updated image won’t show up until you flip.

Drirr.


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

I think we’d better get this one off list as the answer has already
been mentioned a few times. Send me your code at
eratosthenes at users.playstation2-linux.com or @Paul_Smith
and I’ll look through it with you.

However, you keep asking how you specify what order surfaces should
appear on the screen in. The simple answer is that they appear in
exactly the order that you blit them. The second blit will overwrite
anything in the first blit (where they ovelap). The third blit will
overwrite everything in the second, and so on.

So, seeing as you update the entire background, this is what you must
blot first in your code, every frame. After that you blit the sprite
that must appear on top.

I’d also mention that if you really have to update the whole background
every frame, please keep your screen resolution and colour depth down
to something reasonable. For example blitting 320x240x8 every frame
requires the transfer of 75kb of data every (say) 1/60th of a second,
that’s about 4.3 Mb per second, whereas 1024x768x32 (As some other
recent poster was attempting) requires a whopping 180Mb of data to be
blitted per second. I’d suggest reading Bob Pendleton’s hardware vs
software surfaces article in any case :slight_smile:

Like I said - send me your code and I’ll go through it with you.__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

Max Countryman wrote:

/* Blit the player sprite to the screen. */

SDL_BlitSurface ( sprite, NULL, screen, &spriteLocation );

spriteLocation.y = spritePosition_y;
spriteLocation.x = spritePosition_x;

SDL_SetColorKey( sprite, SDL_SRCCOLORKEY, 0);
SDL_SetAlpha( sprite, SDL_SRCALPHA, 255 );

/* Scroll the the level background… */

SDL_BlitSurface ( background, &pictureLocation, screen, NULL );
scrollPosition–;

pictureLocation.y = scrollPosition;

SDL_Flip( screen );

Somebody else already mentioned that you need to reverse the blit order and
that you don’t need to set the color key and alpha on every iteration. You
probably should not set the colorkey of the background at all. You want the
background to be opaque, right?

Something else to consider is that you may not actually get double buffering
even if you request it. There are two ways of dealing with this situation:

  1. Use SDL_SWSURFACE instead SDL_HWSURFACE when setting the video mode.
    This will give you a software backbuffer to which you can render. It will
    also disable all hardware acceleration, so use with care.

  2. Create your own backbuffer with SDL_CreateRGBSurface, draw your
    complete scene on the backbuffer, and then blit the backbuffer to the video
    surface in one fell swoop. It’s a bit of work on your part, but it gives
    good results. This is what I did for Feyna’s Quest.–
    Rainer Deyke - rainerd at eldwood.com - http://eldwood.com