Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!ames!sgi!garyt@westcoast.esd.sgi.com From: garyt@westcoast.esd.sgi.com (Gary Tarolli) Newsgroups: comp.sys.sgi Subject: Re: Trouble drawing point-sampled polygons Summary: exact point sampled polygons Message-ID: <84845@sgi.sgi.com> Date: 11 Feb 91 16:42:31 GMT References: <1991Feb8.200816.20381@Neon.Stanford.EDU> Sender: guest@sgi.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 39 In article <1991Feb8.200816.20381@Neon.Stanford.EDU>, loan@Neon.Stanford.EDU (James P. Loan) writes: > > I'm trying to draw several copies of the same polygon and I'm having > a hard time getting them to look EXACTLY alike. I realize that there > is round-off error when translating within a window, but the manual > presents a way to fix that. I thought the purpose of the +/-0.5 > adjustment in an ortho2() call was to "move" the coordinate system > so that integer vertices would fall exactly in the center of pixels. > Well, I wrote a test program which seems to prove exactly the opposite. > When I add in the +/-0.5 adjustment, there is [round-off] error which > makes one copy of a trapezoid smaller than the other (sometimes). When > I take out the adjustment, there is no difference between the polygons. > Since the error involves the top (flat) edge of the trapezoid, it must > mean that the top two vertices are falling on pixel edges. By the way, > the same problem arises if I draw screen-aligned rectangles instead > of trapezoids, so the problem is with VERTICES falling on pixel edges, > not points on the lines connecting the vertices. > > Can anyone explain to me what is going on? > When you are drawing old style polygons, you want your polygon vertices to land exactly on pixel centers. But when you are drawing point-sampled polygons you want the opposite - you should place your vertices exactly on the pixel borders. This is because the decision to fill a pixel or not is based on whether the pixel center is in/outside of the polygon. If the polygon edge goes right thru the center of a pixel, then you are susceptable to round off error. If you move your vertices to pixel borders (1.5, 2.5, etc) then it takes a big roundoff error to make things fail ( magnitude of .5). Warning - if you attempt to do this by introducing a translate matrix, beware if you are ddrawing lines - it may have an undesired effect on lines. Andrew Meyers once went thru all this and came up with a scheme for drawing exact polygons on all our machines for doing 2-D User Interface code. Any comments Andrew? -------------------- Gary Tarolli