Virtual resolution BMax1.35 and aspect ratio ?

BlitzMax Forums/BlitzMax Programming/Virtual resolution BMax1.35 and aspect ratio ?

Armitage 1982(Posted 2009) [#1]
Hi

Since I don't want to be too off-topic I create this one so I can post 2 pictures and ask a question.

In this picture you can see both virtual resolution and real resolution of 1024x768.
This is exactly how it should appear :


Now I stick to a virtual resolution of 1024x768 but rendering my game in 640x480 :


You can see that black borders of every 'camera' viewport are shifted by 1 or 2 pixels but also some of my tiles are now rendered with gap (look at the grass floating in the middle tiny screen). I suppose it's due to the resolution reduction, viewport cannot precisely draw itself at the exact desired position/size and draw functions are affected in some way.

This also happen while I try higher virtual resolution :-(

Do the currently missing aspect ratio for virtual resolution has something to do with that or is there something I can do ?
I could eventually only allow 640x480, 800x600 ,1024x768 and 1280x1024 resolution for the missing ratio but the above problem will persist...
Any help ?

Thanks


therevills(Posted 2009) [#2]
Sounds bit like what Grey Alien and ImaginaryHuman was talking about in this post:

http://blitzmax.com/Community/posts.php?topic=84098


Armitage 1982(Posted 2009) [#3]
Thanks for the link Therevills.
I have roughly read the whole thread.
Does appear to have connection with this problem although I still need to consider the proposed solutions (seems hardly feasible at this stage).
I need to dig this out.


ImaginaryHuman(Posted 2009) [#4]
If the virtual resolution is adjusting the projection matrix, then the only change is in the calculation that converts game-world coordinates into window coordinates. If you are rendering to integer pixel coordinates, maybe this translation causes some rounding errors that result in the gaps?


Armitage 1982(Posted 2009) [#5]
Hi

I'm using float values everywhere but it's definitely caused by rounding errors.

In fact the viewport is in pixel coordinates and cannot be correctly rounded.
I try to move camera with the mouse and it appear to render correctly on certain position (no more gap).

Depend on the size of that viewport (eg 320x240) the last Y and X pixel is invisible too (no black border for the same reasons).

I "simply" need to round my camera size and find the correct position to avoid that bug.
Hope it won't be a problem at higher resolution or ugly somewhere.


ImaginaryHuman(Posted 2009) [#6]
The viewport is defined with whole integer coordinates, because it's `window coordinates`, not game coordinates. The window is made of whole pixels.


Armitage 1982(Posted 2009) [#7]
I still need to understand the magic numbers behind this because :

Virtual Resolution 1024x768
Real Resolution 640x480

For a nearest viewport of 320 x 240 correctly rendered in cender of the screen I need to :
Resize viewport to 317 x 237
Position it to X:349.0, Y:261.0

Any ~8 pixels size and/or position around will corrupt my rendering scene.

My scale ratio is 1.6 (Virtual Resolution / Real Resolution) so those numbers are a bit strange.

I need to understand this because if I set a real resolution of 800x600 then those numbers aren't correct anymore and gap appears again :-(
I need to add something in relation with the 1.6 ratio somewhere in my camera code but what...


ImaginaryHuman(Posted 2009) [#8]
I notice that:

1024/320 = 3.2
768/240=3.2

And I notice that 317 is 320-3 (approx), and 237 is 240-3, approx.

Is that the math you need? ie X=320-(VirtualWidth/ViewportWidth), and Y=240-(VirtualHeight/VirewportHeight)?

I've no idea if that works out at other resolutions, I Just noticed that you have a difference of about 3 pixels.


Armitage 1982(Posted 2009) [#9]
Since position (0,0) is always the same at any resolution I use that coordinates to find a correct viewport size.
Unfortunately with the above solution I still miss 1 vertical and 1 horizontal line of pixels.

One truly compatible size in every common resolution is (0,0,250,141)

but virtual resolution of 1024x768 to real resolution of 640x480 (ratio 1.6) 800x600 (ratio 1.28) and 1280x1024 (ratio 0.8) give :

250/1.6=156.25
250/1.25=195.3125
250/0.8=312.5

141/1.6=88.125
141/1.25=112.8
141/0.8=176.25

It's non-sense to me.
Maybe I am not taking the problem correctly ...


Armitage 1982(Posted 2009) [#10]
I wrote a little program that nearly reproduce that problem : http://blitzmax.com/Community/posts.php?topic=87819#997236

250x141 are useless values since only working at (0,0) and nowhere else.

True headache :-)