fakecanvas: canvases for everyone??? [tldr: barely]

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
StoneCrow
Party member
Posts: 199
Joined: Sat Apr 17, 2010 9:31 am
Location: Wales the land of leeks and leaks
Contact:

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by StoneCrow » Sat Aug 04, 2012 11:04 pm

This is interesting,
in my projects I just add this to the start of my canvas draw function (canrend)

Code: Select all

function canrend()
        if settings.canvases then
	        synth.canvas:clear()
	        love.graphics.setCanvas(synth.canvas)
        end
...
and then incase someone has them turned off I just have this in the draw code

Code: Select all

if not settings.canvases then
        canrend()
        --[[I add some bits here to simulate the edges of the canvas if it scrolls and then put this bit of code above everything else with the actual draw function for with canvases below at the proper place.]]
end
This is slower for non-canvas users but simple renders everything normally and the canvas draw code can be reused for the normal draw code because when canvases are off it just runs through like a normal draw section.
Not sure how fast this is but it gets the job done :)
Dull but sincere filler.

User avatar
Ref
Party member
Posts: 682
Joined: Wed May 02, 2012 11:05 pm

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Ref » Thu Aug 09, 2012 3:27 am

Hi Xgolf!
Trying to understand exactly how you are creating fakecanvases (not too bright here).
I trimed out everything I could - leaving only things I think (guess) deals with fakecanvases.
I think that I am actually generating a fake canvas.
The problem I'm having is putting a background image behing the canvas.
The follow doesn't work:

Code: Select all

--  in love.load
img = gr.newImage( 'Star.png')
-- in love.load
gr.draw('img',0,0)  --<== error, should be gr.draw(imag,0,0) - thank's Robin!
Error says wrong data type - looking for userdata (I guess a canvas).
You are obvious overloading gr.draw.
Also gr.update(dt) isn't available. -- <= error, had non-printing character in update
Help would be greatly appreciated to better understand how you are avoiding canvases.
Attachments
fakecanvas_test2.love
updated test of fakecanvas
(18.02 KiB) Downloaded 64 times
Last edited by Ref on Thu Aug 09, 2012 3:28 pm, edited 1 time in total.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Robin » Thu Aug 09, 2012 9:01 am

Erhm. Why are you doing

Code: Select all

gr.draw('img',0,0)
instead of

Code: Select all

gr.draw(img,0,0)
?
Help us help you: attach a .love.

User avatar
Ref
Party member
Posts: 682
Joined: Wed May 02, 2012 11:05 pm

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Ref » Thu Aug 09, 2012 2:04 pm

Robin wrote:Erhm. Why are you doing

Code: Select all

gr.draw('img',0,0)
instead of

Code: Select all

gr.draw(img,0,0)
?
Thanks Robin.
A real noob error.
Cudos to Xgolf.
Now for the love.update question.
How did I screw that up?
The follow doesn't work:

Code: Select all

function love.updata(dt)
    angle=angle<2*math.pi and angle+math.pi/1440 or 0
    end
but if I put at the top of love.draw:

Code: Select all

angle=angle<2*math.pi and angle+math.pi/1440 or 0
I get the expected rotation.
Edit:
All's well!
Must have had a non-printing error in my love.update(dt)
Copied & pasted a love.up(dt) from another script and now everything's OK.
My bad!
Now if I could only understand how Xgolf does his magic :awesome:

User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Xgoff » Thu Aug 09, 2012 4:20 pm

basically, it's a really hacky method of taking a screenshot (and pushing it, with some other information, onto a stack), clearing the screen, drawing the requested canvas' image as it was the last time it was used, allowing further draw calls to be done on this surface until another setCanvas() call. you basically repeat this until you have a no-argument setCanvas() call, in which case you save the current image to whichever canvas was used last, then clear the stack and restore the background. there's more involved ('taking a screenshot' is simplifying this a lot), but that's more or less the process

so in effect, you're using the main framebuffer as scratch space while you're drawing into the current "canvas"

it's still not entirely correct from some of the tests i have done on a few of the canvas-using .love files i've seen on here, so the process still needs some tweaking

User avatar
Ref
Party member
Posts: 682
Joined: Wed May 02, 2012 11:05 pm

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Ref » Thu Aug 09, 2012 6:36 pm

Xgoff wrote:basically, it's a really hacky method of taking a screenshot (and pushing it, with some other information, onto a stack), clearing the screen, drawing the requested canvas' image as it was the last time it was used, allowing further draw calls to be done on this surface until another setCanvas() call. you basically repeat this until you have a no-argument setCanvas() call, in which case you save the current image to whichever canvas was used last, then clear the stack and restore the background. there's more involved ('taking a screenshot' is simplifying this a lot), but that's more or less the process
so in effect, you're using the main framebuffer as scratch space while you're drawing into the current "canvas"
it's still not entirely correct from some of the tests i have done on a few of the canvas-using .love files i've seen on here, so the process still needs some tweaking
Think I'm getting closer to what's going on - please correct if not quite correct.
newScreenshot() creates an image from the data in the background buffer.
OK, this is what I think you are doing (made simple for people with limited IQs):
1. take a screenshot of data in background buffer => original data image
2. clear the background buffer => love.graphics.clear()
3. draw something to the background buffer
4. take a screenshot of the new drawing => drawing image
5. clear the buffer => love.graphics.clear()
6. reload original data to buffer <= original data image
7. switch buffers => love.draw()
8. use drawing image as a fakecanvas
If this is even close to correct, how are different size fakecanvas created as the buffers are screen size?
Hope I'm not too far out in left field.

User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Xgoff » Thu Aug 09, 2012 8:01 pm

Ref wrote:
Xgoff wrote:basically, it's a really hacky method of taking a screenshot (and pushing it, with some other information, onto a stack), clearing the screen, drawing the requested canvas' image as it was the last time it was used, allowing further draw calls to be done on this surface until another setCanvas() call. you basically repeat this until you have a no-argument setCanvas() call, in which case you save the current image to whichever canvas was used last, then clear the stack and restore the background. there's more involved ('taking a screenshot' is simplifying this a lot), but that's more or less the process
so in effect, you're using the main framebuffer as scratch space while you're drawing into the current "canvas"
it's still not entirely correct from some of the tests i have done on a few of the canvas-using .love files i've seen on here, so the process still needs some tweaking
Think I'm getting closer to what's going on - please correct if not quite correct.
newScreenshot() creates an image from the data in the background buffer.
OK, this is what I think you are doing (made simple for people with limited IQs):
1. take a screenshot of data in background buffer => original data image
2. clear the background buffer => love.graphics.clear()
3. draw something to the background buffer
4. take a screenshot of the new drawing => drawing image
5. clear the buffer => love.graphics.clear()
6. reload original data to buffer <= original data image
7. switch buffers => love.draw()
8. use drawing image as a fakecanvas
If this is even close to correct, how are different size fakecanvas created as the buffers are screen size?
Hope I'm not too far out in left field.
that's more or less how it works

differently-sized canvases are done by simply pasting only the needed portion of a screenshot into the canvas imagedata

User avatar
Ref
Party member
Posts: 682
Joined: Wed May 02, 2012 11:05 pm

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by Ref » Thu Aug 09, 2012 8:43 pm

Xgoff wrote:
Ref wrote:
Xgoff wrote:basically, it's a really hacky method of taking a screenshot (and pushing it, with some other information, onto a stack), clearing the screen, drawing the requested canvas' image as it was the last time it was used, allowing further draw calls to be done on this surface until another setCanvas() call. you basically repeat this until you have a no-argument setCanvas() call, in which case you save the current image to whichever canvas was used last, then clear the stack and restore the background. there's more involved ('taking a screenshot' is simplifying this a lot), but that's more or less the process
so in effect, you're using the main framebuffer as scratch space while you're drawing into the current "canvas"
it's still not entirely correct from some of the tests i have done on a few of the canvas-using .love files i've seen on here, so the process still needs some tweaking
Think I'm getting closer to what's going on - please correct if not quite correct.
newScreenshot() creates an image from the data in the background buffer.
OK, this is what I think you are doing (made simple for people with limited IQs):
1. take a screenshot of data in background buffer => original data image
2. clear the background buffer => love.graphics.clear()
3. draw something to the background buffer
4. take a screenshot of the new drawing => drawing image
5. clear the buffer => love.graphics.clear()
6. reload original data to buffer <= original data image
7. switch buffers => love.draw()
8. use drawing image as a fakecanvas
If this is even close to correct, how are different size fakecanvas created as the buffers are screen size?
Hope I'm not too far out in left field.
that's more or less how it works

differently-sized canvases are done by simply pasting only the needed portion of a screenshot into the canvas imagedata
WOW!
The light blinks on.
Simple test script using just a few simple commands actually worked.
Thanks Xgoff :awesome:

User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: fakecanvas: canvases for everyone??? [tldr: barely]

Post by AntonioModer » Wed Sep 26, 2012 2:59 pm

CANVAS WORK on video card INTEL X3100(Intel 965/963 Graphics Media Accelerator, driver v6.14.10.5218) on Windows XP SP3:
viewtopic.php?f=4&t=11008#p66302
Thanks user Boolsheet.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests