[solved] Canvases

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
Purple Fedora
Prole
Posts: 23
Joined: Fri Oct 26, 2018 8:41 pm

[solved] Canvases

Post by Purple Fedora »

If I want to draw something to a canvas, do I need to put the draw functions to draw something on to the canvas in the love.draw function? And how do I draw something to a canvas?
Last edited by Purple Fedora on Wed Nov 21, 2018 10:47 pm, edited 1 time in total.
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: Canvases

Post by MrFariator »

Code: Select all

-- create a canvas somewhere outside love.draw
local myCanvas = love.graphics..newCanvas ( width, height, {format="normal"}, 1 )

-- set the canvas inside love.draw, and clear its contents if need be
love.graphics.setCanvas ( myCanvas )
love.graphics.clear()

-- draw things to canvas with love.graphics.draw, love.graphics.rectangle, or other methods here

-- unset the canvas
love.graphics.setCanvas()

-- draw the canvas to screen
love.graphics.draw ( myCanvas, x, y, rotation, scaleX, scaleY )
When you draw stuff between the "set" and "unset" steps, everything you draw ends up on the canvas.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Canvases

Post by zorg »

To actually answer part of your question, unlike drawing to the screen (more or less) directly, you can render stuff to a canvas outside of love.draw... but unless you're just pre-rendering some static stuff, i'd (erase, and) draw to canvases in love.draw too.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Purple Fedora
Prole
Posts: 23
Joined: Fri Oct 26, 2018 8:41 pm

Re: Canvases

Post by Purple Fedora »

MrFariator wrote: Sat Nov 03, 2018 12:23 am

Code: Select all

-- create a canvas somewhere outside love.draw
local myCanvas = love.graphics..newCanvas ( width, height, {format="normal"}, 1 )

-- set the canvas inside love.draw, and clear its contents if need be
love.graphics.setCanvas ( myCanvas )
love.graphics.clear()

-- draw things to canvas with love.graphics.draw, love.graphics.rectangle, or other methods here

-- unset the canvas
love.graphics.setCanvas()

-- draw the canvas to screen
love.graphics.draw ( myCanvas, x, y, rotation, scaleX, scaleY )
When you draw stuff between the "set" and "unset" steps, everything you draw ends up on the canvas.
I have seen your code but why do things get discoloured?
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Canvases

Post by zorg »

Because you forgot to setColor(1,1,1) before drawing the canvas to the screen; the graphics state remembers the last set color, and if you're not careful, it can tint things you don't want tinted.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 228 guests