Polygon fill mode unexpected result

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
dlumo
Prole
Posts: 2
Joined: Sun Jan 29, 2017 4:32 pm

Polygon fill mode unexpected result

Post 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?
Attachments
test.png
test.png (3.48 KiB) Viewed 2183 times
line.png
line.png (138.86 KiB) Viewed 2183 times
fill.png
fill.png (10.18 KiB) Viewed 2183 times
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Polygon fill mode unexpected result

Post 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").
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Polygon fill mode unexpected result

Post by raidho36 »

Yea I'll work on patching that when I get a chance. Too many projects, to little time... :crazy:
dlumo
Prole
Posts: 2
Joined: Sun Jan 29, 2017 4:32 pm

Re: Polygon fill mode unexpected result

Post 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.
Attachments
IMG_20170129_205646.jpg
IMG_20170129_205646.jpg (57.98 KiB) Viewed 2174 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests