Trying to understand why text rendering differently with a background in a canvas
Posted: Wed May 09, 2018 8:35 pm
So I have this code (bear in mind this is just something I threw together as I am evaluating Love2D as an alternative to Unity3d for my current project so the structure is probably not great):
Just for context, the basic idea is that I wanted to see how easy it was to create a scrollable ui content area. From my limited knowledge of Love2D, I decide to create 2 canvases, one for the content and 1 for the scrollable viewport and just set an offset when drawing the content in the scrollable viewport (and then just draw the scrollable viewport to the "main canvas"). While I am not sure if this a the best way to do this, lets just ignore that for the time being (unless it is directly related to the text rendering issue).
Now I am drawing the scrollable viewport in an area where I am already drawing a black background however I am drawing another black background in the content canvas which allows me to get the following results:
Initial I did not do this because I think I did not need to however if I remove the black background in the content canvas (the lines I commented as important 1 / 2), I get the following results:
So the main part of my question here is why would the text render different based on the background being nothing (or transparent) vs it explicitly being set as black when it is being drawing on top (a.k.a. after) a black box anyways (though on a different canvas)?
Now I am also opened to any suggestions / critiques people might have about my implementation of the scrollable content outside of you can using library X / Y / Z (part of the allure of using Love2D is that fact it's low level API is much simpler and I think, maybe naively, it is easier to do exactly want you want and nothing more than with something like Unity).
Code: Select all
local inventoryCanvasVertices = {}
local inventoryScreenVertices = {}
local inventoryWidth = 340
local contentHeight = 16000
local viewportHeight = 150
local inventoryContentCanvas = love.graphics.newCanvas(inventoryWidth, contentHeight)
local inventoryViewportCanvas = love.graphics.newCanvas(inventoryWidth, viewportHeight)
function drawInventory()
love.graphics.setCanvas(inventoryContentCanvas)
local topOffset = 180
-- important line 1
love.graphics.setColor(0, 0, 0, 1)
inventoryCanvasVertices = getBoxVertices(0, 0, inventoryWidth, contentHeight)
inventoryScreenVertices =
getBoxVertices(
uiManager.sideInfo.points.topLeft.x + uiManager.inventory.positionOffset.x + uiManager.sideInfo.padding,
uiManager.sideInfo.points.topLeft.y + uiManager.inventory.positionOffset.y + uiManager.sideInfo.padding + topOffset,
inventoryWidth,
contentHeight
)
-- important line 2
love.graphics.polygon("fill", inventoryCanvasVertices)
love.graphics.setColor(1, 1, 1, 1)
drawItem()
love.graphics.setCanvas(inventoryViewportCanvas)
love.graphics.draw(inventoryContentCanvas, 0, 0, 0, 1, 1, 0, uiManager.inventory.scrollOffset)
love.graphics.setCanvas()
love.graphics.draw(
inventoryViewportCanvas,
uiManager.sideInfo.points.topLeft.x + uiManager.inventory.positionOffset.x + uiManager.sideInfo.padding,
uiManager.sideInfo.points.topLeft.y + uiManager.inventory.positionOffset.y + uiManager.sideInfo.padding + topOffset
)
end
Now I am drawing the scrollable viewport in an area where I am already drawing a black background however I am drawing another black background in the content canvas which allows me to get the following results:
Initial I did not do this because I think I did not need to however if I remove the black background in the content canvas (the lines I commented as important 1 / 2), I get the following results:
So the main part of my question here is why would the text render different based on the background being nothing (or transparent) vs it explicitly being set as black when it is being drawing on top (a.k.a. after) a black box anyways (though on a different canvas)?
Now I am also opened to any suggestions / critiques people might have about my implementation of the scrollable content outside of you can using library X / Y / Z (part of the allure of using Love2D is that fact it's low level API is much simpler and I think, maybe naively, it is easier to do exactly want you want and nothing more than with something like Unity).