• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Dynamically create image from array

S

Spafford

Guest
Hi everyone,

I am trying to create an image from an array of data.

For example, I have an array of 1024*1024 floats and I want to generate an image that takes the greyscale value for each pixel from that position in the array. So effectively I am looking for a GMS2 version of the python pyplot imshow https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.imshow.html .

I would also like to do this dynamically, so that I can change the contrast if I were to zoom in on a smaller area of the image. This would be like setting the greyscale so the lightest and darkest areas of the image are white and black, regardless of their actual value.

Any help is appreciated!
 

davawen

Member
This method is certainly not the most efficient, but it's the simplest I could think off :
GML:
///Create event
_uContrast = shader_get_uniform(shd_correction, "constrast");
_uWhatever = shader_get_uniform(shd_correction, "whatever");

contrast = .5;
whatever = something I don't know it's your shader
GML:
///Draw event
shader_set(shd_correction);
shader_set_uniform_f(_uContrast, constrast);
shader_set_uniform_f(_uWhatever, whatever);

var _width = array_height(array);
for(i = 0; i < _width; i++)
{
    var _height = array_length_2d(array, i);
    for(j = 0; j < _height; j++)
    {
        var _v = array[i, j],
            _c = make_colour_rgb(_v, _v, _v);
          
        draw_point_color(i, j, _c);
    }
}
shader_reset();
I don't know how you would go about making a contrast shader, but doing some searching here is what I found in glsl (don't know if they work like you would expect tho) :

Edit : also, I forgot to add, you might want to use game maker beta 2.3, since it would allow you to store r,g and b values in your array, here are the new gml feature if you're interested : https://www.yoyogames.com/blog/549/gamemaker-studio-2-3-new-gml-features
 
Top