Issue with mipmapping - Textures fade to black

Started by
4 comments, last by Ignifex 15 years, 6 months ago
Hello, I am trying to enable mipmapping within my opengl code and am having trouble getting it to work correctly. The textures seem to fade to black with this being directly related to the resolution of the texture. The smaller the resolution the further the viewable distance. I have included some screenshots to more adequately convey what I am saying: Texture size 512x512: http://img357.imageshack.us/img357/8711/mipmappingissuetexturespm4.png Texture size 256x256: http://img339.imageshack.us/img339/8998/mipmappingissuetextureshz3.png Texture size 128x128: http://img357.imageshack.us/img357/8683/mipmappingissuetexturesmv9.png Texture size 64x64: http://img339.imageshack.us/img339/7831/mipmappingissuetexturesvh6.png Those screenshots were all taken with these lines in my code:

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_INT, image);

If these lines are instead replaced with (essentially disabling mipmapping):

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_INT, image);

then I get the following output (which is what I'd expect): Without mipmapping - Texture size 512x512: http://img392.imageshack.us/img392/1125/mipmappingdisabled512x5zi4.png I'm using the ppm file format for my textures, and my best guess is that the issue may be related to how the image data is stored, or that it may be due to the large file sizes (the 512x512 is 2.4MB) I wanted to check that this wasn't something else before I write a file loader for another format so that I can test this theory. I've worked on the problem on and off for a few days now and haven't been able to find a solution. Any advice that anyone has will be appreciated. Thank you all for your time.
Advertisement
Just a thought, but could it have anything to do with using GL_UNSIGNED_INT? Are you sure your texture data is stored as unsigned integers?
How to create textures, how enable mipmaps
http://www.opengl.org/wiki/index.php/Texture_Mapping

Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Yeah my texture is stored as an unsigned int,

GLuint *image;


unless I've done it wrong some how, but I don't think so.

I've read the link you supplied V-man. As far as I can tell I'm setting everything up correctly. I'm mostly looking for ideas about what might be wrong, if I've got an idea about where to look I should be able to track down the problem.

Thanks.
Not sure about this at all--but can you pass mipmapping to the mag filter?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Geometrian has a point.
GL_TEXTURE_MAG_FILTER must be either GL_NEAREST or GL_LINEAR.

This topic is closed to new replies.

Advertisement