Page 1 of 1

Polygon fill mode unexpected result

Posted: Sun Jan 29, 2017 7:21 pm
by dlumo
Hi there!

I'm trying to implement a simple softwared based 3d renderer.
So far I'm able to load and render .obj files exported from blender. To draw the faces of the model I use the love.graphics.polygon() function. This works as expected when using the fill option, however when using the line option to basically render the model in wireframe mode things start to look weird.

I've included a simple script to replicate the issue I'm having:

Code: Select all

function love.load()
    x = 99
end

function love.draw()
    love.graphics.setLineWidth(2)
    love.graphics.rectangle("line",10,10,100,100)
    love.graphics.polygon("line",x,20,100,10,100,110,x,90)
end

function love.update(dt)
end

function love.keypressed(k)
    
    if k == "escape" then love.event.push("quit") end
    if k == "right" then x = x + 1 end
    if k == "left" then x = x - 1 end
    print(x)
end
As soon as the left and right sides of the polygon nearly overlap the rendered height of the polygon does not seem right as it should basically appear as a straight 100px long line(see attached file).
Has anybody a workaround for this?

Re: Polygon fill mode unexpected result

Posted: Sun Jan 29, 2017 7:32 pm
by Nixola
That's due to the default [wiki]LineJoin[/wiki] (miter) doing its work. If you need to not have that kind of thing, e.g. when working with narrow or possibly arbitrary angles (as you're doing), you should [wiki]love.graphics.setLineJoin[/wiki]("bevel").

Re: Polygon fill mode unexpected result

Posted: Sun Jan 29, 2017 7:37 pm
by raidho36
Yea I'll work on patching that when I get a chance. Too many projects, to little time... :crazy:

Re: Polygon fill mode unexpected result

Posted: Sun Jan 29, 2017 7:58 pm
by dlumo
Nixola wrote:That's due to the default [wiki]LineJoin[/wiki] (miter) doing its work. If you need to not have that kind of thing, e.g. when working with narrow or possibly arbitrary angles (as you're doing), you should [wiki]love.graphics.setLineJoin[/wiki]("bevel").
Thank you! None seems to to the trick.