Rendering problem with Canvas
ddabrahim opened this issue · 3 comments
Hi.
I'm trying to draw a 3D mesh on to a Canvas and then draw the canvas, however it seems it does not render properly.
This is the result I would like to achieve:
But this is what I get if I draw on to a canvas:
Here is an example that reproduce the problem:
g3dtest-canvas.zip
Love 11.4
g3d 1.5.1
macOS 12.2.1
Not entirely certain if it's a bug, could someone please tell me why is this happening and if there is any possible work around, solution to this?
I would appreciate any help.
Thank you.
The issue is not having a depth buffer. There are two ways to add one; one more performant over the other
-- Better
local canvas = {
love.graphics.newCanvas(width, height),
depthstencil = love.graphics.newCanvas(width, height, {format="depth24"}), -- add `readable=true` if you want to be able to read it within a shader
}
love.graphics.setCanvas(canvas) -- the table we just created
-- the other way, faster to get up and running
local canvas = {
love.graphics.newCanvas(width, height),
depth = true, -- let love create the depth buffer for you; unable to pass it into a shader since it's managed internally
}
love.graphics.setCanvas(canvas) -- table we just created
With this you'll have a depth buffer
(as a footnote, if you look at conf.lua in this repo it shows you how to add the depth buffer for the default canvas that you have to do; your last issue with a copy of your project excluded the conf so I had to add it myself just to let you be aware of it) (some system automatically create the depth buffer for you hence why it seemed to work for you previously)
You can also look in the Github wiki, this is listed under the FAQ section. Please look at the wiki next time before posting an issue.
https://github.com/groverburger/g3d/wiki/Can%27t-render-models-to-canvas
Thanks a lot it worked! For some reason I was not aware of the wiki. In the future I am going to check the documentation before posting 👍