import gui
import ft8xx as ft

fill = True
outline_colour = gui.RGB(255,255,255) # white
fill_colour = gui.RGB(255,0,255) # purple

line_vertex_list = []
line_vertex_list.extend([
    [gui.DL_VERTEX2F(100, 100)],
    [gui.DL_VERTEX2F(300, 100)],
    [gui.DL_VERTEX2F(200, 200)],
    [gui.DL_VERTEX2F(100, 200)],
    [gui.DL_VERTEX2F(100, 100)],
])

gui_l = [
    [gui.DL_SAVE_CONTEXT()],
    [gui.DL_LINE_WIDTH(2)],
    [gui.DL_COLOR(outline_colour)],
    [gui.DL_BEGIN(gui.PRIM_LINE_STRIP)]] + line_vertex_list + [[gui.DL_END()],
    [gui.DL_STENCIL_OP(ft.STENCILOP_INCR, ft.STENCILOP_INCR)],
    [gui.DL_COLOR_MASK(0, 0, 0, 0)],
    [gui.DL_BEGIN(gui.PRIM_EDGE_STRIP_L)]] + line_vertex_list + [[gui.DL_END()],
    [gui.DL_COLOR_MASK(1, 1, 1, 1)],]
    
if fill:
    gui_l.extend([
        gui.DL_COLOR(fill_colour),
        gui.DL_STENCIL_FUNC(ft.ALPHAFUNC_EQUAL, 1, 255),
        gui.DL_BEGIN(gui.PRIM_EDGE_STRIP_L),
        gui.DL_VERTEX2F(800, 0),       #0
        gui.DL_VERTEX2F(800, 480),
        gui.DL_END(),
        ])

gui_l.extend([
        gui.DL_STENCIL_FUNC(ft.ALPHAFUNC_ALWAYS, 0, 255),
        gui.DL_CLEAR(0, 1, 0),
        gui.DL_RESTORE_CONTEXT(),
])

gui.show([gui_l])