Help with "surface_get_pixel_ext"

S

sminc

Guest
Hey gang,

Longtime Game maker guy here, getting back into it and starting a serious project. I don't "fully" understand shaders and surfaces, and that's leading to a problem with "surface_get_pixel_ext".

Currently, I use this to (attempt) to find the alpha of the pixel at this point (where the player is):

Code:
if surface_exists(light)
{
surfpix = surface_getpixel_ext(light,464,200);
myvisibility = (surfpix >> 24) & 225;
};

However, it only jumps between 255 an 0 as the returned values-- nothing in between, even though I've drawn multiple gradients of circles on the surface. Below is what I typically use to draw said circles:

Code:
if surface_exists(light)
{
var lightsize = 128;
var lightcolor = c_dkgray;
gpu_set_blendmode(bm_subtract);
surface_set_target(light);
draw_ellipse_colour(x-lightsize/2,y-11-lightsize/2,x+lightsize/2,y-11+lightsize/2,lightcolor,c_black,false);
surface_reset_target();
gpu_set_blendmode(bm_normal);
};
Am I missing something? Does this have to do with the fact that I'm using subtraction as the blend mode and removing from the black surface? Something to do with negative numbers? I've been struggling with this for months.

Thanks in advance,
sminc
 
S

sminc

Guest
Tried that, not sure how that typo snuck in-- It's normally 255! Oops!

I may have stumbled upon something, however. Could it be I'm asking for alpha-- but the alpha remains the same even when subtracting a color from the surface? Because it fluctuates appropriately when i just look for surface_get_pixel(). I will most likely go with a color method instead of alpha-- save a little processing power as well.

sminc
 
I

icuurd12b42

Guest
if you are subtracting with the alpha channel set to 1 then the resulting alpha on the surface should be 0

draw_ellipse_colour is a shape/primitive drawing (using vertices to setup triangles or drawing lines) which requires you to call draw_set_alpha to change the alpha channel value the drawing will use.

try
...
draw_set_alpha(.5);
draw_ellipse_colour(x - lightsize / 2, y - 11 - lightsize / 2, x + lightsize / 2, y - 11+ lightsize / 2, lightcolor, c_black, false);
draw_set_alpha(1);
...
 
S

sminc

Guest
Please correct me if I'm wrong, but won't that just "layer" a transparent ellipse on top of what already is on the surface? Maybe I needed to give more details-- I'm using the surface as a fog of war, and subtracting where there is light. I did get a version working with the method I described above (using color, not alpha). I'm very interested in continuing this chat, I'd love to learn what I was doing wrong.

I'll give this a shot today. Thank you!

sminc
 
S

sminc

Guest
draw_set_alpha(.5);
draw_ellipse_colour(x - lightsize / 2, y - 11 - lightsize / 2, x + lightsize / 2, y - 11+ lightsize / 2, lightcolor, c_black, false);
draw_set_alpha(1);
No cigar, icuurd. Thanks though. Again, still curious as to way-- but for anyone else (am my own sake!) the problem has been addressed using another method of grabbing less accurate but useful information: color.

sminc
 
Top