• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED] Surface Draw - black lines go transparent

Kezarus

Endless Game Maker
Hi everyone!

So, I am drawing everything into a surface and retaining that as a tooltip.

Problem is, all black lines goes transparent and I don't know why. Take a very closer look on the attached image. The issue is around the fonts and the map symbol.

I tried additive blending, clear the surface with and without alpha, drew a black rectangle, etc. All to no avail.

This is what I do at the start of the event that draws the surface. The event is a user event that is called on the Draw GUI event.
Code:
///CLEAN & CREATE SURFACE
if( surface_exists(TooltipSurface) ){
    surface_free(TooltipSurface);
}

TooltipSurface = surface_create( surfaceWidth, 768 );
surface_set_target(TooltipSurface);

draw_clear_alpha(c_black,0);

//DON'T WORK
//draw_set_blend_mode(bm_add);
/*draw_set_alpha(1);
draw_set_colour(c_black);
draw_rectangle(0, 0, surfaceWidth, 768, false);*/

draw_panel( surfaceWidth, 768, c_dkgray, 0, 0 );
This is inside the same event and I use it to draw the buildings tooltip
Code:
///CREATE SURFACE - BUILDING
if( TooltipObj.object_index == objBuilding ){
    var wy = 0;
    var text = "";
   
    //PREPARE DRAW NAME
    draw_set_alpha(1);
    draw_set_colour(c_white);
    draw_set_halign(fa_center);
    draw_set_valign(fa_top);
    draw_set_font(fntTownNames);
   
    //PREPARE DRAW HERALDRY
    var HeraldrySize = sprite_get_height(sprHeraldryBack);
    var wx = (surfaceWidth div 2)-(HeraldrySize div 2);
    var wType = TooltipObj.Type;
    var centerX = surfaceWidth div 2;
   
    with(TooltipObj.TownOwner){
        //DRAW NAME
        draw_text_outline( centerX, wy, Name, -1, 5000, c_black, 1, 0 );
        wy += 25;
       
        //DRAW TYPE
        draw_set_font(fntTooltip);
        draw_text_outline( centerX, wy, TownBuildToText(wType), -1, 5000 );
        wy += 18;
       
        //DRAW HERALDRY
        draw_sprite_stretched_ext(sprHeraldryBack, 0,
            wx, wy, HeraldrySize, HeraldrySize, HeraldryColor1, 1);
        draw_sprite_stretched_ext(sprHeraldryPatterns, HeraldryPattern,
            wx, wy, HeraldrySize, HeraldrySize, HeraldryColor2, 1);
        draw_sprite_stretched_ext(sprHeraldrySymbols, HeraldrySymbol,
            wx, wy, HeraldrySize, HeraldrySize, HeraldryColor3, 1);
    }
   
    with(TooltipObj){
        draw_set_font(fntTooltip);
        wy += HeraldrySize+5;
        draw_text_outline( centerX, wy, "HP:" + string(ceil(HitPoints)), -1, 5000 );
       
        if(DaysToFinish > 0){
            wy += 14;
            text = string(DaysToFinish) + " days to finish";
            draw_text_outline( centerX, wy, text, -1, 5000 );
        }
       
        draw_set_halign(fa_left);
        wy += (14*2);
        draw_text_outline( 10, wy, TownBuildingDescription(wType), -1, other.surfaceWidth-20 );
    }

}
This is the draw_text_outline:
Code:
/// draw_text_outline(x, y, text, separation, width, *outline_color, *scale, *angle);

/*
separation -   The distance in pixels between lines of
        text as if the string was being drawn.
width - The maximum width (in pixels) of the string
        before a line break as if the string was bring drawn.
*/

var
    x1 = argument[0],
    y1 = argument[1],
    text = argument[2],
    wSep = argument[3],
    wWidth = argument[4],
    wScale = 1,
    wAngle = 0,
    c1 = c_black;

var c2 = draw_get_colour();
if (argument_count > 5){ c1 = argument[5]; }
if (argument_count > 6){ wScale = argument[6]; }
if (argument_count > 7){ wAngle = argument[7]; }

draw_set_alpha(1);
draw_set_color(c1);

draw_text_ext_transformed(x1+1, y1+0, text, wSep, wWidth, wScale, wScale, wAngle);
draw_text_ext_transformed(x1-1, y1+0, text, wSep, wWidth, wScale, wScale, wAngle);
draw_text_ext_transformed(x1+0, y1+1, text, wSep, wWidth, wScale, wScale, wAngle);
draw_text_ext_transformed(x1+0, y1-1, text, wSep, wWidth, wScale, wScale, wAngle);

draw_set_color(c2);

draw_text_ext_transformed(x1, y1, text, wSep, wWidth, wScale, wScale, wAngle);
And this is at the end of the event:
Code:
///RESET SURFACE TARGET

surface_reset_target();
The font is anti-aliased and the sprite have some transparency. Any insight on what is happening will be greatly appreciated.


Thanks!
Kezarus
 

Attachments

I'm not 100% sure I understand your problem completely.

But it sounds like it is a farily typical problem that a lot of people have with writing alpha to a surface.

If you don't want transparency of something being drawn to affect the alpha of the surface, then turn off writing to the alpha channel while you draw it. GMS1: draw_set_colour_write_enable , GMS2: gpu_set_colorwriteenable.

If you need to make parts of your surface transparent, then you have one of two choices. If you don't draw any overlapping semi-transparent things, then you can use the extended blending mode (bm_one,bm_zero). But if you do have overlapping semi-transparencies and you want them to stack correctly, then you have to use pre-multiplied alpha.
 

Kezarus

Endless Game Maker
Hi @flyingsaucerinvasion!

Thanks for you help! I am trying to draw kind of a helper when the player click a city or a building. I draw on the surface and then I just print the surface.

Unfortunately, none of the sugestions solved the problem. I read somewhere that this have something to do with font anti-aliasing, but even the symbol in the shield have some kind of unwanted transparency. =/

draw_set_colour_write_enable(true, true, true, false);
Draws nothing at all. o_Ô

draw_set_blend_mode_ext(bm_one, bm_zero);
upload_2019-6-28_21-40-44.png

Just to test I did this:
draw_set_colour_write_enable(false, false, false, true);
upload_2019-6-28_21-38-43.png
 
So with this:

draw_set_colour_write_enable(true, true, true, false);

The idea is to first set the alpha of the surface to whatever it should be. One way you could do that is by doing draw_clear_alpha.'

Then you'd disable drawing to the alpha channel.

And then you'd draw stuff that has semi-transparencies.

I'm going to look into the anti-aliasing thing with drawing text to see if I'm overlooking something important. And I'll get back to you in a few minutes.
 
Hi again. Looked into the anti-aliasing thing.

I did not detect any problems drawing anti-aliased text to a surface under these conditions:

Normal blending mode. Alpha of surface already set to desired state (in my case, 1). Writing to alpha channel turned off while drawing the text.

It might still be possible that you are having a problem that doesn't occur on my platform or with my version of gamemaker. But I think you should be able to solve your problem with one of the solutions I mentioned above, assuming it is executed correctly.

EDIT: Knowing what your tooltip graphics are supposed to look like might help arrive at a solution faster. EIDT2: Oh, nevermind that... it is fairly obvious what it should look like.
 

Kezarus

Endless Game Maker
So with this:

draw_set_colour_write_enable(true, true, true, false);

The idea is to first set the alpha of the surface to whatever it should be. One way you could do that is by doing draw_clear_alpha.'

Then you'd disable drawing to the alpha channel.

And then you'd draw stuff that has semi-transparencies.

I'm going to look into the anti-aliasing thing with drawing text to see if I'm overlooking something important. And I'll get back to you in a few minutes.
Hi again @flyingsaucerinvasion, thanks a lot for your time trying to help me! =D

So, as I read what you said I realised that I was, yes, clearing the surface, but with draw_clear_alpha(c_black,0)! When I did the following:

Code:
draw_clear_alpha(c_black,1);
draw_set_colour_write_enable(true, true, true, false);
It worked like a CHARM! Thanks man! Really appreciate the help. =D

upload_2019-6-29_9-42-48.png

p.s.: should I call @Nocturne or any other admin to mark this thread as solved? Can I do it?
 
If you want to understand what happened and why the fix hrlped, here's a video tutorial:

To mark a thread solved, just edit the title add [SOLVED] in front.
 
Top