• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Weird contour around sprites when surface is drawn (OpenGL only?)

Starfag

Member
Hi!

I'm using surfaces to copy the screen content before deactivating all other instances (like a pause screen). When the surface is drawn, it presents a weird contour around objects (see image). You can see that there is a gray contour around the door, the wardrobe, the mat and even the corner of the wall! The book itself does not have this contour, which implies that it happens on the surface copy/draw process. This problems occurs on Desktop, Android and HTML5 with WebGL enabled. If I disable WebGL, this does not happen. Also, I'm not using any shaders.

ex.png

I'm creating the surface in the Draw Event
GML:
if(surface_exists(surf_bg)){
    draw_surface_stretched(surf_bg, 0, 0, view_wport[0], view_hport[0]);
    surf_mustRedraw = false;
}
else{
    surf_bg = surface_create(surface_get_width(application_surface), surface_get_height(application_surface));
    surf_mustRedraw = true;
    instance_activate_all();
    exit;
}
and copying/drawing it in the Draw End event.
GML:
if(surf_mustRedraw){
    if(surface_exists(surf_bg)){
        surface_copy(surf_bg, 0, 0, application_surface);
        draw_surface_stretched(surf_bg, 0, 0, view_wport[0], view_hport[0]);
        deactivate_instances();
    }   
}
Does anyone have a clue of why this happens? Thank you!
 

Ricardo

Member
When you create surf_bg you're using surface_get_width(application_surface) and surface_get_height(application_surface). When rendering it, you're using view_wport[0] and view_hport[0] along with draw_surface_stretched. If the surface is been stretched down when drawing that can result in some artifacts due to pixel interpolation. If that's not the case, you could try to disable color blending when drawing the surface. Like this:
gpu_set_blendenable(0)
draw_surface_stretched(surf_bg, 0, 0, view_wport[0], view_hport[0]);
gpu_set_blendenable(1)
 

Starfag

Member
Thanks for your reply, Ricardo! Even when I create and draw the surface using view_wport/view_hport, and disabling color blending, the result is the same. Also, this does not happen in HTML5 with WebGL disabled, but as soon as I enable it, it happens the same way as Desktop and Android.
 

Ricardo

Member
Hmm, I see. I suspected it could be a color blending issue because HTML5 (WebGL disabled) doesn't support it.
I still think it has something to do with interpolation and stretching the surface while it is being draw, though.

I also noticed other thing: You are coping the application surface into surf_bg instead of drawing into it? I'd do it other way myself, something like:

GML:
surface_set_target(surf_bg);
draw_clear_alpha(c_black,0.0); // clear surf_bg
// draw application surface here. You can try to disable interpolation while drawing it to surf_bg to see if that's what causing the issue (gpu_set_texfilter(0))
surface_reset_target();
 

Starfag

Member
Hey, it worked! Actually, I made a mix of the two solutions you proposed. Making it like this solved the problem! Thank you!
GML:
surface_set_target(surf_bg);
gpu_set_blendenable(false);
draw_surface(application_surface, 0, 0);
gpu_set_blendenable(true);
surface_reset_target();
 
Top