GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2009-10-04 02:59:22

~Dannyboy~
~hoqhuue(|~
From: Melbourne, Australia
Registered: 2009-10-02
Posts: 21
Website

draw_polygon_inverted

Based on my recent topic at the GMC, I put together this script. As it is based on both "draw_rectangle_inverted" and "polygon_area" I borrowed the comments from them, I hope that's OK.

/*
**  Usage:
**      draw_polygon_inverted(polygon)
**
**  Arguments:
**      polygon    ds_list containing XY coordinate pairs defining
**                 the shape of a polygon {x0,y0,x1,y1,...,xn,yn}
**
**  Returns:
**      nothing, inverts the given polygonal area of the screen
**
**  Notes:
**      Polygons are closed figures, the first point in the polygon
**      will also be considered the last point in the polygon.
**      Polygons must be simple, which means they can not have
**      edges that cross each other.
**
**      Resets blending mode to normal.
**
**  GMLscripts.com
*/
{
    var polygon, i, j, x1, y1;
    polygon = argument0;
    j = ds_list_size(polygon);
    draw_set_blend_mode_ext(bm_inv_dest_color, bm_inv_src_color);
    draw_primitive_begin(pr_trianglefan);
    for (i = 0; i < j; i += 2)
    {
        x1 = ds_list_find_value(polygon, i);
        y1 = ds_list_find_value(polygon, i + 1)
        draw_vertex_color(x1, y1, c_white, 1);
    }
    draw_primitive_end();
    draw_set_blend_mode(bm_normal);
}

Offline

#2 2009-10-04 17:16:06

RaiSoleil
Member
Registered: 2009-08-02
Posts: 16

Re: draw_polygon_inverted

Careful of the alpha there. When drawing to a surface, inverting with an alpha of 1 will flip the alpha channel too, which might not be what you want.

Also, pr_trianglefan only?

Offline

#3 2009-10-04 18:52:27

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: draw_polygon_inverted

Also, pr_trianglefan only?

Amazingly, that's all you need for this. See the linked topic above or click here.


Abusing forum power since 1986.

Offline

#4 2009-10-05 11:04:35

RaiSoleil
Member
Registered: 2009-08-02
Posts: 16

Re: draw_polygon_inverted

Ah, intriguing idea. I'll need to fiddle with this some more . . . seems like it should mesh with my AA engine pretty well.

Offline

Board footer

Powered by FluxBB