calref / cboe

Classic Blades of Exile
http://spiderwebforums.ipbhost.com/index.php?/forum/12-blades-of-exile/
Other
168 stars 41 forks source link

Game tiles rendering with too-wide or narrow pixels at 1x and 2x scale. #234

Open clort81 opened 4 years ago

clort81 commented 4 years ago

oBoE/sfml is rendering the tiles in the game-world screen at incorrect position.

This can be seen when screenshotting a 2x scaled game and scaling down the image 0.5x in GIMP etc. boe-bug-offsettiles

clort81 commented 4 years ago

Simply zooming-in on the game window rendered at 2.00 reveals the issue. I noticed this happening on rendered text as well!

oboe-sfml-scaling

clort81 commented 4 years ago

Oh it also happens at 1x scale.

Please Notice: 1- it's not only happening at terrain tile boundaries, so the error is not placing tiles at wrong position - it's also widerning one column of the character sprite.

2- checking boe.graphics.cpp, i noticed mainPort.height was set to 1.97xxx while width was set to 2. Changing getMenubarHeight() in winutil.linux.cpp from return 1; to return 0; gave me an integer scale matching UIScale, but that didn't fix this problem.

3- Some text is also being drawn with 1-pixel offset. If I specify the same starting x in the rectangle boxes for the text dialogues, "Party status" and "Inventory" headers fail to line-up. sfmldrawbad

I think i will need to write simple test code to learn how SFML renders these things, and whether the problem is in BoE or SFML.

retropipes commented 4 years ago

Perhaps SFML and BoE aren't in agreement on the tile size, as BoE uses 28x36 tiles. Perhaps SFML just needs to be told that the tiles aren't square? This one's a mystery to me as well.

clort81 commented 4 years ago

With 1x scaling, i'm getting a 'cross' of duplicate tiles in the center of the game world window, but no rendering errors outside of it. Notice the border pixmap (brown) also has duplicate rows/columns, not just terrain. But outside that rectangle, there aren't errors in this screenshot.

badpixels

retropipes commented 4 years ago

This smells like an off-by-one error to me; maybe the map grid is one pixel wider than it should be, or the upper-left tiles are placed one pixel further left than intended, and SFML is compensating by scaling the center tiles slightly - if so, the cause is in BoE.

clort81 commented 4 years ago

Thanks wldwzrd89 - but it's not just the map tiles. It's also the game world border, which is one contiguous .png file.

The borderfile is terscreen.png, which gets loaded to terrain_screen_gworld. The border rectangle is 278x350 pixels.

boe.graphics.cpp: clip_rect(terrain_screen_gworld, {13, 13, 337, 265}); sets a rectangle of 265x324 pixels. 324 is the height of the interior space drawn with tiles but afaict the width should be 252 pixels.

From a screenshot the border rectangle is rendered as 279x351 pixels at scale factor 1x.

-

retropipes commented 4 years ago

Huh. Maybe it's more complex than it appears. It's not impossible that a weird interaction of BoE image placement and SFML scaling is causing this, but teasing out the bad interactions is the tough part.

CelticMinstrel commented 4 years ago

The terrain (including the border) is first rendered to a render texture, then copied to the screen. It might be useful to dump the render texture and see if it already exhibits the duplicated pixels? I don't expect it will, but…