Expand description
General graphics-related utility functions
§Coordinates
The gl_Position output of the last GLSL vertex processing stage (vertex
shader, tessellation shader, or geometry shader) is in clip space, that is
4D homogeneous (projective) coordinates (x, y, z, w). During vertex
post-processing, clip space coordinates are transformed to normalized device
coordinates (NDCs) by perspective divide and clipped to the range
[-1.0, 1.0] in the x, y, and z coorinates. Finally the viewport transform
takes NDCs and outputs screen space (or window space) coordinates, which
are 2D device coordinates + a 1D depth coordinate, on which rasterization is
performed to produce fragments.
2D
2D x,y coordinates normalized to [-1.0, 1.0] can be passed through to vertex post-processing unmodified. This is the case with shader pipelines that specify inputs are in “ClipSpace”; the pass-thru vertex shader will add a z component of 0.0 and a w component of 1.0.
(Note: as of v0.6.0 none of the default draw2d resources use clip space rendering pipelines)
Even though the ultimate output of vertex post-processing is 2D screen space
(device) coordinates, in order to render screen-space input vertices, they
must be transformed to clip space by vertex processing. Two utility
functions are provided to convert between screen space and normalized
coordinates: graphics::screen_2d_to_ndc_2d and
graphics::ndc_2d_to_screen_2d. Both require screen dimensions as input.
Functions§
- ndc_
2d_ to_ screen_ 2d - Maps OpenGL NDC coordinates to screen coordinates based on a given screen resolution.
- projection_
mat_ orthographic - Convenience method that calls
math::orthographic_rh_noon the givenFrustmPlanesstruct - projection_
mat_ perspective - Convenience method calling
Matrix4::perspective_rh_noto construct a right-handed perspective matrix with -1 to 1 clip planes, equivalent to thegluPerspectivefunction. - screen_
2d_ to_ ndc_ 2d - Convert screen coordinate to OpenGL NDC based on a given screen resolution.