XFillPolygon() replacement?

Has anyone got a good SDL-based replacement for the X11 "XFillPolygon()"
function?

Thanks!

-bill!

Has anyone got a good SDL-based replacement for the X11 "XFillPolygon()"
function?

Getting the exact semantics of XFillPolygon is tedious, if not tricky
(concave and self-intersecting polygons, overlapping rules etc).
I would just write a filled triangle primitive and work from that.
If you want to do it right you may want sub-pixel positioning, anti-
aliased edges (perhaps using the alpha channel) etc.

Speaking of which, since filled polygons are frequently accelerated,
I was considering adding it to the SDL API for post-1.2, along with
drawing line segments. Nothing decided yet though

Getting the exact semantics of XFillPolygon is tedious, if not tricky
(concave and self-intersecting polygons, overlapping rules etc).
I would just write a filled triangle primitive and work from that.
If you want to do it right you may want sub-pixel positioning, anti-
aliased edges (perhaps using the alpha channel) etc.

Hehe… Hrm. Well, all I “need” it for is when/if I decide to convert
my game BoboBot from Xlib to SDL. On the title screen, I use XFillPolygon
to 3D-ify some of the sprites from the game and throw them around in an
entertaining fashion. :slight_smile:

So, I guess in that case, a function that used two filled triangles to
create a filled 4-sided polygon would work.

-bill!

Mon, 04 Dec 2000 William Kendrick wrote:

Getting the exact semantics of XFillPolygon is tedious, if not tricky
(concave and self-intersecting polygons, overlapping rules etc).
I would just write a filled triangle primitive and work from that.
If you want to do it right you may want sub-pixel positioning, anti-
aliased edges (perhaps using the alpha channel) etc.

Hehe… Hrm. Well, all I “need” it for is when/if I decide to convert
my game BoboBot from Xlib to SDL. On the title screen, I use XFillPolygon
to 3D-ify some of the sprites from the game and throw them around in an
entertaining fashion. :slight_smile:

So, I guess in that case, a function that used two filled triangles to
create a filled 4-sided polygon would work.

I guess you can find code for that kind of stuff in many places…

If you feel like hacking it yourself (and do all kinds of polygons), the
easiest way that delivers aceptable performance is probably a two-step
approach, where you first scan through the polygon from top to bottom,
splitting it at the Y coord of every point, until you have a list of "bands"
with an even number of lines in each, all of the same projected height.

Note: For polygons with crossing lines, you also need to consider every
intersection as a point in the first step.

The second step would be to deal with these lines, by pairing them into “quads"
with horizontal top and bottom edges. The simplest way to do that would
probably be to emulate the approach that the Amiga blitter used; mark edes with
a single XOR pixel per row, then scanning the entire area, either setting or
zeroing bits, toggling every time you hit one of those pixels. A faster way
with software is to sort the lines by X coord, and then fill horizontal rows of
pixels between the left and right edge, for each row. (That is, run two
"one-X-per-Y” line drawing algorithms at once, drawing horizontal rows between
the points.)

Oh well, have fun! :slight_smile:

//David

…- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' ..- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -’

Has anyone got a good SDL-based replacement for the X11 "XFillPolygon()"
function?

I do. I implemented a polygon fill program as part of a non-OpenGL 3-D
renderer. If you want the code, send me private email.On Sun, 3 Dec 2000, William Kendrick wrote:


Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
ICSM-F Development Team, UP Diliman +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481