What happens at the end of a vertex shader in OpenGL?
At the end of each vertex shader run, OpenGL expects the coordinates to be within a specific range and any coordinate that falls outside this range is clipped. Coordinates that are clipped are discarded, so the remaining coordinates will end up as fragments visible on your screen.
How to transform vertex coordinates from view to clip-space?
To transform vertex coordinates from view to clip-space we define a so called projection matrix that specifies a range of coordinates e.g. -1000 and 1000 in each dimension. The projection matrix then transforms coordinates within this specified range to normalized device coordinates (-1.0, 1.0).
When do you apply perspective division in OpenGL?
OpenGL requires that the visible coordinates fall between the range -1.0 and 1.0 as the final vertex shader output, thus once the coordinates are in clip space, perspective division is applied to the clip space coordinates: o u t = (x / w y / w z / w)
How to create an orthographic projection matrix in GLM?
To create an orthographic projection matrix we make use of GLM’s built-in function glm::ortho : glm::ortho (0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f); The first two parameters specify the left and right coordinate of the frustum and the third and fourth parameter specify the bottom and top part of the frustum.
Are there any good resources for learning OpenGL?
Throughout the internet there are thousands of documents, books, and resources on learning OpenGL, however, most of these resources are only focused on OpenGL’s immediate mode (commonly referred to as the old OpenGL), are incomplete, lack proper documentation, or are not suited for your learning preferences.
When does OpenGL clip coordinates close to the camera?
Whenever the near value of your perspective matrix is set too high (like 10.0), OpenGL will clip all coordinates close to the camera (between 0.0 and 10.0), which can give a visual result you maybe have seen before in videogames where you could see through certain objects when moving uncomfortably close to them.