Bug in stretch bitmap code
by Tim Newell · in Torque Game Engine · 02/08/2002 (4:44 pm) · 15 replies
When using transparency there is a bug in the stretch bitmap code....it leaves an artifact on the bottom and right side of the image. This screenshot shows the same image not stretched and stretched:
Before and After
-Tim aka Spock
Before and After
-Tim aka Spock
#2
Go to engine/dlg/dlg.cc and go to the void dglDrawBitmapStretchSR function and in it go to the lines:
Change them to:
-Tim aka Spock
02/08/2002 (5:09 pm)
I have a fix for it...it might be considered a hack but it gets rid of the artifacts:Go to engine/dlg/dlg.cc and go to the void dglDrawBitmapStretchSR function and in it go to the lines:
F32 screenRight = dstRect.point.x + dstRect.extent.x; (line 89) F32 screenBottom = dstRect.point.y + dstRect.extent.y; (line 91)
Change them to:
F32 screenRight = dstRect.point.x + dstRect.extent.x+1; F32 screenBottom = dstRect.point.y + dstRect.extent.y+1;
-Tim aka Spock
#3
First, it stretches the image one pixel more in both directions, so if your images are part of a sliced up interface, this will cause other problems. Second, this fix only hides the defect by pushing off the right and bottom edges, but in some of my images, the stretched image is then shifted, and when the shift is up or to the left, you can see the defect again. I do believe it would work for the average application tho.
I'll add this to my list of things to poke around in... but if you or someone else figures it out before I get to it... :D
02/09/2002 (8:53 am)
I haven't had a chance to track the real problem down, but your fix does work, sorta. There are two problems tho.First, it stretches the image one pixel more in both directions, so if your images are part of a sliced up interface, this will cause other problems. Second, this fix only hides the defect by pushing off the right and bottom edges, but in some of my images, the stretched image is then shifted, and when the shift is up or to the left, you can see the defect again. I do believe it would work for the average application tho.
I'll add this to my list of things to poke around in... but if you or someone else figures it out before I get to it... :D
#4
02/09/2002 (9:02 am)
Is this the same reason why there is a weird line along the bottom and right side of the main menu background?
#5
i think it has to do with bilin filtering and averaging of edge pixels, or with the clamp/wrap mode, or both.
d
02/09/2002 (11:24 am)
these sorts of artifacts also show up with anti-aliasing in a lot of cases.i think it has to do with bilin filtering and averaging of edge pixels, or with the clamp/wrap mode, or both.
d
#6
02/09/2002 (1:08 pm)
Yeah, well, I dug around this morning, and I'm baffled, so I'll let you gurus figure this one out. :]
#7
-Tim aka Spock
02/09/2002 (2:06 pm)
I figured it was a hack since it was so easy and looked hackish :) If I figure out the real solution I'll let everyone know.....but like you said, for what I'm doing it works.-Tim aka Spock
#8
right above were you would have done the previous hack, do this one instead:
The -1s are what I added
-Tim aka Spock
02/09/2002 (2:22 pm)
here is another Hack...see if it fixes either one of your problems from before...I'm guessing no but its worth a try.right above were you would have done the previous hack, do this one instead:
F32 texRight = F32(srcRect.point.x + srcRect.extent.x-1) / F32(texture->texWidth); F32 texBottom = F32(srcRect.point.y + srcRect.extent.y-1) / F32(texture->texHeight);
The -1s are what I added
-Tim aka Spock
#9
The edge artifacts were caused when a bitmap is stretched and the bilinear filtering (thanks David), causes a read outside of the boundaries of the bitmap, but inside the boundaries of the expanded power of 2 bitmap.
Fix: I added code to replicate the right and bottom edges of the bitmap into the expanded regions. It's in CVS now.
02/25/2002 (11:34 am)
ok... figured this one out finally. The problem: bitmaps whose sizes are not powers of two are expanded to fit powers of two in gTexManager.cc (a requirement of most graphics cards for texturing).The edge artifacts were caused when a bitmap is stretched and the bilinear filtering (thanks David), causes a read outside of the boundaries of the bitmap, but inside the boundaries of the expanded power of 2 bitmap.
Fix: I added code to replicate the right and bottom edges of the bitmap into the expanded regions. It's in CVS now.
#10
02/25/2002 (12:59 pm)
Mebbe I'm misunderstanding. That won't create tiling will it?
#11
This fix makes it so that undefined color values from outside the bitmap (but still in the power of 2 texture) don't bleed into the bitmap - by forcing them to be the same.
02/25/2002 (1:21 pm)
Nope... it just replicates the right and bottom (single pixel) edges of the bitmap. Tiling of bitmaps (as in GuiBitmapCtrl) is actually handled by drawing the bitmap multiple times.This fix makes it so that undefined color values from outside the bitmap (but still in the power of 2 texture) don't bleed into the bitmap - by forcing them to be the same.
#12
(I knew how the tiling works as I have spent a fair amount of time working with my own components. I just wasn't clear on what all you were replicating...)
02/25/2002 (1:55 pm)
Ah. I see. Cool. Now my new bitmap-based classes should look better. Thank you.(I knew how the tiling works as I have spent a fair amount of time working with my own components. I just wasn't clear on what all you were replicating...)
#13
Mark, is the problem with GuiChunkedBitmaps the same as this one? if you look at the main menu it has a pixel artifact border across the bottom and right.
-Tim
02/25/2002 (2:56 pm)
I guess my new resource is just a hack...I figured it was.Mark, is the problem with GuiChunkedBitmaps the same as this one? if you look at the main menu it has a pixel artifact border across the bottom and right.
-Tim
#14
1. Bottom and right edge pixels not being filled - due to rounding errors, in some resolutions it was possible that chunked bitmaps weren't filling their right and/or bottom edges. Just checked in the fix for this.
2. Stretch bleeding artifacts from garbage data in pow2 textures. Should be fixed from this morning.
If you are still seeing errors of this after a get, let me know.
02/25/2002 (4:05 pm)
Ok... well there were actually 2 possible errors with GuiChunkedBitmapCtrl:1. Bottom and right edge pixels not being filled - due to rounding errors, in some resolutions it was possible that chunked bitmaps weren't filling their right and/or bottom edges. Just checked in the fix for this.
2. Stretch bleeding artifacts from garbage data in pow2 textures. Should be fixed from this morning.
If you are still seeing errors of this after a get, let me know.
Torque Owner Tim "Zear" Hammock