BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: Drawing filled polygon  (Read 1155 times)

MPW691

  • Newbie
  • *
  • Posts: 8
    • View Profile
Drawing filled polygon
« on: July 20, 2020, 09:32:26 AM »

Hi all,

I need to draw the following shape but I'm not sure how is best to do it with the minimal number of instructions (as I need a few of them and don't want to fill my display list).


I can draw the outline very easy with
Code: [Select]
BEGIN(LINE_STRIP)
VERTEX2II(150, 200, 0, 0)
VERTEX2II(200, 200, 0, 0)
VERTEX2II(225, 225, 0, 0)
VERTEX2II(225, 275, 0, 0)
//etc...

However I also need to fill it in. I tried doing:
Code: [Select]
STENCIL_OP(INCR, INCR)
COLOR_MASK(0, 0, 0, 0)
BEGIN(EDGE_STRIP_B)
//draw lines
END()
STENCIL_FUNC(EQUAL, 1, 255)
BEGIN(EDGE_STRIP_B)
//draw lines again
END()

But this only fills in part of the polygon, and leaves parts of it unfilled. Do I need to split this shape up into 3 mini shapes (which seems like a lot of extra unnecessary instructions added to the display list) or can I use a different method, maybe the scissor?

If possible I wan't to avoid loading in bitmaps because they never work quite how I want them too, I'd have to load in separate ones for filled and unfilled, and I don't have a lot of space to store them. Would prefer a display list option, which I'm sure must be possible.

I have tried a lot of different things so if anyone want's to take on this challenge and finds any code they could share that could create this shape then it would be hugely appreciated!

_ Image doesn't seem to want to display so I have attached it to this post) _
Logged

BRT Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 390
    • View Profile
Re: Drawing filled polygon
« Reply #1 on: July 20, 2020, 04:01:28 PM »

Hi,

Welcome to the forum,

This code works to produce your shape using a similar technique to what you were already using but with a left hand edge strip.

Maybe some other users can improve on it too

Best Regards, BRT Community

Code: [Select]
CLEAR(1, 1, 1)); // clear screen

COLOR_RGB(255, 100, 0)
STENCIL_OP(INCR,INCR)
COLOR_MASK(0,0,0,0)
BEGIN(EDGE_STRIP_L)
VERTEX2II(30,100,0,0)
VERTEX2II(100,100,0,0)
VERTEX2II(150,150,0,0)
VERTEX2II(150,250,0,0)
VERTEX2II(100,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(80,250,0,0)
VERTEX2II(80,150,0,0)
VERTEX2II(30,100,0,0)
END()

COLOR_MASK(1,1,1,1) )
STENCIL_FUNC(EQUAL, 1, 255)
BEGIN(EDGE_STRIP_L)
VERTEX2II(300,0,0,0)
VERTEX2II(300,300,0,0)
END()

STENCIL_FUNC(ALWAYS,0,255)
LINE_WIDTH(32)
COLOR_RGB(255, 255, 255)
BEGIN(LINE_STRIP)
VERTEX2II(30,100,0,0)
VERTEX2II(100,100,0,0)
VERTEX2II(150,150,0,0)
VERTEX2II(150,250,0,0)
VERTEX2II(100,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(80,250,0,0)
VERTEX2II(80,150,0,0)
VERTEX2II(30,100,0,0)
END()
DISPLAY()
Logged

MPW691

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Drawing filled polygon
« Reply #2 on: July 20, 2020, 05:30:19 PM »


This code works to produce your shape using a similar technique to what you were already using but with a left hand edge strip.

Code: [Select]
CLEAR(1, 1, 1)); // clear screen

COLOR_RGB(255, 100, 0)
STENCIL_OP(INCR,INCR)
COLOR_MASK(0,0,0,0)
BEGIN(EDGE_STRIP_L)
VERTEX2II(30,100,0,0)
VERTEX2II(100,100,0,0)
VERTEX2II(150,150,0,0)
VERTEX2II(150,250,0,0)
VERTEX2II(100,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(80,250,0,0)
VERTEX2II(80,150,0,0)
VERTEX2II(30,100,0,0)
END()

COLOR_MASK(1,1,1,1) )
STENCIL_FUNC(EQUAL, 1, 255)
BEGIN(EDGE_STRIP_L)
VERTEX2II(300,0,0,0)
VERTEX2II(300,300,0,0)
END()

STENCIL_FUNC(ALWAYS,0,255)
LINE_WIDTH(32)
COLOR_RGB(255, 255, 255)
BEGIN(LINE_STRIP)
VERTEX2II(30,100,0,0)
VERTEX2II(100,100,0,0)
VERTEX2II(150,150,0,0)
VERTEX2II(150,250,0,0)
VERTEX2II(100,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(80,250,0,0)
VERTEX2II(80,150,0,0)
VERTEX2II(30,100,0,0)
END()
DISPLAY()

This works perfectly, thank you BRT Community! And thank you for accepting me into the community, hopefully once I've got to grips with it a bit more I can help others out, as this has helped me out a lot!

As a further question, how much effort would it be to fill that polygon with a gradient rather than just a solid colour? Is it even possible, perhaps using the SCISSOR_XY?

Thanks again!
Logged

BRT Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 390
    • View Profile
Re: Drawing filled polygon
« Reply #3 on: July 21, 2020, 04:08:29 PM »

Hi,

We're glad it helped,

Here is a way to add the gradient. You can draw the gradient based on the stencil:

Code: [Select]
CLEAR(1, 1, 1)); // clear screen

STENCIL_OP(INCR, INCR)
COLOR_MASK(0,0,0,0)
BEGIN(EDGE_STRIP_L)
VERTEX2II(30,100,0,0)
VERTEX2II(100,100,0,0)
VERTEX2II(150,150,0,0)
VERTEX2II(150,250,0,0)
VERTEX2II(100,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(80,250,0,0)
VERTEX2II(80,150,0,0)
VERTEX2II(30,100,0,0)
END()

STENCIL_OP(KEEP, KEEP)
COLOR_MASK(1,1,1,1) )
STENCIL_FUNC(EQUAL, 1, 255)
CMD_GRADIENT(73, 69, 0x0000FF, 80, 334, 0xFF0000)

STENCIL_FUNC(ALWAYS,0,255)
LINE_WIDTH(32)
COLOR_RGB(255, 255, 255)
BEGIN(LINE_STRIP)
VERTEX2II(30,100,0,0)
VERTEX2II(100,100,0,0)
VERTEX2II(150,150,0,0)
VERTEX2II(150,250,0,0)
VERTEX2II(100,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(30,300,0,0)
VERTEX2II(80,250,0,0)
VERTEX2II(80,150,0,0)
VERTEX2II(30,100,0,0)
END()
DISPLAY()

Best Regards, BRT Community
Logged

MPW691

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Drawing filled polygon
« Reply #4 on: July 22, 2020, 02:16:19 PM »

Again, this worked perfectly, thank you!
Logged