Hi.
I work on my own rasterizer. I’m confused what is the pixel center in OpenGL and how top-left rule work.

OpenGL spec tell us:
"
A fragment is located by its lower left corner, which lies on
integer grid coordinates. Rasterization operations also refer to a fragment’s center,
which is offset by (1/2; 1/2) from its lower left corner (and so lies on half-integer
coordinates)
"

Does it mean if the vertex coordinates are (1.0, 1.0), rasterizer should calculate value of color,texture and coordinate of point (1.5, 1,5)?
And if the vertex coordinates are (1.2, 1.2) should we floor them and add 0.5?

In many computer graphics articles/books (Shirley P. Fundamentals of CG) we can see that pixel center is (1.0, 1.0) (and bottom/left coordinates of pixel are (0.5, 0.5) so we can use ceil function to implement top-left rule.

It’s more complicated than that. I’m assuming you’re talking about rasterizing an area (such as a triangle) rather than a line or a point. There’re quite different problems.

In the case of rasterizing an area, it initially has nothing to do with where vertex coordinates are. Initially it has everything to do with whether the center of a pixel fragment is inside the area being rasterized or not. If the center of a pixel fragment is inside the area, then the rasterizer interpolates the attributes associated with the vertices that define the area, but if it is outside, then that pixel fragment is discarded.

To do the interpolation, the actual coordinates of the vertices defining the area being rasterized are used to determine where, proportionally, the center of the pixel fragment is within that area. Those same proportions are used to interpolate between the attributes associated with the vertices defining the area.

Now it is clear for me. But I want to understand how it works(in math).
Is it right to use ceil function during interpolation of edge do decide what pixel is inside or outside area?

I’m not sure I completely understand your last question, but let me try. There are quite a few steps to determining whether a pixel center is inside an area. So, your question isn’t specific enough for me to interpret what you mean. Where, exactly, are you thinking of using the ceil function in your interpolation? You can’t look at a single edge of an area, no matter how you interpolate that edge, and determine whether a pixel is inside the area or not. You just can’t look at edges in isolation to determine whether something is inside or outside an area partially defined by that edge. A single edge can partially define two side-by-side areas, and any given pixel can be in one of the areas or the other. Just looking at the edge alone can’t tell you which area the pixel is in. You fundamentally have to consider area, not lines, when determining whether a pixel is inside an area or not.

Having looked at the mesa triangle rasterizer over the last couple of days I can’t fathom why there is a half-pixel offset in (-0.5, -0.5) in x and y at the start of the rasterization…? Can somone explain this?

Initially the pixel offset applied to the window coordinates is (0.5, -0.5) in x and y but during span rendering all the pixels within a triangle (or satisfying the top-left fill convention) are actually shifted to the left by 1 pixel. The net effect is a shift in window coordinates by (-0.5, -0;5) in x and y.

This has been puzzling me for a while. Can someone help?

To answer my own question, mesa must surely have the lower-left corner of the screen in window coords @ (-0.5, -0.5) with the first pixel originating @ (0.0, 0.0). In other words, mesa pixel centres are indeed at integer (and not half-integer) locations…