GMS 2 draw_getpixel_ext

Discussion in 'Programming' started by Daniel Mallett, Dec 12, 2018.

  1. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    150
    So I like the look of this draw_getpixel_ext. The problem is I don't want to know the colour of the pixel underneath the transparent pixel.

    The best way to explain this. If I have an object which has and image attached to an object that covers the whole screen. That object is 100% transparent. So all you can see is the colour of the background below.

    I do not wish to get the black value. I want only the object colour (transparent).

    This is the part I am confused about. There are two functions draw_getpixel and draw_getpixel_ext. What is the point in the ext function. You can't ever get an alpha integer from this function because it will always report the value below.

    However I believe this is still possible because in the manual it says. "results will depend on the event in which the function is called, and also on the target surface being used."

    This is not helpful. It does not expand on this very vague information.

    Please would someone explain in greater detail how this function works.
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,164
    The manual says it gives you the alpha. You just have to extract it from the bitmask.
    "abgr" to "a" should be simple enough.
    var abgr = draw_getpixel_ext(x, y);
    var a = col >> 24;

    For the targeting of the desired pixel, it will take it from the application surface if no other surface is set.
    Example:
    you have 2 images (image A and image B).
    You draw image A with a draw_whatever() function and it is now on the application surface.
    Now you draw image B directly on top of A.
    Now you call draw_getpixel and it will get the pixel of image B so to say.

    If you draw_getpixel before drawing B you'll presumably get the pixel of image A.
     
  3. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    150
    This is how I thought it should work but it doesn't seem to. I have a black background lets say. I have a transparent object that takes the whole screen. But all you can see is black due to the transparency.

    What you are saying under this scenario is that I can take a pixel from anywhere and get a transparent value. But I don't. I only get the colour that is under that. It could be another colour image even. It will return that value.

    It's seems that the ext and non ext version do exactly the same thing.

    The chances are I have cocked up but that seems to be the results I am getting currently.
     
  4. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,164
    Expected behaviour.
    You draw a black background on the application surface, draw getpixel would return black.
    Then you draw a transparent sprite on it, you see that the application surface is still black.
    So does draw getpixel, that's just how color merging works.

    You would have to explain what exactly you're trying to do, because right now, you may as well not call draw getpixel at all and assume that it's transparent.

    That said, there is not transparency to be had on the application surface. You would have to make your own surface.
     
  5. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    150
    So I would have to create my own surface_create. That's fine.

    What I have is object drawn with draw function taken from a list. I have categories of stuff. Like bushes for example. Most of them are small. But one of them is larger so all the bounding boxes for that category would be as big as the biggest bush.

    The biggest one is the size of the bounding box for all of those categories. I am making a level editor if that clears things up.

    The only other way is to just list all the values in a table. I can get around this in a number of ways. I am trying to find the path of least fudge.

    Problem is if you have different size images within a single sprite you have to bound the images in a transparent box so they don't get stretched. Otherwise instead of doing a sprite_get_width() I would do sprite_get_index_width(sprite, index). (Which as you know you can't do.)
     
  6. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,164
    Hmm, peculiar situation.

    I think I have a solution though.
    There is this function called sprite_get_uvs().
    https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_get_uvs.html

    With this you could evaluate just how big a sprite with different index is on the texture page, because on there, each sub image gets trimmed of it's 0 alpha zones.

    uv [6] and [7] sounds like what you want.
    The manual says, it's a percentage. I believe to get the width of the sprite you can multiply it by the texture width.

    To get the texture width, you'd math this
    Code:
    tex_width = 1 / texture_get_texel_width();
    
    To get the texture, this
    Code:
    texture = sprite_get_texture(sprite_index);
    
    To get the uvs of the sprite
    Code:
    uvs = sprite_get_uvs(sprite_index, image_index);
    
     
  7. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    150
    That sounds like exactly the sort of thing I need. Thank you for researching that. I will have to digest and test that information in more detail, but I think you have me on the right track. I will keep you posted how it goes.

    Thank you.
     

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