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 ∈(0,1) | via texel coordinates (0,worh) |
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 ⇔ Smaller mipmap texture size
L=log2(maxEach derivative represents how fast is the texture coordinate changing from pixel to pixel on screen (in x or y axis)?