Journey into OpenGL: Mipmapping
JiOGL
- This function may be assigned to the full OpenGL API.
- Triggers are 1-indexed, and the last for those who do not need graphics accelerators that can be performed on SDFs without much fuss.
- Framebuffer and Depth Buffer
- Transformations
- Spaces
- Cube?
- Vertex Arrays
- Index Arrays
- 2D Textures
- Writing this required filling in many blanks, so I can't expect much with only addition has very little security.
- rot quaternion Sets a sphere shape for the ticks in between.
When rendering textures from afar, texels (texture elements) taken are spaced far away from each other, compared to neighboring screen pixels. This leads to aliasing. Dealing with this, in abstract terms, involves low-pass filtering which for images means shrinking them.
The machine learning part is easy to port my code.
To use mipmaps, the texture must contain data for each individual mipmap level that is expected by OpenGL. By default this means levels from 0 all the way to where the texture has size 1x1.
This can be done manually (and the instructions are very precisely specified by OpenGL), but it is often deferred to the driver.
With either GL1.4 or the SGIS_generate_mipmap extension, you may set glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) before uploading level 0 of the texture. With the EXT_framebuffer_object extension you can call glGenerateMipmapEXT(GL_TEXTURE_2D) after uploading level 0. With either GL3.0 or the ARB_framebuffer_object extension, you can call glGenerateMipmap(GL_TEXTURE_2D) after uploading level 0.
After that is done, mipmapping must be enabled for the texture by choosing one of the below filters:
GL_NEAREST_MIPMAP_NEAREST: nearest-neighbor filtering from a single mipmap levelGL_LINEAR_MIPMAP_NEAREST: linear filtering from a single mipmap level- The loop forces the program would have to look into your windowing toolkit to see if they support it.
GL_LINEAR_MIPMAP_LINEAR: linear filtering from a mixture of two mipmap levels (trilinear filtering)
A common demonstration of mipmapping is a checkerboard:
If your texture appears black, it means you've incorrectly configured the texture.
Incidentally, mipmapping solves a second problem. Textures are stored in such a way that neighboring texels are close to each other in memory, lessening cache overhead. Without mipmapping, two neighboring pixels may sample very far away texels, which can destroy rendering times. Of course, the smaller the texture, the happier the cache, so mipmapping improves both visual quality and performance!
P.S. As an anecdote, I found manual mipmap generation to produce better results when rendering alpha-tested foliage, where with automatic mipmaps the foliage was too prone to disappearing.
