Archived

This topic is now archived and is closed to further replies.

Destroyer

Blitting accuracy in DirectDraw...

Recommended Posts

Hi. So - here''s the question. It''s from my understanding from "Tricks of the Game Programming Gurus" that a rectangle is upper left inclusive and bottom right exclusive... so the pixels at the bottom and right parameters of the rectangle never show up. Now - here''s the problem... Say I''m in 320x200 and I want to display a bitmap to the screen that''s also 320x200 pixels. No sweat you say - child''s play So you set your source rectange to something like: srcrect.left = 0; srcrect.top = 0; srcrect.bottom = 320; srcrect.right = 320; And your destination rectangle to something like: destrect.left = 0; destrect.top = 0; destrect.bottom = 320; destrect.right = 320; Then you blit it... But uh oh, is something not right? If rectangles are bottom right exclusive then the pixels in the bottom right row of both the destination and the source rectangles don''t show up... not what we want... 0 -> 320 = 321 pixels, right ? Which is not what you want either... Uhhh - I''m confused - someone help! :p Thanks, Destroyer //---------------------------- So... what do you want? I''ll have everything but fudge... ----------------------------\\

Share this post


Link to post
Share on other sites
Remember to account for the 0 pixels. A 320x240 blit will blit all pixels from 0 to 319, 0 to 239. The 320x240 pixels dont exist.

0x320 = 321 .. correct.

But the bottom and right pixels are exclusive, meaning only the first 320 pixels count, which starts at 0, not 1.

Hope this makes things more clearer.



Downloads, D3DXSprite tutorial, New platform game: .-= The ZeroOne Realm =-.

Share this post


Link to post
Share on other sites
Thanks!

It does help!

So those destination and source rects are actually both right since they''re actually blitting 321 by 201 pixels since it counts from 0 -> 320 and 0 -> 200. But since the bottom right of the rectangle is exclusive those pixels don''t show up anyway... hence 320 X 200 pixels show up on the screen - like it should

I think I got it!

Thanks,

Destroyer

//----------------------------
So... what do you want?

I''ll have everything but
fudge...
----------------------------\\

Share this post


Link to post
Share on other sites
Are you sure that "a rectangle is upper left inclusive and bottom right exclusive"? Every API I use has rectangles inclusive everywhere.

I will now assume that bottom and right pixels are inclusive, not exclusive. Therefore your rectangles are 321x201 pixels, not 320x200.

The drawing code does not discard the bottom and right pixels. Therefore, it will draw (or at least attempt to draw) 321x201 pixels.

However, the screen rectangle is

screen.left = 0;
screen.top = 0;
screen.bottom = 319;
screen.right = 199;

Since pixels start at 0, the number of pixels across and down is: 319-0+1=320 and 199-0+1=200. If this is not obvious, there are 6 numbers between 1 and 6, inclusively, or 0 and 5, inclusively.

To cover the whole screen, you use this rectangle (screen).

Share this post


Link to post
Share on other sites
Uh oh...

I would test that if I were you...
I tested it out, and yes, the RECT''s for blitting in DirectDraw are upper left inclusive and bottom right exclusive... try it out. Have a colored border around a pict that ur blitting and mess around with the values close to the edge... I''m sure you''ll be suprised

But hey - this might only be a DirectDraw thing - so don''t fret!

Thanks,



Destroyer

//----------------------------
So... what do you want?

I''ll have everything but
fudge...
----------------------------\\

Share this post


Link to post
Share on other sites