Can a grid fit a 1920x1080 surface?

  • Thread starter Deleted member 16767
  • Start date
D

Deleted member 16767

Guest
I'm trying to make a grid the size of the surface width and height. I am using it for lassoing pixel (2x2 in size) and filling it with color. But it doesn't fit the whole room/surface. When I try to make the ds_grid_create bigger or smaller than 128x128, it hangs up to the point I have to alt tab out and stop the project.
 

Tthecreator

Your Creator!
It doesn't seem like a good idea to use the grid at all. Why do you want to use the grid and draw individual pixels?
Remember, the surface itself is also a kind of data structure that can hold the data you need. Why not draw once to a surface and keep it at that?
If you try to do your grid thing, you are basically using cpu rendering which is likely going to be a little slow.
 
D

Deleted member 16767

Guest
Is there some other way to make a lasso then?
 

Tthecreator

Your Creator!
There are multiple options actually!
First, you could create a shader that given a target color makes a mask of all pixels conform to the target color. Then you'd have to find a way with shaders to figure out if blobs on your mask are connected to your point. (Which may not be easy)

So an easier way could be to transform the surface into a buffer using buffer_get_surface. Then you could read the data from your buffer. You'd still be looking at a cpu-driven software flooding algoritm, but I think this is the easiest to get the trick done. However, you still have to learn how to use buffers.
 

GMWolf

aka fel666
So an easier way could be to transform the surface into a buffer using buffer_get_surface. Then you could read the data from your buffer. You'd still be looking at a cpu-driven software flooding algoritm, but I think this is the easiest to get the trick done. However, you still have to learn how to use buffers.
For @mikix I'd recommend this approach over using a shader approach.

Doing a shader_get_buffer
I'm trying to make a grid the size of the surface width and height. I am using it for lassoing pixel (2x2 in size) and filling it with color. But it doesn't fit the whole room/surface. When I try to make the ds_grid_create bigger or smaller than 128x128, it hangs up to the point I have to alt tab out and stop the project.
That's very odd.
Can you show us some of the code used to create this grid?
Coulld you also use the debugger to find out exactly where it is that your program hangs? Is it when creating the grid? Or perhaps some algorithm you wrote doesn't like the grid?
 
D

Deleted member 16767

Guest
GML:
//Pixel mode
//Draw event

if keyboard_check_released(ord("F")) && keyboard_check_released(vk_control)
{
    ds_grid_clear(gridlasso,-1)
}


//Lasso
//Draw GUI event

if ds_exists(gridlasso,ds_type_grid) //&& !point_in_rectangle(mouse_x,mouse_y,lxx,lyy,lmmxx,lmmyy)
&& global.lasso = true
{

for (iff=0; iff<width; iff++)
{
    for (jff=0; jff<height; jff++)
    {
        x1ff=iff*sizelassox;
        y1ff=jff*sizelassoy;
        
        

        if gridlasso[# iff, jff]=1 && mouse_check_button(mb_right)
        {
        //draw_rectangle_color(x1ff,y1ff,x1ff+(sizelassox-1),y1ff+(sizelassoy-1),c_white,c_black,c_white,c_black,false);
            //draw_set_alpha(1)
        }
       else if gridlasso[# iff, jff]==2 && !point_in_rectangle(mouse_x,mouse_y,lxx,lyy,lmmxx,lmmyy)
        {

            
if surface_exists(global.final_surf)
{
            surface_set_target(global.final_surf)

            draw_rectangle_color(x1ff,y1ff,x1ff+(sizelassox-1),y1ff+(sizelassoy-1),color,color,color,color,false);
      
           //draw_sprite_ext(global.spr_index,0,x1ff+(sizex-1),y1ff+(sizey-1),global.scax,global.scay,rotatecam,color,0);
            surface_reset_target();
}       




            
        }
    }
}

}
//Create Event
globalvar width,height,size,colorfill,x1ff,y1ff;
width=128
height=128
gridlasso=ds_grid_create(width,height);
x1ff = 0
y1ff = 0
iff = 0
jff = 0
colorfill = 2
sizelassox = 2
sizelassoy = 2
sizelasso = sizelassox + sizelassoy

//Step event

if !point_in_rectangle(mouse_x,mouse_y,lxx,lyy,lmmxx,lmmyy) && global.lasso = true && keyboard_check_pressed(ord("F")) && keyboard_check(vk_control)

{


    fill(gridlasso,lxx,lyy,colorfill);

    
    
}
    




if ds_grid_get(gridlasso,sizelassox,sizelassoy)
{
    ds_grid_clear(gridlasso,-1)
    
}


if keyboard_check_pressed(ord("F")) && keyboard_check(vk_control)
{
    global.lasso = true
}

if mouse_check_button(mb_right) && global.lasso = true
{
global.shDrawFreely = 200
global.shMouse = 200
//colorfill = 2
//global.shDrawFreely = global.shDrawFreely

    gridlasso[# lxx, lyy]=1;

}

if keyboard_check_pressed(ord("Q")) && keyboard_check(vk_control)
{
    ds_grid_clear(gridlasso,-1)
    global.lasso = false
}


SCRIPT
GML:
function fill(argument0, argument1, argument2, argument3)
{
/// @function fill(grid, x, y, filler)
/// @description Flood fills a grid with the value specified in filler, starting on position (x,y). Returns the number of cells filled.
/// @param {ds_grid} grid
/// @param {int} x
/// @param {int} y
/// @param filler

//Parameter initialization---------------------------------------------------
var grid  =argument0;    //The grid to flood fill
var xx    =argument1; //Starting x position
var yy    =argument2;    //Starting y position
var filler=argument3; //Value to fill with

//Fifth parameter is automatically determined and should not be set by user
var target; //The value to replace with filler value
if argument_count=4
{
    //Determine the target value the first time ds_grid_floodfill is called
    target=grid[# xx, yy];   
}
else
{
    target=argument[4];   
}

//Flood fill-----------------------------------------------------------------
var count=0; //Used to count filled cells
if (xx>=0 and xx<ds_grid_width(grid)) and (yy>=0 and yy<ds_grid_height(grid))
{
    var value=grid[# xx, yy];
    if value==target and value!=filler
    {
        grid[# xx, yy]=filler;
        count=1;
    
        //Flood fill neighbouring cells
        count+=fill(grid,xx-1,yy,filler,target);
        count+=fill(grid,xx,yy-1,filler,target);
        count+=fill(grid,xx+1,yy,filler,target);
        count+=fill(grid,xx,yy+1,filler,target);
    }
}

return count
}
 
D

Deleted member 16767

Guest
The ds grid gets smaller with 2x2 draw_rectangle. And then it counts all the grids in the background, making a lockdown on the app. I use sprite_height x sprite_width with the fill tool for painting. No, it does not work if I have a sprite that's 2x2 either.

I'm curious to know if ds_grid uses the old array1d/2d?
 
Top