GML SOLVED: Drawing A Surface Onto Another Surface From Another Object


Paris Stalker

Hi all,

I know it's possible to create a surface in an object and then use the with() function to draw multiple other objects onto that surface whilst it's targeted, and have managed to use this successfully.

However, in an attempt to optimise my draw pipeline I was hoping I could do the following:

- Draw onto two surfaces within two objects
- Then draw those two surfaces onto another surface in a control object

But no matter which way I try to do this, all it ends up doing is just drawing the two surfaces as if I hadn't set the target to the new combined surface, implying that nothing is being drawn to the new surface. Due to the nature of how surfaces work, is it simply not possible to do this?

I have tried a lot of variations, but the first code I tried that is most comparable to the normal with() style is:

// Players Scaled Up Surface
if (!surface_exists(player_scale_surf)) {player_scale_surf = surface_create(640,360);}


with (obj_player)
if (surface_exists(surf))


//Draw Character Surface
EDIT: If you're wondering why not just draw the objects straight onto the combined surface, I am using a shader with different inputs per each of the two starting object's surfaces, so if I drew them onto the same surface I could not have the different parts.
Last edited by a moderator:

Paris Stalker

I solved this issue by drawing onto the first two surfaces from the same object that I wanted to use the final combined surface on rather than within those. I was struggling because I think I'd written an incorrect value somewhere for the surface initiating.

So for example put the following all within one objects draw event:

- Create Surface A
- Set target to Surface A
- Draw all of Object A's draw code onto Surface A using with()
- Reset Surface Target

- Repeat above steps for Surface B

- Create Surface C
- Set target to Surface C
- Draw Surface A && Surface B
- Reset Target
- Draw final Surface C