Distortion on Draw2dImage [solved]
Posted: Tue Nov 20, 2007 12:54 am
HI,
We've been thinking a lot about this and debugging a lot before posting here, and I also checked for similar problems in the forum. I'm almost sure this is an Irrlicht bug, but I'd like to check with advanced users if they even ran on this problem.
First, a few things to keep in mind:
- We are using "power 2" sided textures, this is not a distortion because of the texture image dimensions.
- This is a problem with the overload Draw2dImage(texture, Rect dest, Rect source, color, alpha). It does not happen with Draw2dImage(texture, Pos2D, Rect source, Rect clip, color, alpha) overload. But as I'll explain, unfortunately we can't use this overload on our project.
OK, now, this is the image loaded in memory (512x512), and the area I marked with red is a slice that I'll render on a given point of the screen using Draw2dImage():
Now, I will draw it using the following call:
IrrVideoDriver.Draw2DImage(tex, new Rect(290, 20, 502, 207), new Rect(300, 325, 512, 512), whitecolor, true);
The result is a draw with distortion on its pixels, where I marked red:
But check the yellow mark above. This slice is rendered from the same texture, uses the same Draw2dImage() code, on the same class, but its pixels are fine! This distortion is actually random, and this another screen confirms it:
So I guessed the engine was somehow missing the coordinates of the dest rect by one pixel. Then I forced a -1 subtraction on the first X and Y of the dest rect, as follows:
IrrVideoDriver.Draw2DImage(tex, new Rect(290-1, 20-1, 502, 207), new Rect(300, 325, 512, 512), whitecolor, true);
And it solved the problem... for a while:
But I soon realized that this fix wouldn't work on all machines. I tested on another video card, and the distortion returned. And as the test continued, on each machine different slices were distorted or just rendered fine.
So I decided to try another overload, Draw2dImage(texture, Pos2D, Rect source, Rect clip, color, alpha). The call became:
IrrVideoDriver.Draw2DImage(tex, new Position2D(290, 20), new Rect(300, 325, 512, 512), new Rect(0, 0, 502, 207), whitecolor, true);
And it worked fine:
Buuuuuuut....
But I have some scale animations on menu and characters that can't be reproduced with this overload. For example, the image below shows a scale transition for menus that can't be done with this last overload:
So I really need to make the former overload, Draw2dImage(texture, Rect dest, Rect source, color, alpha), to work.
Does any one has a suggestion?
Thanks,
We've been thinking a lot about this and debugging a lot before posting here, and I also checked for similar problems in the forum. I'm almost sure this is an Irrlicht bug, but I'd like to check with advanced users if they even ran on this problem.
First, a few things to keep in mind:
- We are using "power 2" sided textures, this is not a distortion because of the texture image dimensions.
- This is a problem with the overload Draw2dImage(texture, Rect dest, Rect source, color, alpha). It does not happen with Draw2dImage(texture, Pos2D, Rect source, Rect clip, color, alpha) overload. But as I'll explain, unfortunately we can't use this overload on our project.
OK, now, this is the image loaded in memory (512x512), and the area I marked with red is a slice that I'll render on a given point of the screen using Draw2dImage():
Now, I will draw it using the following call:
IrrVideoDriver.Draw2DImage(tex, new Rect(290, 20, 502, 207), new Rect(300, 325, 512, 512), whitecolor, true);
The result is a draw with distortion on its pixels, where I marked red:
But check the yellow mark above. This slice is rendered from the same texture, uses the same Draw2dImage() code, on the same class, but its pixels are fine! This distortion is actually random, and this another screen confirms it:
So I guessed the engine was somehow missing the coordinates of the dest rect by one pixel. Then I forced a -1 subtraction on the first X and Y of the dest rect, as follows:
IrrVideoDriver.Draw2DImage(tex, new Rect(290-1, 20-1, 502, 207), new Rect(300, 325, 512, 512), whitecolor, true);
And it solved the problem... for a while:
But I soon realized that this fix wouldn't work on all machines. I tested on another video card, and the distortion returned. And as the test continued, on each machine different slices were distorted or just rendered fine.
So I decided to try another overload, Draw2dImage(texture, Pos2D, Rect source, Rect clip, color, alpha). The call became:
IrrVideoDriver.Draw2DImage(tex, new Position2D(290, 20), new Rect(300, 325, 512, 512), new Rect(0, 0, 502, 207), whitecolor, true);
And it worked fine:
Buuuuuuut....
But I have some scale animations on menu and characters that can't be reproduced with this overload. For example, the image below shows a scale transition for menus that can't be done with this last overload:
So I really need to make the former overload, Draw2dImage(texture, Rect dest, Rect source, color, alpha), to work.
Does any one has a suggestion?
Thanks,