1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

gradient color background GMS:2

Discussion in 'Programming' started by Mr Trick, Feb 2, 2019.

  1. Mr Trick

    Mr Trick Member

    Joined:
    Aug 24, 2018
    Posts:
    13
  2. The Sorcerer

    The Sorcerer Member

    Joined:
    Jan 3, 2019
    Posts:
    147
    Easy way, Photoshop
    Harder way, Shaders
     
  3. The Reverend

    The Reverend Member

    Joined:
    Sep 8, 2016
    Posts:
    504
    a simple but not perfect way:

    create a tiny 2x1 pixel sprite.
    for the left pixel choose the left gradient colour
    for the right pixel choose the right gradient colour
    then draw the sprite stretched with the linear texture interpoilation on:
    Code:
    gpu_set_tex_filter(true); // only if it isn't on anyways
    draw_sprite_stretched(spr_2x1px_gradient, 0, left_x, top_y, ww, hh);
    gpu_set_tex_filter(false); // only if it usually isn't on anyways
    
    You can create wider sprites and add more colours to get a nicer gradient of course. But the colours will always only interpolate linearly for each colour channel. Nothing more fancy than that.

    Edit: if you just need two colours, you could draw a coloured rectangle instead (draw_rectangle_color). not sure wich would be faster.
     
    Last edited: Feb 3, 2019
  4. The Sorcerer

    The Sorcerer Member

    Joined:
    Jan 3, 2019
    Posts:
    147
    Another way is to create a simple quad using vertex buffers. Make the colour of the left most vertices your start colour and the right most vertices as the end colour. Then draw it to the screen. All of the in between colours will be auto calculated internally.
     
  5. Mr Trick

    Mr Trick Member

    Joined:
    Aug 24, 2018
    Posts:
    13
    thank u so much :)
     
  6. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    364
    Why could you not use draw_rectangle_colour() ?
     
  7. Mr Trick

    Mr Trick Member

    Joined:
    Aug 24, 2018
    Posts:
    13
    Because of performance...
    I mean it's draw on a big screen and it's not making performance issue for me?
     
  8. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    364
    I don't think a singular draw_rectangle_colour call is going to impact performance.
     
  9. Mr Trick

    Mr Trick Member

    Joined:
    Aug 24, 2018
    Posts:
    13
    Well.. It's great thank u sooo much bro ❤️❤️❤️
     
  10. The Reverend

    The Reverend Member

    Joined:
    Sep 8, 2016
    Posts:
    504
    You can (mentioned that as well in my post). If you just want a linear gradient with two colours. If you want more colours or add gradient stops the sprite is the way to go.
     

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