I am experimenting with mip-maps for the first time in OpenGL. I followed this tutorial, which builds on this code. In the fragment shader I did the following modification:
vec2 uv = UV;
uv.y = 1-UV.y;
color = texture( myTextureSampler, uv, 1 ).rgb;
... which flips the y axis values (part of the tutorial exercise to get the texture right). It also sets the LOD bias on the final row, so that I can view the coarser details in the texture.
I also modified the cpp file of the tutorial:
line 29, turned off super-sampling anti-aliasing:
// glfwWindowHint(GLFW_SAMPLES, 4);
line 87, create the mip-maps:
GLuint Texture = loadDDS("uvtemplate.DDS");
glBindTexture(GL_TEXTURE_2D, Texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
from line 183, implemented simple camera movement (to get a good overview of its appearance):
...
GLfloat rot = 0.0;
do{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programID);
rot += 0.003;
View = glm::lookAt(
glm::vec3(glm::cos(rot)*4.8, glm::cos(rot/3)*1.3+ 1.3 ,glm::sin(rot)*2.9),
glm::vec3(0,0,0),
glm::vec3(0,1,0));
MVP = Projection * View * Model;
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
...
I expected to see a blurred version of the input texture, instead it looks awful:
The jagged edges on the bottom side of the "1" makes no sense to me at all. They appear on some of the figures in the texture, but not others.
The input texture format is .DDS, could that somehow be the source of the problem? Could it be a bug in my driver? I am on Ubuntu Linux 16.04, with the newest drivers as found in the PPA:s. Searched online, found nothing on this topic.
edit: I also experimented with some openGL settings, like this:
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
GLfloat anisoVal;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisoVal);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoVal);
but it did nothing.
The source of the problem was an old driver. The computer I was working on had a special setup where non-standard PPAs had replaced the ubuntu (Canonical) supported ones. I could not access some of those outside of a special intra-net (at customer). Didnt read the error messages at sudo apt-get update.
The lesson from my question: The sort of bugs that can arise, and how they can bite you is unpredictable if you do not update your graphics drivers.... even if you think you have updated them.... double and tripple check. Thanks to @derhass and @Rabbid76 for leaving helpful remarks.