[SOLVED] Running with Scissors (Scissors causing flickering)

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.
User avatar
SelfDotX
Prole
Posts: 25
Joined: Sun Oct 02, 2022 5:06 pm

[SOLVED] Running with Scissors (Scissors causing flickering)

Post by SelfDotX »

[SOLVED] Seems the issue was the MSAA setting - I had it on 0, changed it to 1, works like a charm. Thanks again Bigfoot for all your help.
---------------------------
The code below produces extreme flickering. I'm looking to understand why, and how to fix it. This was something of an experiment to see if I could save on some draw calls by 'ignoring' a part of the screen after drawing what I need there once. I can see that it's "working", poked around in love.run() but nothing I did stopped the flickering.

Code: Select all

local heartbeat = 0
local heartbeatrise = true
local curColor = { 1, 1, 1, 1 }

function love.load()
    love.graphics.setColor(0, 1, 0, 1)
    love.graphics.rectangle("fill", 0, 0, 800, 600)
    love.graphics.setScissor(0, 0, 400, 600)
end

function love.update(dt)
    --Heartbeat timer
    if (heartbeatrise) then
        heartbeat = heartbeat + dt
        if (heartbeat >= 1) then
            heartbeat, heartbeatrise = 1, false
            curColor = { 1, 1, 1, 1 }
        end
    else
        heartbeat = heartbeat - dt
        if (heartbeat <= 0) then
            heartbeat, heartbeatrise = 0, true
            curColor = { 1, 0, 0, 1 }
        end
    end
end

function love.draw()
    love.graphics.setColor(curColor)
    love.graphics.rectangle("fill", 0, 0, 400, 600)
end
Last edited by SelfDotX on Mon Apr 10, 2023 9:45 pm, edited 3 times in total.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Running with Scissors

Post by Bigfoot71 »

Here is the result for me, I have no flickering unless I misunderstood the problem:
Image
My avatar code for the curious :D V1, V2, V3.
User avatar
SelfDotX
Prole
Posts: 25
Joined: Sun Oct 02, 2022 5:06 pm

Re: Running with Scissors

Post by SelfDotX »

Nope, no misunderstanding - for me the green side flickers black/green 60x a second - must be either a graphics/driver setting on my end. Any ideas where to start troubleshooting?
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Running with Scissors

Post by Bigfoot71 »

First I will check for driver updates, otherwise I found this page which talks about it for OpenGL and which describes the same problem as you, it would apparently be a double buffering problem.

https://anirudhsasikumar.net/blog/2006.03.04.html

However, I don't currently see how to replicate what is shown in the OpenGL example in love2d for your case, I'm looking on my side, otherwise someone else might already have the solution.

Edit: You could try this but it's only theoretical since I can't reproduce it on my hardware:

Code: Select all

local heartbeat = 0
local heartbeatrise = true
local curColor = { 1, 1, 1, 1 }

function love.load()

    -- We draw once --

    love.graphics.setColor(0, 1, 0, 1)
    love.graphics.rectangle("fill", 0, 0, 800, 600)

    -- Render it, so that the previous rectangle is in the back buffer --

    love.graphics.present()

    -- Redraw the rectangle in front buffer --

    love.graphics.rectangle("fill", 0, 0, 800, 600)

    -- Apply the scissors --

    love.graphics.setScissor(0, 0, 400, 600)

end

function love.update(dt)
    --Heartbeat timer
    if (heartbeatrise) then
        heartbeat = heartbeat + dt
        if (heartbeat >= 1) then
            heartbeat, heartbeatrise = 1, false
            curColor = { 1, 1, 1, 1 }
        end
    else
        heartbeat = heartbeat - dt
        if (heartbeat <= 0) then
            heartbeat, heartbeatrise = 0, true
            curColor = { 1, 0, 0, 1 }
        end
    end
end

function love.draw()
    love.graphics.setColor(curColor)
    love.graphics.rectangle("fill", 0, 0, 400, 600)
end
My avatar code for the curious :D V1, V2, V3.
User avatar
SelfDotX
Prole
Posts: 25
Joined: Sun Oct 02, 2022 5:06 pm

Re: Running with Scissors

Post by SelfDotX »

Thanks for helping out, unfortunately a driver update and the code above haven't solved the issue. The only driver setting that dealt with buffers was the 'TripleBuffering' setting for Nvidia GTX 980 - both on and off no change. Oh well, it's not the end of the world. Thanks again!
User avatar
pgimeno
Party member
Posts: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: Running with Scissors

Post by pgimeno »

I'm not sure why it works in the first place. The graphics driver assumes that you will update the whole screen in every frame. Just don't do that. Use a canvas if you want to leave a part of the screen static, and draw it every frame.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Running with Scissors

Post by Bigfoot71 »

pgimeno wrote: Mon Apr 10, 2023 8:07 pm I'm not sure why it works in the first place. The graphics driver assumes that you will update the whole screen in every frame. Just don't do that. Use a canvas if you want to leave a part of the screen static, and draw it every frame.
I had considered suggesting the use of a canvas to work around the refresh issues associated with using scissors but figured that using a canvas might have a greater impact on performance (although that this remains minimal in any case), because the display must be refreshed at each frame in the area where the canvas is displayed unlike the scissors (unless I'm wrong about the implementation of the scissors in love2d?)

Okay the canvas will still limit the display calculations but think it's a shame to give up a useful feature just because of a compatibility issue. Besides, there must be a solution.
My avatar code for the curious :D V1, V2, V3.
User avatar
SelfDotX
Prole
Posts: 25
Joined: Sun Oct 02, 2022 5:06 pm

Re: Running with Scissors

Post by SelfDotX »

I had meant to include in the OP that I was aware this was easily solvable with other methods. Scissors, by their very definition, and specifically that they clip graphics.clear(), lead me to believe updating only a part of the screen was possible, so that's what I tried - it didn't work for me, but clearly it does work. I have a feeling it has something to do with a very specific graphics card feature/technology/api that I got unlucky on.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Running with Scissors

Post by Bigfoot71 »

Well it's very strange, the gif I shared above was made on an NVidia Quadro NVS 160M (so an old thing)

So I just tried it on a GTX 980 on Parrot Linux and proprietary driver (all info on the left) and it works too. Strange...
Image

But it is at least the proof that there is necessarily a solution.
My avatar code for the curious :D V1, V2, V3.
User avatar
SelfDotX
Prole
Posts: 25
Joined: Sun Oct 02, 2022 5:06 pm

Re: Running with Scissors

Post by SelfDotX »

Really appreciate you looking into it this much. I might try downgrading to the 470 drivers see if that does anything... Other than that there's not a lot I can think of to change on my system.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], CPop and 54 guests