Jump to content

  • Log In with Google      Sign In   
  • Create Account


Redraw 2D backgrounds every frame?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 brewknowc   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 January 2002 - 04:01 AM

Hi, I''m new to directX and am only about half way through lamothe''s book, but a question came to mind. When you have a character walking around on a pre rendered background image, do you have to draw that background to the back surface every frame? I was wondering because there seems like there would be a more efficient way. I know lamothe did this for one of his small demos in chap 7. Which is the faster part of the process? Drawing the bitmap to the back buffer or flipping it? - Free Your Mind -

Sponsor:

#2 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 13 January 2002 - 04:31 AM

Flipping is faster : it just involves changing in memory the pointer that tells the video bios where the image is stored.

#3 pizza box   Members   -  Reputation: 168

Like
Likes
Like

Posted 13 January 2002 - 05:23 AM

You have to redraw the entire screen otherwise your last frame would still be stuck on the screen, and the character would leave a trail of sprites behind him. There are a number of efficient ways to do this, like Fruny said, page flipping.

#4 BitBlt   Members   -  Reputation: 386

Like
Likes
Like

Posted 13 January 2002 - 07:11 AM

It sounds like you''re a little confused on the processes, I may be wrong though. First you draw everything to the backbuffer, then you flip the backbuffer with the frontbuffer, repeat.



Make games, it''s fun

#5 merlin9x9   Members   -  Reputation: 174

Like
Likes
Like

Posted 13 January 2002 - 07:28 AM

You draw your frame in some off-screen buffer. Then you either flip it or blit it to the front buffer. You only get page flipping in full-screen apps, remember, so blitting is still necessary to display the frame when your app is running in a window.

Also, you don''t have to redraw the background every frame. There''s such a thing as dirty rectangles (or regions) that can be used to squeeze some more performance when actual pixel setting is a bottleneck.

#6 GBGames   Members   -  Reputation: 182

Like
Likes
Like

Posted 13 January 2002 - 07:34 AM

Dirty rectangles? I never heard of them. How do those work?



#7 Abstraction   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 January 2002 - 07:38 AM

1) Draw the background image on the back buffer

2) Before you blt your character copy the part of the backbuffer that the character is going to cover into an offscreen surface
3) blt your character
4) flip the surfaces
5) blt your offscreen surface onto the backbuffer to restore it
go back to step 2

Now instead of drawing a surface the size of your render target and another surface the size of your character, you are just drawing two surface the size of your character. Of course if you have a whole crap load of objects moving every frame and being drawn over your background (and possibly each other) than you might as well screw the whole thing and draw your background every frame. 2d games don''t really have the speed problems 3d games have so I wouldn''t worry about it.

#8 merlin9x9   Members   -  Reputation: 174

Like
Likes
Like

Posted 13 January 2002 - 05:11 PM

Yeah, dirty rectangles are of limited use these days. But if you''re writing a GDI app, dirty rectangles (or--better yet--masking regions) ase the way to go.

#9 mickey   Members   -  Reputation: 100

Like
Likes
Like

Posted 14 January 2002 - 02:00 AM

guys! directly rectangles aren''t implemented that easy, i''ve read books saying about using clippers, that is, you use a cliplist to hold the rectangles, anyway i posted a thread here, asking for an article about this so if anybody here is kind-hearted to submit an article...

#10 merlin9x9   Members   -  Reputation: 174

Like
Likes
Like

Posted 15 January 2002 - 05:10 AM

I only brought up dirty rectangles to point out that you don''t have to redraw everything for every frame like someone here asserted. Yes, they are a pain in the neck, and the only time they''d really be of much use these days is—as I said before—for a GDI game. In such a case, you can just use Windows'' implementation of dirty rectangles, saving yourself a lot of work.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS