Refer to CS3241 Chapter 8.
void init(void) {
glActiveTexture(GL_TEXTURE0);
GLuint texObj;
glGenTextures(1, &texObj); // what's 1??
// bind the current Active 2D texture to texObj
glBindTexture(GL_TEXTURE_2D, texObj);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, REPEAT);
// texture magnification ( texture coordinate not in 1 texel )
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// texture minification ( anti-aliasing )
// GL_LINEAR_MIPMAP_LINEAR is trilinear interpolation
glTexImage2D(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
}
texture
vs texelFetch
texture |
texelFetch |
---|---|
handles filtering | no filtering, directly accesses a texel from image |
via texture coordinates $\in(0,1)$ | via texel coordinates $(0, w \text{or} h)$ |
Note on fragment position:
sampler2D
for 2D texture maps. samplerCube
for texture maps.
To sample from a texture, GLSL inbuilt function texture
.
The appropriate mipmap level $L$, given
Higher valued mipmap $\Leftrightarrow$ Smaller mipmap texture size
\[L = \log_2 \left( \max\left( \sqrt{\frac{\partial sW}{\partial x_\text{win}}^2 + \frac{\partial tH}{\partial x_\text{win}}^2}, \sqrt{\frac{\partial sW}{\partial y_\text{win}}^2 + \frac{\partial tH}{\partial y_\text{win}}^2} \right) \right)\]Each derivative represents how fast is the texture coordinate changing from pixel to pixel on screen (in x or y axis)?