I understand why one should specify pixel coordinates at pixel centers, the confusion that can happen otherwise. But why would I want to render filled primitives at pixel edges? Why would the GL not consider painting the wrong pixel in this case as well? If a vertex sits at a fragment edge, there are a minimum of 2 candidate fragments to be painted.

Also, does the magical 0.375 constant have anything to do with rounding errors?

AFAIK, the best thing would be to simply use float coordinates, unless rounding errors can be an issue (because of the modelview matrix). Certainly, if the matrix had a translation component I could imagine these arising.

Also:

http://msdn.microsoft.com/en-us/library/ms537007%28VS.85%29.aspx

The parameters width and height are the dimensions of the viewport. Given this projection matrix, place polygon vertices and pixel image positions at integer coordinates to rasterize predictably. For example, glRecti(0, 0, 1, 1) reliably fills the lower-left pixel of the viewport, and glRasterPos2i(0, 0) reliably positions an unzoomed image at the lower-left pixel of the viewport. However, point vertices, line vertices, and bitmap positions should be placed at half-integer locations. For example, a line drawn from (x (1) , 0.5) to (x (2) , 0.5) will be reliably rendered along the bottom row of pixels in the viewport, and a point drawn at (0.5, 0.5) will reliably fill the same pixel as glRecti(0, 0, 1, 1).

But why is there no ambiguity when rasterizing the rect? Any how to decide where to put the vertices of 2D triangles?

ZbuffeR

09-16-2011, 02:13 AM

Forget about line and pixel drawing, just think about drawing a smooth surface out of triangles.

You have lots of triangles sharing an edge, using exact same vertex coordinates on one side or the other right ?
Now think about a blended surface : what you propose ("If a vertex sits at a fragment edge, there are a minimum of 2 candidate fragments to be painted") means the edges will be drawn twice, which will display some sort of wireframe on top of filled primitives. Bad.

Get the OpenGL spec, and go for "diamond exit rule" or something like that :
http://www.opengl.org/registry/

ugluk

09-16-2011, 03:54 AM

Ahh, now I remember from the old days, when I was writing a software triangle rasterizer. Yeah, I've had to be careful that the pixels I painted were either inside the triangle or at the left or top boundary.