Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!spool.mu.edu!uunet!shelby!neon!loan From: loan@Neon.Stanford.EDU (James P. Loan) Newsgroups: comp.sys.sgi Subject: Trouble drawing point-sampled polygons Message-ID: <1991Feb8.200816.20381@Neon.Stanford.EDU> Date: 8 Feb 91 20:08:16 GMT Organization: Computer Science Department, Stanford University Lines: 98 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? Sample program follows. thanks for any help with this trivial but annoying problem, pete loan loan@neon.stanford.edu /* Test file for problem with translating point-sampled polygons. * To see the problem: * (1) Compile this file: cc -o test test.c -lgl_s * (2) Get /usr/demos/bin/snoop running and turn Cmode on. * (3) Run the test program: test * (4) Use snoop to check out the HEIGHT of the two trapezoids * (5) Resize the test window so it is at least 700 pixels HIGH * (6) Use snoop again to check the HEIGHT of the trapezoids * (7) Edit this file so that the other ORTHO2 command is used. * (8) Repeat steps (1) - (6). */ #include #include main() { short val; long id, xs, ys; prefposition(100,300,100,200); id = winopen(""); winconstraints(); qdevice(ESCKEY); qdevice(REDRAW); qenter(REDRAW,id); while (1) { switch (qread(&val)) { case REDRAW: getsize(&xs,&ys); viewport(0,(Screencoord)xs-1,0,(Screencoord)ys-1); ortho2(-0.5,(Coord)xs+0.5,-0.5,(Coord)ys+0.5); /* ortho2(0.0,(Coord)xs+1,0.0,(Coord)ys+1); */ color(0); clear(); color(5); pushmatrix(); translate(0.0,(Coord)ys-25.0,0.0); trapezoid(); translate(0.0,-20.0,0.0); trapezoid(); popmatrix(); break; case ESCKEY: exit(0); } } } int pts[][2] = { {40,20}, {10,20}, {13,17}, {37,17} }; trapezoid() { bgnpolygon(); v2i(pts[0]); v2i(pts[1]); v2i(pts[2]); v2i(pts[3]); endpolygon(); }