• 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!

SOLVED Draw Font to Surface - Alpha problem

JeanSwamp

Member
Hello,

I am currently drawing some sort of inventory/item list with a lot of sprites and text to a surface, so then I can just mask the surface for scrollable purposes.

When drawing text to a surface, the text looks blurry, undefined and messy. After looking around in a lot of threads I found out that using gpu_set_blendenable(true); before drawing the surface and set it back to true after, will make the text look alright.

HOWEVER, since the rest of the surface has a lof of transparent areas, because is a big surface, everything that is transparent turn to black, so this method won't really fix the problem.

Is there any alternative on how to solve this? I can't believe this is even happening that something so simple like drawing text to a surface has bad results.
 
Last edited:

FoxyOfJungle

Kazan Games
Try:
gpu_set_colorwriteenable(true, true, true, false);

Do this before drawing items on the surface. (after surface_set_target).
Don't forget to turn alpha again afterward.
 

JeanSwamp

Member
Try:
gpu_set_colorwriteenable(true, true, true, false);

Do this before drawing items on the surface. (after surface_set_target).
Don't forget to turn alpha again afterward.
Using this alone or combined with the blendenable?

Using it alone makes everything invisible. Using it combined has no effect.
 

FoxyOfJungle

Kazan Games
So, try using it when drawing the surface. Test them both to see which one works.

GML:
gpu_set_blendenable(false);
gpu_set_colorwriteenable(true, true, true, false);

draw_surface(...);

gpu_set_blendenable(true);
gpu_set_colorwriteenable(true, true, true, true);
Don't forget to use draw_clear_alpha() after surface_set_target().

I suggest to you this video:

 

JeanSwamp

Member
So, try using it when drawing the surface. Test them both to see which one works.

GML:
gpu_set_blendenable(false);
gpu_set_colorwriteenable(true, true, true, false);

draw_surface(...);

gpu_set_blendenable(true);
gpu_set_colorwriteenable(true, true, true, true);
Don't forget to use draw_clear_alpha() after surface_set_target().
This is something I've tried also and didn't have good results.
 

JeanSwamp

Member
Normal
GML:
draw_surface(shop_surface,bbox_left,bbox_top + _diff );


Combined
GML:
    gpu_set_blendenable(false);
    gpu_set_colorwriteenable(true, true, true, false);
    draw_surface(shop_surface,bbox_left,bbox_top + _diff );
    gpu_set_blendenable(true);
    gpu_set_colorwriteenable(true, true, true, true);


Only colorwrite - Same result as no filters
GML:
//    gpu_set_blendenable(false);
    gpu_set_colorwriteenable(true, true, true, false);
    draw_surface(shop_surface,bbox_left,bbox_top + _diff );
//    gpu_set_blendenable(true);
    gpu_set_colorwriteenable(true, true, true, true);


GML:
surface_set_target(shop_surface);
    draw_clear_alpha(c_black,0);
    gpu_set_blendenable(false);
    gpu_set_colorwriteenable(true, true, true, false);
    //ALL THE ITEMS DRAWN
    gpu_set_blendenable(true);
    gpu_set_colorwriteenable(true, true, true, true);
    surface_reset_target();
    draw_surface(shop_surface,bbox_left,bbox_top + _diff );


GML:
surface_set_target(shop_surface);
    draw_clear_alpha(c_black,0);
    //gpu_set_blendenable(false);
    gpu_set_colorwriteenable(true, true, true, false);
    //ALL THE ITEMS DRAWN
   //gpu_set_blendenable(true);
    gpu_set_colorwriteenable(true, true, true, true);
    surface_reset_target();
    draw_surface(shop_surface,bbox_left,bbox_top + _diff );
Same result as above
 
Last edited:

JeanSwamp

Member
I am not using a font sprite no.

About Premultiply, I heard that thing before but I have no idea what that is.
 

JeanSwamp

Member
So what do you use to make the outline effect on the text?

I strongly recommend using a font sprite.
Using a font sprite is just a terrible solution if you want to support other languages. Chinese glyphs do not even fit in the biggest GM texture page.

Also. I think I fixed it lol
 
Last edited:

FoxyOfJungle

Kazan Games
What is your solution? Post here to help the next one please.

Edit:
Nocturne was faster.
Why did you remove screenshots from your game? This is important.
 

JeanSwamp

Member
So if you're drawing multiple sprites and text to a surface you must use gpu_set_colorwriteenable(true, true, true, false); only before each draw_text calls that you may have and turn it on right after. If you try to do it the before the draw_surface, or after surface_set_target and turn it back on before surface_reset_target will cause everything to be invisble.

Make sure not to apply to to any sprite, ONLY to individual text events within surface_set_target and surface_reset_target

It will look a bit like this:

GML:
surface_set_target(surface);
draw_clear_alpha(c_black,0);
draw_sprite(sprite1,image_index,x,y);
gpu_set_colorwriteenable(true, true, true, false);
draw_text(x,y, "text1");
gpu_set_colorwriteenable(true, true, true, true);
draw_sprite(sprite2,image_index,x,y);
draw_sprite(sprite3,image_index,x,y);
gpu_set_colorwriteenable(true, true, true, false);
draw_text(x,y, "text2");
gpu_set_colorwriteenable(true, true, true, true);
draw_sprite(sprite4,image_index,x,y);
gpu_set_colorwriteenable(true, true, true, false);
draw_text(x,y, "text3");
gpu_set_colorwriteenable(true, true, true, true);
draw_sprite(sprite5,image_index,x,y);
draw_sprite(sprite6,image_index,x,y);
surface_reset_target();
draw_surface(surface,x,y);
 
Last edited:
Top