Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » dirty rectangle tutorials/examples?

This thread is locked; no one can reply to it. rss feed Print
dirty rectangle tutorials/examples?
Derezo
Member #1,666
April 2001
avatar

The only example I can find of dirty rectangles is the allegro demo..
I tried to get into it, but there's so much in that source that you need to look around.. and I never could make sense of it entirely.
One game I'm working on is a 2D RPG.. unlike most RPG's, it's not scrolling
Now, I know basically how dirty rectangles drawing works.. you only draw the pixels that have changed. I tried constructing it myself, but I'm no good
Does anyone know of a good tutorial, or small example on the internet?
Or, if possible, could someone create a small example for me? I hope that's not asking too much...
Thanks

"He who controls the stuffing controls the Universe"

Evert
Member #794
November 2000
avatar

I made a small demo program a while ago that shows how I do it. It also shows how I handle multiple screen update methods in one program. It's based on the Allegro demo game, but hopefully it will be easier to understand.

You can get it from

http://www.science.uva.nl/~eglebbk/download/upddemo.zip

Hope it helps...

Evert

Derezo
Member #1,666
April 2001
avatar

The problem I'm finding, is looking at the source, tearing out the page flipping/triple buffering/etc that's not needed, then taking what's left and combining it with my own drawing functions to make it work..
....
I have defiled that code to an extreme, heh, and I've got more errors than I can handle after trying to hack it into my code (previously page flipping)...
Thanks for the help though, I'll most likely try again with it.
With page flipping I'm only getting 18-20 fps.. drawing the background layer, then a single character sprite over top, then the top layer over top.. in 640x480 mode.. and 16bit color..
Mind you, that's on my p133mhz system with Windows98.. (DOS mode though)
[ September 08, 2001: Message edited by: Derezo ]

"He who controls the stuffing controls the Universe"

Zaphos
Member #1,468
August 2001

The concept behind dirty rectangle code ...
The dirty rectangle method of rendering is based upon the concept that one need only redraw the part of the screen that changes from frame to frame. I will focus on the case described below:
I have a relatively static scene, and I want to put moving characters on it.
(1) For each character, have a buffer bitmap the same size.
(2) Copy the rectangle that the character will be blitted to into the buffer (b4 drawing the character, of course).
(3) Masked blit, or whatever, the character to that rectangle.
(4) When the character needs to change position, copy the buffer to where the character was ... erasing the character.
(5) Go to step (2).
(edited: sp and such)
[ September 08, 2001: Message edited by: Zaphos ]

epiwerks
Member #489
June 2000

That's all well and good, but what about multiple sprites?

------
I'm back.

Zaphos
Member #1,468
August 2001

Umm ... have buffers for each sprite (of corresponding sizes) and buffer the static scene for every sprite before drawing the sprites to the screen ... or just remember the order you drew the sprites and buffer as you go ... it isn't much different. Just follow the same process a bunch of times.
The original instructions were written for multiple sprites actually.
here, errata step five to:
(5) change char to the next character to draw, then goto (2).

Derezo
Member #1,666
April 2001
avatar

my problem is.. if I stick on the character, I also need to stick on what's infront of the character (the top layer, tree's and such). Blitting the entire layer causes slow down..

(Edit: Spelling.. it just sounded funny)

[ September 12, 2001: Message edited by: Derezo ]

"He who controls the stuffing controls the Universe"

Zaphos
Member #1,468
August 2001

Does the layer in front of the character change? If not, and if you are using double buffer redraws, try this:
Use masked blits, and have three standard bitmaps of screen size. One will hold the backbuffer, as normal. The other will hold the background, stuff that goes behind mr main character, and the other other will hold the foreground, which will all go infront of the character. To initially draw the screen, blit the background, then the character, then the foreground. Character may be replace with characters. Always masked blit the character and the foreground, so that everything is see through and you don't cover the screen up. Always std blit the background, so that you erase what ever was beneath it.
When you want to move a character, copy a rectangle of the size and position of the character from the background bmp to the back buffer (unmasked blit, this is your character erase), then blit the foreground. Then blit, to the new location of the character, the background, then character, then foreground, always only blitting enough rectangle to cover up where the character is to go. This method takes more ram to begin with, but no longer requires a buffer for each moving sprite ... so it all depends. If this explanation is too confusing, I wouldn't be surprised if it is, just demand of me a code sample, and I'll be happy to oblodge (darn, I could never spell that word) you.

Zaphos
Member #1,468
August 2001

Oh yeah, I almost forgot to add:
Ouch. That be one slooooow system, dig?

Derezo
Member #1,666
April 2001
avatar

Well, I've been working with the code a bit..
thankfully, I got it up to 40fps..
However, I need to always blit the foreground I think.. when I use the same system for the foreground as I do with the background, it doesn't blit the background.........doesn't even make sense, really..
I'm going to work with it some more. I'd post some code, but I don't have it with me (at school).. Thanks for your help guys

"He who controls the stuffing controls the Universe"

Zaphos
Member #1,468
August 2001

Are you masked_blit ting the foreground? If you simply blit the foreground it will cover up the background and only the foreground will show.

Go to: