Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!sgi!shinobu!odin!bennett From: bennett@sgi.com (Jim Bennett) Newsgroups: comp.sys.sgi Subject: Re: Trouble drawing point-sampled polygons Message-ID: <1991Feb9.002155.3909@odin.corp.sgi.com> Date: 9 Feb 91 00:21:55 GMT References: <1991Feb8.200816.20381@Neon.Stanford.EDU> Sender: news@odin.corp.sgi.com (Net News) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 48 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? This discussion only applies to applications who want to use pixel coordinates. The .5 offsets do put integer coordinates at pixel centers. So when you draw a line with integer vertices, it interpolates between the pixel centers, just the way you expect. If you draw a polygon with integer vertices, the polygon you get is the interior of the region formed by connecting the pixel centers. For any pixel, if its center is inside this region, then the pixel belongs to the polygon, otherwise it doesn't. When the edge of a polygon passes exactly through a pixel center, then the pixel is included in the polygon if it is on a left or lower edge, and excluded if it is on a right or upper edge. On a VGX or a GT, the computations are done correctly, and you should get the same polygon regardless of where it is drawn within the window or on the screen. On a PI, the round off error causes different effects in different quadrants of the viewport. To fix this problem, you can use an offset of 0.49 instead of 0.5, and then the PI will behave more nicely. However, there will still be (rare) cases where a polygon will light up different pixels, depending on its location. Jim Bennett (bennett@esd.sgi.com)