![]() |
|
Dirty Rectangles |
Ludwig Auer
Member #3,103
January 2003
![]() |
Hi! Ok, I tried Doublebuffering! Is ist right, that this methode isn't very fast. By playing the Demogame with Doublebuffering I got about 60 fps - with this 'Dirty Rectangle' Variante, I got ca. 500. The Screenresolution was 640x480... Now I'm Searching for a simple implementation of Dirty Rectangle. Can sb. help me? It would be kind of you. THX |
Jouser
Member #869
December 2000
![]() |
To use dirty rectangles in your small program instead of double buffering: 1. Simply save the part of the screen that your box is going to be blitted to (using blit()) 2. Blit() your image box or whatever you have to its destination on screen. 3. Calculate the new position from keyboard input or whatever... 4. Blit() the original part of the screen from step 1 back to its place. 5. Start over at step 1 with a new (x,y) |
miran
Member #2,407
June 2002
|
Actually DRS is a bit different although Jouser's method works too: 1. make a buffer you draw to just like with normal double buffering -- |
Ludwig Auer
Member #3,103
January 2003
![]() |
Thank you for your reply, but I don't really understand.:-/??? Like I said: I'm new to coding with C and allegro... Perhaps you have an old (small) code which includes Dirty Rectangles. |
miran
Member #2,407
June 2002
|
There's a DRS tutorial (along with a bunch of other tutorials) here: [url http://agdn.cjb.net] -- |
Steve Terry
Member #1,989
March 2002
![]() |
1. Create buffer exactly as you would using a double buffer. Sounds complicated but generally isn't. Good Luck. ___________________________________ |
Surt
Member #273
April 2000
![]() |
Ludwig Auer said: Ok, I tried Doublebuffering! Is ist right, that this methode isn't very fast. By playing the Demogame with Doublebuffering I got about 60 fps - with this 'Dirty Rectangle' Variante, I got ca. 500 The 60 fps you got on double buffering may well be due to v-syncing on a 60 Hz video mode, if that's the case, then turning off v-sync should allow a higher frame rate. Steve Terry said: 6. You may wish to make the DRS "smarter" by combining rectangles or deleting those that exist inside another rectangle. Has anyone implemented an exclusive dirty rects. What kind of overhead does the spliting/merging of rects incur? --- |
miran
Member #2,407
June 2002
|
Carl Olsson said: What kind of overhead does the spliting/merging of rects incur? It depends on what you're doing. If you have lots of rects and many overlap you can save quite a bit of time but if overlapping rects are few and far between then most of the time the code will just iterate through the list for no reason doing a lot of unnecessary checking ultimately proving to be more trouble than it's worth. The only way to answer the question is to implement the algo and make some tests... With all that in mind it has to be said that with the processing power of todays CPUs the performance lost or gained will most probably be minimal... -- |
Evert
Member #794
November 2000
![]() |
Quote: Has anyone implemented an exclusive dirty rects. What kind of overhead does the spliting/merging of rects incur?
I have a dirty rectangle system that merges aligned rectangles or rectangles that are fully contained within each other, but not the general case of overlapping rectangles. I based most of my DRS system on the Allegro demo game, btw. A bit complicated to learn from if you're really a beginner, but it might be worthwhile to look into it nevertheless. |
Tobias Dammers
Member #2,604
August 2002
![]() |
Before implementing a dr algo, be sure you are making the right kind of game for it. As soon as you have scrolling backgrounds, parallax effects, or do 3d, or for some other reason update most part of the screen in every frame, double-buffering is the way to go (or check if triple-buffering is an option). Method 1: Method 2: While method 2 is certainly faster and needs less memory, it has the big disadvantage that it only works correctly if either first all sprites restore, then all sprites draw in the exact same order (but that can easily cause flicker), or if no two sprites overlap. This might be feasible for some kinds of games (tile-based come to mind), but not for others (side-scrollers). --- |
Ludwig Auer
Member #3,103
January 2003
![]() |
>>The 60 fps you got on double buffering may well >>be due to v-syncing on a 60 Hz video mode, if >>that's the case, then turning off v-sync should >>allow a higher frame rate. Maybe you're right! I often get these 60fps, also in BlitBasic under Windows. How can I turn off this v-sync? I guess, that this DR stuff is a bit to complicated for me, right now. Althogh Thank you for your support. I will soon post my variante of double buffering... A thing is confusing me: My Code is bucking a lot, but the demo game (in double buffering mode) isn't. Perhaps I make a stupid mistake?!?!? bye |
Evert
Member #794
November 2000
![]() |
Quote: How can I turn off this v-sync?
Toggle the button on the lower right hand corner of your monitor Ok, bad joke - you can't disable the retrace, but you can choose not to wait for the sync, however this is generally a bad idea IMO. Image quality will suffer and you will/may get flickering. (See Tobias's post above) |
Surt
Member #273
April 2000
![]() |
Ludwig Auer said: How can I turn off this v-sync? If you are using v-sync (vertical refresh syncronisation), then you should be calling the vsync function just before you blit the contents of the buffer to the screen. Just comment it out and see how your frame rate changes. Evert said: ...you can choose not to wait for the sync, however this is generally a bad idea IMO. Image quality will suffer and you will/may get flickering. Without v-sync the screen may "tear", with the monitor updating before the frame is fully draw, leaving part of the old frame on screen. (This may still happen with v-sync if drawing takes longer than a refresh cycle.) This will look nasty if the screen image changes a great deal each frame. For example, with fast moving sprites, the top half of the sprite may draw at the edge of the screen with the bottom half mid screen. --- |
|