gl_Position is in uniform post projection coordinates.
It is worth noting that gl_Position is the (4d) position of the vertex, and gl_FragCoord is the (2d) position of the fragment.
The operations that occur between them are
- primitive assembly (for creating a triangle of three vertices, for example)
- clipping (i.e. cut a triangle in several triangles that are inside the view if it does not initially fit)
- application to view
- rasterization (take these triangles and generate covered fragments)
So, although you can find a formula for transforming an arbitrary point represented from the position of a vertex in 2d, which is a viewport, it is not useful in itself, since the generated fragments do not directly align the position of the vertices. formula for obtaining the 2d coordinate of the vertex
2d_coord_vertex = viewport.xy + viewport.wh * (1 + gl_Position.xy / gl_Position.w)/2
Again, this is not gl_FragCoord. Check the rasterization information in the GL specification if you want to get deeper knowledge.
I'm not sure what you mean by "replacing the openGL function", but rasterization is nontrivial and goes beyond the scope of the SO answer.
source share