Strange image behavior

BlitzMax Forums/BlitzMax Beginners Area/Strange image behavior

Eikon(Posted 2005) [#1]
Today I was working on my Jill of the Jungle game when I noticed something odd. Any image that's position is tracked with floats becomes blurred when moving it around the screen. Here is a simple example that gives me the same problem on two different machines.
Graphics 320, 240, 32

SetMaskColor 255, 0, 255
img = LoadImage("jill.png", MASKEDIMAGE)

Local jY# = 15

SetColor 255, 255, 255
Repeat
Cls

DrawImage img, 50, jY
DrawText jY, 1, 1

If KeyDown(KEY_UP) Then jY:-.1 ElseIf KeyDown(KEY_DOWN) Then jY:+.1

FlushMem; Flip
Until KeyDown(KEY_ESCAPE)
Required Image:

Press down to move Jill and you'll notice the top and bottom of the image doesn't appear the same when at certain positions. This is causing every tile in my map to randomly change from 16 to 17 pixels tall. Why does this happen and how can it be fixed?


tonyg(Posted 2005) [#2]
Eikon, Same thing happens with me. I converted the code to .bb and all was OK.
I can only assume it's a 'feature' of the 'improved' float
system.
Check...
here
and
here
and
here
If it is caused by this then it's VERY annoying.
Obviously, I reserve the right to be very wrong.


Eikon(Posted 2005) [#3]
Sorry to waste your time, TonyG. Converting the float with Int() fixes the problem. :|

Note to self: Experiment more before posting...


Booticus(Posted 2005) [#4]
Nonsense! Then you rob idiots like me of solutions to problems I havent run into yet!! ;)


ImaginaryHuman(Posted 2005) [#5]
The effect you are seeing is actually correct. What's happening is that your graphics card is probably applying realtime antialiasing on all the pixels to try to represent what the image would look like at a sub-pixel coordinate. This does tend to have the subtle effect of making the image look a little blurred, especially if you're used to seeing solid distinctions between areas of different colors.

Of course, as you found, converting your coords with Int() resolves the issue because when the coordinates are whole numbers there is no antialiasing effect shown.


ImaginaryHuman(Posted 2005) [#6]
You could also try a call to glDisable(GL_POLYGON_SMOOTH) and that might have the same effect of switching off the antialiasing.


tonyg(Posted 2005) [#7]
Hmmm.. I didn't get any blurring just the top of her head went missing every few moves. Same thing was OK on B3D on
the same machine so, in my case, it wasn't the graphics card.
Anyway, it's over now.


Dreamora(Posted 2005) [#8]
DirectX isn't OpenGL.
So just because B3D did something this does not imply that BM does it as well or in the same way


tonyg(Posted 2005) [#9]
I'll consider myself corrected


FlameDuck(Posted 2005) [#10]
Why does this happen and how can it be fixed?
Sub pixel positioning. Since BlitzMAX uses a texel based (or 3D if you wish) coordinate system (as opposed to pixel based) 2,5 is actualy a valid position! Ofcourse since the screen cannot display this position accurately, the 3D hardware is compensating for it by transforming the image.

As you have noticed yourself, the "fix" is to use absolute integer positions.