Legacy GM Draw Screen Into Surface / Using the Application Surface

Heya!
I've been trying to find a way to convert the application surface into a texture so I can use it in shaders.
However, any attempts to draw this surface texture result in the image being repeated into infinity.

This is an undesirable effect, as I want the surface to be drawn a single time without containing an instance of itself.

I am currently achieving this effect by creating a "screen grab" surface, then drawing the application surface into the screen grab surface during the post draw event.
Here is the code from the tests:

Post Draw Event:
Code:
{
    if (surface_exists(global.screenGrab)) {
        surface_set_target(global.screenGrab);
            if (surface_exists(application_surface)) {
                draw_clear(c_black);
                draw_surface(application_surface, 0, 0);
            }
        surface_reset_target();
    }
}
Draw Event:
Code:
var
        _tex = surface_get_texture(global.screenGrab);

draw_primitive_begin_texture(pr_trianglestrip, _tex);
        draw_vertex_texture(x1, y1, 0, 0);
        draw_vertex_texture(x2, y1, 1, 0);
        draw_vertex_texture(x1, y2, 0, 1);
        draw_vertex_texture(x2, y2, 1, 1);
draw_primitive_end();
If there are different or more efficient means of achieving this effect, please let me know.
I would really appreciate the help :) Thank you.
 

jo-thijs

Member
Heya!
I've been trying to find a way to convert the application surface into a texture so I can use it in shaders.
However, any attempts to draw this surface texture result in the image being repeated into infinity.

This is an undesirable effect, as I want the surface to be drawn a single time without containing an instance of itself.

I am currently achieving this effect by creating a "screen grab" surface, then drawing the application surface into the screen grab surface during the post draw event.
Here is the code from the tests:

Post Draw Event:
Code:
{
    if (surface_exists(global.screenGrab)) {
        surface_set_target(global.screenGrab);
            if (surface_exists(application_surface)) {
                draw_clear(c_black);
                draw_surface(application_surface, 0, 0);
            }
        surface_reset_target();
    }
}
Draw Event:
Code:
var
        _tex = surface_get_texture(global.screenGrab);

draw_primitive_begin_texture(pr_trianglestrip, _tex);
        draw_vertex_texture(x1, y1, 0, 0);
        draw_vertex_texture(x2, y1, 1, 0);
        draw_vertex_texture(x1, y2, 0, 1);
        draw_vertex_texture(x2, y2, 1, 1);
draw_primitive_end();
If there are different or more efficient means of achieving this effect, please let me know.
I would really appreciate the help :) Thank you.
There are 2 main kinds of solutions for this.
1) Draw the application_surface to the screen in the "post draw event" or a "draw GUI event" instead of the normal draw event.
Things you draw in the draw event are drawn to the application_surface by default.
Things drawn in the post draw event or a gui event are drawn directly to the screen buffer.
On top of that, these events are performed afer all the regular things have been drawn, so the application_surface is reset.
2) Don't use the application_surface itself, but have everything drawn to a surface you manage yourself (except the shader stuff), then use that surface.
view_surface and view_current might help with this.
 
Top