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

P

Paris Stalker

Guest
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);}

surface_set_target(player_scale_surf);
draw_clear_alpha(c_black,0);

with (obj_player)
{
if (surface_exists(surf))
{
draw_surface_ext(surf,0,0,1,1,0,c_white,1);
}
}

surface_reset_target();

//Draw Character Surface
better_scaling_draw_surface(player_scale_surf,0,0,3,3,0,c_white,1,3);
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:
P

Paris Stalker

Guest
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:

--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
 
Top