GMS 2 Drawing to surface on many objects without reset_surface_target()

Discussion in 'Programming' started by Michael Stearns, Jun 12, 2019.

  1. Michael Stearns

    Michael Stearns Member

    Joined:
    Jul 3, 2017
    Posts:
    17
    Hey everybody~

    I'm trying to do a bit of a strange thing where, explaining briefly, I want to draw a bunch of low res objects on top of a big high res object. It's a single screen game. To accomplish this cleanly, I thought I'd draw all the objects to a surface at low resolution, then in GUI Draw events, draw the background, and then the new surface with all the objects scaled up. Possibly this is a terrible idea, but it (almost) does what I intended. Here's the order everything happens in, just to be clear:

    Surface Object (Begin Draw): Make sure surface exists, clear it, etc, leave it open as the draw target
    Draw events for all objects: Draw like normal
    Draw End (Surface Object): reset draw target
    background object (Draw GUI): Draw like normal
    Surface Object (Draw GUI): Draw surface scaled up to fill GUI layer

    The order is definitely correct and everything is working, but the surface always ends up covering the entire screen, as if the clear command (draw_clear_alpha(c_black, 0)) executed in the Surface Object's Draw Begin was setting the whole screen to be solid black. So the result is it draws everything except for the background (it is drawing the background, it's just covered up). I figured this had to do with blend modes, you know, my Arch-Nemesis, but I did some experiments:

    - If I reset the draw target immediately after clearing the surface, it does what I expect (that is, it draws "nothing" over the whole screen instead of a big black rectangle. Or more accurately, it draws a big black rectangle with an alpha of zero).

    - If I reset the draw target after clearing the surface, and then set and reset it for each individual object, it also does what I expect--it creates a surface that is mostly alpha = 0, but draws the sprite objects exactly where they're supposed to be, no problems. It does not seem to matter if an object has alpha values are not.

    So it seems like the problem was with my assumption that I could just set the surface target, let a ton of objects do their own draw events, and then reset it. The documentation implies that this sort of thing should be possible (or at least, implies that this is what will happen if you don't reset the target) so I'm left to wonder if I'm doing something wrong or if the entire concept was flawed? Obviously I can just keep setting the surface target, but it seems like there should be a better way!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice