Fast filled polygons 
Author Message
 Fast filled polygons

Hi all,

I've worked on a fast filled polygon -draw routine, but it's still very
slow. I'm soon getting VERY depressed...
I use direct to video memory -writing (1 pixel at a time) with Borland
Asm4.0.

A while ago I read that Skywalker (Luke?:) said one can't do anything
serious with putpixel. So now I'm asking help. What's a fast method to
write polygons & how can I do it?

Thanks in advance!

Pekka




Wed, 04 Feb 1998 03:00:00 GMT  
 Fast filled polygons

Quote:
> Hi all,

> I've worked on a fast filled polygon -draw routine, but it's still very
> slow. I'm soon getting VERY depressed...
> I use direct to video memory -writing (1 pixel at a time) with Borland
> Asm4.0.

> A while ago I read that Skywalker (Luke?:) said one can't do anything
> serious with putpixel. So now I'm asking help. What's a fast method to
> write polygons & how can I do it?

Seperate it into two steps: drawing the outline (drawing lines)
and drawing the fill.  As I mentioned the other day drawing lines
can be optimized in a variety of ways... since you have your own draw
routines ( I hope you have a good line-drawing algorithm!) probably
the major way to optimize your putpixel is to calculate addresses
incrementally.  Get away from muls if you're using them in any case...
you can see significant improvement with the numbers the video forces
you to use by doing a multiply-by-shifting.  But the best speed will
be got by calculating addresses incrementally.  Assuming you've
picked a good line-drawing algorithm... which by the way when you use
bresenham a lot of people like to use seperate code depending on the
angle of the line, that's an improvement over the generalized case.

If you're drawing a lot of horizontal or vertical lines, especially in
mode 12h... you can get a lot of speed increase by writing multiple
pixels at once (horizontal lines) and using incremental addresses
(horizontal and vertical lines.

I'm no graphics guru so I can't tell you about fills in general... but
the big key to speed is draw them horizontally.  Then you can use incremental
addressing and maybe writing multiple pixels at once (depending on your
graphics mode)  and that will save you lots of time right there.

I recommend Richard Wilton's "Programmer's guid to PC & PS/2
Video Systems"- it is a very good introductory book both to the
various video hardware systems and general graphics programming
methodologies.

David

Quote:

> Thanks in advance!

> Pekka





Thu, 05 Feb 1998 03:00:00 GMT  
 Fast filled polygons

 > I've worked on a fast filled polygon -draw routine, but it's still
 > very  slow. I'm soon getting VERY depressed...
 > I use direct to video memory -writing (1 pixel at a time) with Borland
 > Asm4.0.
 >
 > A while ago I read that Skywalker (Luke?:) said one can't do anything
 > serious with putpixel. So now I'm asking help. What's a fast method to
 > write polygons & how can I do it?

 It sounds like you're trying to do flat-shaded polys?  (as in the whole poly
 is only one color)  If so, the general method is this:

 Keep two arrays, each with as many elements as you have scan lines in your
 display.  Call one right_most and one left_most, or something like that.
 Initialize all the elements of right_most to be the far left side of the
 screen (0) and left_most to be the right side (319 for mode 13h).

 Now, for each side of the polygon:
   "Draw" the line, but instead of displaying it, "plot" a point by doing the
   following:
     to "plot" (x,y) : If x > right_most[y] then right_most[y] = x
                       if x < left_most[y] then left_most[y] = x

 Now that all our edges have been converted to left/right extremes, our task
 is simple:

 For each scan line y, if right_most[y] > left_most[y] then fill every pixel
 (left_most[y], y) through (right_most[y], y) with the color of the polygon.
 This can be done by loading es:di with a pointer to (left_most[y], y), cx
 with right_most[y]-left_most[y]+1, and doing a rep stosb.

 Now, there are several optimizations I didn't go over, but once you have the
 basic idea, the optimizations pretty much write themselves.

 If I need to clear anything up, let me know.  I'm a morning person and I get
 groggy around 10pm.  :-)

... Fun, fun, fun, 'til her daddy takes her Blue Wave away!
___ Blue Wave/QWK v2.12



Sat, 07 Feb 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. filled polygons

2. Polygon fill routine for Top Speed M2.

3. MIT-Scheme Win32 'fill-polygon

4. Polygon fill problem (1/2)

5. Am I filling the polygon the wrong way?

6. Problem with bitmaps as polygon fill

7. convoluted polygons are filled incorrectly

8. Bug: Tcl/Tk 8.0p1 polygon -fill option

9. Canvas polygons are always filled?

10. Fast Polygon Routines needed.

11. Fast filled rectangles in mode 12h...

12. Fastest way to fill data...

 

 
Powered by phpBB® Forum Software