GMS 2 SOLVED: draw text shadow z-fighting in 3D

Discussion in 'Programming' started by foreverisbetter, Jul 14, 2019 at 11:52 AM.

  1. foreverisbetter

    foreverisbetter Member

    Joined:
    Aug 17, 2017
    Posts:
    36
    Hello,

    I'm working on a 2D platformer but I decided for parts of the menu to be 3D. It used to be everything 2D but now I want to show a simple 3D Model in the background and also use the perspective view to get a nice parallax effect.
    The Problem is: up until now, I used the following script to draw text shadow
    Code:
    //draw text shadow
    draw_set_color(argument10);
    draw_set_alpha(argument11);
    draw_text_ext_transformed(xx+lengthdir_x(sh_len, sh_dir),
                        yy+lengthdir_y(sh_len, sh_dir), string_hash_to_newline(str),
                        sep, w, xscale, yscale, angle
                        );
    
    //draw text
    draw_set_color(prev_col);
    draw_set_alpha(prev_alpha);
    draw_text_ext_transformed(xx, yy, string_hash_to_newline(str), sep, w,
                        xscale, yscale, angle
                        );
    Now this code introduces z-fighting. And I can't wrap my head around how to draw text from the same object to another depth/layer in the new layer system.
    Do I have to draw the text to a surface then change it to a texture and then draw the texture to a primitive and then draw the primitive at the right z location?
    What would be the best approach? How does one tackle this problem?

    Thanks in advance for your advice!
     
  2. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,088
    Turn off z_testing for this section of code and re enable it again afterwards. :)
     
    foreverisbetter likes this.
  3. foreverisbetter

    foreverisbetter Member

    Joined:
    Aug 17, 2017
    Posts:
    36
    oh. my. god. I totally forgot that there is something like turning off z_testing! XD
     
    Lonewolff likes this.
  4. foreverisbetter

    foreverisbetter Member

    Joined:
    Aug 17, 2017
    Posts:
    36
    Thanks so much for your answer! Do you know if there is any difference between gpu_set_zwriteenable and gpu_set_ztestenable? Does one break the vertex batch and the other doesn't or something?
     
    Lonewolff likes this.
  5. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,088
    Good question. I am pretty sure gpu_zwriteenable turns on the z buffer and gpu_set_ztestenable performs the actual z testing.

    And yes, I am confident that it will break the batch as it is a state change on the GPU. The overhead would be minimal though.
     
    foreverisbetter likes this.

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