Grab part of screen, draw, replace

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
mr_happy
Citizen
Posts: 84
Joined: Fri Mar 18, 2016 8:57 pm

Grab part of screen, draw, replace

Post by mr_happy »

I'm sure I've done this before, but I haven't done any coding of late and can't recall how to go about it:

I need to copy part of the back-buffer (or whatever its called these days), draw some stuff on it then copy it back to the screen before it's displayed. The part being copied, drawn to then copied back, is of constant size so doesn't need to be created on the fly. What's the quickest way to do this?

In other libraries I've used it would be a case of creating a new image, copying a quad to it from the back-buffer, setting it as the draw target, drawing then copying it back. I'm getting lost in canvases and imagedata on the wiki! No code example required, just a nudge in the right direction would be great.

TIA
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Grab part of screen, draw, replace

Post by raidho36 »

You can draw to an intermediate render target, then perform manipulations with it, and finally put it on the screen.
User avatar
mr_happy
Citizen
Posts: 84
Joined: Fri Mar 18, 2016 8:57 pm

Re: Grab part of screen, draw, replace

Post by mr_happy »

raidho36 wrote: Wed Feb 21, 2018 6:55 pm You can draw to an intermediate render target, then perform manipulations with it, and finally put it on the screen.
Hehe yeah that's pretty much what I want to do (well, do a normal draw, copy part of that to the intermediate target etc) just can't see how atm :D
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Grab part of screen, draw, replace

Post by pgimeno »

To make it general, you need two canvases. One would be the back buffer, and the other the copied quad.

You would draw to the backbuffer canvas rather than to the screen, and in love.draw, you would draw the backbuffer to the screen.

To copy a quad, you need to draw that canvas on the second canvas.

There are probably better ways for specific usages.
User avatar
mr_happy
Citizen
Posts: 84
Joined: Fri Mar 18, 2016 8:57 pm

Re: Grab part of screen, draw, replace

Post by mr_happy »

pgimeno wrote: Wed Feb 21, 2018 7:17 pm To copy a quad, you need to draw that canvas on the second canvas.
There are probably better ways for specific usages.
Thanks for the help, got it now. Must be my age :D
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 63 guests