1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML Getting the % of the drawn area of a surface

Discussion in 'Programming' started by Dawn, Feb 13, 2020 at 1:26 PM.

  1. Dawn

    Dawn Member

    Joined:
    Sep 5, 2016
    Posts:
    59
    Let's say

    1) There's an empty (or white) area/surface.

    2) Clicking on any point inside it will draw a circle (or any shape) of a certain size on it.

    3) The screen shows (filled area/whole area)

    So it's like a paint brush and the system need to get the % of the painted area. Through what method can I achieve this?
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,095
    You know the positions and other measurements, so you can calculate the size of the drawn area, and from there the percentage it takes of the entire area. A rectangle draw to (10, 10, 20 ,20) is 10x10 or 100 pixels, so on a 100x100 draw area that would be 100 / 10000 = 0.01 or 1%.
     
  3. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    1,104
    Copy the surface to a buffer and iterate through it, counting the number of times a byte in a group of 4 (to account for RGBA/BGRA/whatever) is not zero (or whatever kind of threshold you intend to apply to a give pixel). No idea how inefficient it would be to run continuously (assuming you want to update the % every step, etc.) Percentage calculation should be trivial if you make that work.

    Another option could be to use a shader to count for you (https://stackoverflow.com/questions/29352965/shader-for-counting-number-of-pixels, for inspiration).
     

Share This Page