-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|706|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Graphical Effects


 
Andy_A
Created : 17 March 2011
Edited : 17 March 2011
System : Windows
Language : Blitz

FAST! - Scan line filled polygons

Fill ANY polygon quickly

This function fills just about any polygon very quickly from 0ms for a small triangle to 15ms for 60 sided complex polygon (self-intersecting)

Below is a simple demo but, I may have more to show later.


 

Comments


Thursday, 17 March 2011, 16:45
Cower
15ms for a 60-sided polygon is not very fast. You should rewrite it in C and import it into whichever language this is instead.
Thursday, 17 March 2011, 17:33
Jayenkai
It's BlitzPlus, says on the 5th line.

Given Blitz's unnaturally slow 2D primitive speeds, I'd say 15ms's is probably quite good.
If you grab them as sprites, rather than constantly redrawing them, you'll be coming out with some nice effects.
Thursday, 17 March 2011, 19:21
Andy_A
@Cower - The original code was C (see link on third line), I just ported BlitzPlus.

I re-ran the code to look at 60 vertices of a complex (self-intersecting) polygon - it took 9ms. It takes a complex polygon of 100 vertices to take 15ms. Not blazing by C standards but fast by Blitz standards.

The major slowdown is when a complex polygon has a large number of vertices. A simple convex polygon of 100 vertices only takes 4ms.

Maybe a better way to share with the community is to write your own version of this routine in whatever language you like.

@Jay - that's exactly the type of routine I had in mind. This routine is ideal for generating small-medium sprites in code rather that storing them as images on disk. I'll see if I can come up with some suitable example.
Thursday, 17 March 2011, 21:11
Cower
If the original is C, why not build a DLL and use it through that? Then you'll actually get the speed boost provided by a language that isn't horrifically slow.
Thursday, 17 March 2011, 21:14
Andy_A
It's fast enough for what I'm doing but, your welcome to make the DLL and take the credit.
Friday, 18 March 2011, 22:50
Andy_A
Here's a small demo to lend some ideas on how one might use the polyFill() function.

[Edit] I just found out that this listing doesn't work straight away in B3D.

To make it work in B3D make the following changes:

1) Change the line: scrn = CreateImage( scrn, sw, sh) to -> scrn CreateImage( scrn, 800, 600). It's located just above the DIM statement near the top of the listing.

2) Cut that line you just changed and paste directly into the 'intro()' function. Right after the local declarations should do nicely.

3) (optional) change the 'Flip' statements to the two line version 'VWait : Flip False'

I could only test the first two screens because I used the B3D demo version (B3D v1.83) which only allows 16K of code. So for testing I had to delete all references to the last two demo screens.

If anybody gets this to work in B3D, please post the working code.

TIA
[end Edit]