No this is not correct.

Look at figure 2.6 “vertex transformation sequence”, page 41, OpenGL spec 2.1.

gl_Position are the clip coordinates of the vertex.

From the clip coordinates, you first have to get the normalized coordinates with a perspective division:

vec3 n=gl_Position.xyz/gl_Position.w

Then apply the viewport transformation (section 2.11.1 controlling viewport, page 42)

vec2 lowerLeft; // lower left corner of the viewport, given

vec2 o; // center of the viewport, computed

// From end of page 42:

o.x=lowerLeft.x+WIDTH/2.0;

o.y=lowerLeft.y+HEIGHT/2.0;

vec3 win // window coordinates of the point

// from section 2.11.1

win.x=(WIDTH/2)*n.x+o.x

win.y=(HEIGHT/2)*n.y+o.y

// we don’t care about win.z for this computation

Then, because you are looking for point coordinates, you have to refer to “section 3.3.1 Basic Point Rasterization”, page 97.

“In the default state, a point is rasterized by truncating its x_w and y_w coordinates (…) to integer.”

So the operation is not round(), floor() or ceil() but truncate, so it is just a matter of casting a “float” into an “int”.

ivec2 FinalPos;

FinalPos.x=int(win.x);

FinalPos.y=int(win.y);

As a side note, chapter 3, page 90, remember that a fragment is a grid box (assumed square), located by its lowerleft corner, which lies on integer grid coordinates. The fragment’s center is offset by (1/2,1/2) from its lower left corner, and so lies on half-integer coordinates.