delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/25/16:18:58

Message-ID: <007901bd881a$110af560$694d08c3@arthur>
From: "Arthur" <arfa AT clara DOT net>
To: "DJGPP Mailing List" <djgpp AT delorie DOT com>
Subject: Re: polygon
Date: Mon, 25 May 1998 21:15:20 +0100
MIME-Version: 1.0

>can anybody recommend a piece of code
>that draws a simple polygon (and possibly some clipping).

How simple? How many sides? Filled or unfilled? What screen mode? What
language (C, C++, ASM)?

I assume you are not using Allegro or any other graphics library, which is
the easiest (though least efficient) way.

Clipping is simple: if the pixel you are plotting is off-screen, just don't
plot it :^)

It's easy to draw a point, easy to draw circles and lines, easy to draw
filled boxes, but as soon as you get onto filled irregular polygons, it gets
harder.

And it is harder when not using mode 13h or modex.

Got a routine for C somewhere which does it, but is not very efficient. It
uses a modification on the Bresenham line routine. The line routine loads
the co-ordinates of each point on the perimeter of the polygon into an
array. It then draws horizontal lines between the point on the left-hand
side, and on the right-hand side of the polygon on each scanline. You need
to have a good working knowledge of what the Bresenham routine does, first.

If you are interested, I'll send you the source to my *basic* gfx routines.

Or as I said, you could use Allegro - but it's always more fun if you do it
yourself, isn't it?


James Arthur
jaa AT arfa DOT clara DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019