I'm not sure if this is a behavior that would help, and I'm not so sure that this is going to be useful since we are getting into 3D, but, for those still making games and such, this edition will, instead of giving you an error, just do a simple wraparound. Can't believe I didn't think of it sooner.
void D3DGraphics::PutPixel( int x,int y,int r,int g,int b )
{
x %= 799; // (or your window length - 1)
y %= 599; // (or your window height - 1)
int wrapAround = x + (rect.Pitch >> 2) * y;
((D3DCOLOR*)rect.pBits)[wrapAround] = D3DCOLOR_XRGB( r,g,b );
}
This will wrap any sprites and drawings around the screen instead of that annoying error when you go over the edge.
Very simple edit to PutPixel that stops out of bounds errors
-
- Posts: 4
- Joined: July 30th, 2012, 7:46 pm
Very simple edit to PutPixel that stops out of bounds errors
Last edited by GraniteHope on August 20th, 2012, 9:34 am, edited 1 time in total.
Re: Very simple edit to PutPixel that stops out of bounds er
Nice bro, I haven't got a chance to try it but it looks pretty good
MOOOOOO
Re: Very simple edit to PutPixel that stops out of bounds er
Nice idea, but this will only loop the pixels around the screen, what you want to do is check if the pixel is inside the screen and make that decide if the pixel gets drawn.
Also, I think the mod function is rather slow since it's really an advanced division operation, division being fairly slow.
Also, I think the mod function is rather slow since it's really an advanced division operation, division being fairly slow.
ʕ •ᴥ•ʔ
Re: Very simple edit to PutPixel that stops out of bounds er
On old cpus division / mod was slow but on new ones the cpu can usually process two integer divides per clock even without sse.
P.S. That annoying error is there to let you know when you're going over the edge. Going over the edge means programing: you're doing it completely wrong.
P.S. That annoying error is there to let you know when you're going over the edge. Going over the edge means programing: you're doing it completely wrong.
Chili
- viruskiller
- Posts: 399
- Joined: June 14th, 2012, 5:07 pm
Re: Very simple edit to PutPixel that stops out of bounds er
yeah is better to know when u'r doing something wrong,and also to be told what went wrong in some code right where it happened....
but sometimes it does a bit of domino effect and in the end it usually spits a drawing related error when in fact is a pointer related error,or a loop going out of boundary or something completely different.
tbh this error saved me lots of times with my games so far, by telling me something was wrong.
once i had a case where my code worked completely fine in debug mode,but on release mode it acted really strange, i got no warnings,no errors,but it turned to be a loop going out of boundary's.
but sometimes it does a bit of domino effect and in the end it usually spits a drawing related error when in fact is a pointer related error,or a loop going out of boundary or something completely different.
tbh this error saved me lots of times with my games so far, by telling me something was wrong.
once i had a case where my code worked completely fine in debug mode,but on release mode it acted really strange, i got no warnings,no errors,but it turned to be a loop going out of boundary's.
Re: Very simple edit to PutPixel that stops out of bounds er
I'd go with
void D3DGraphics::PutPixel( int x,int y,int r,int g,int b )
{
if (x >= 0 && y >= 0 && x < 800 && y < 600) {
((D3DCOLOR*)backRect.pBits)[ x + (backRect.Pitch >> 2) * y ] = D3DCOLOR_XRGB( r,g,b );
}
}
Im currently also looking for a way that I get the window size
void D3DGraphics::PutPixel( int x,int y,int r,int g,int b )
{
if (x >= 0 && y >= 0 && x < 800 && y < 600) {
((D3DCOLOR*)backRect.pBits)[ x + (backRect.Pitch >> 2) * y ] = D3DCOLOR_XRGB( r,g,b );
}
}
Im currently also looking for a way that I get the window size