PDA

View Full Version : Anisotropic Filtering Help



BSchare
12-14-2010, 03:09 PM
Hello people! Myself, along with a couple of friends, have been attempting to implement a small, textured, 3-dimensional house. For the most part, everything has gone quite swimmingly, but we've encountered a problem where images appear to be awkwardly stretched if viewed from a weird angle. A quick Google search seemed to hint that this problem required us to implement Anisotropic filtering, though very little is actually available in terms of code we can utilize.

If anyone could tell us why this fails to change anything, I would be most appreciative!

Below is our entire LoadTexture function.

float maxA;
GLuint LoadTexture(const char*filename, int width, int height)
{
GLuint texture;
unsigned char * data;
FILE * file;

file = fopen(filename, "rb");
if (file == NULL) return 0;
data = (unsigned char *)malloc(width*height*3);
fread(data, width*height*3,1,file);
fclose(file);

glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxA);
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,maxA);//Anisotropic Filtering Attempt


glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0 ,GL_RGB,GL_UNSIGNED_BYTE,data);
free(data);
return texture;
}

Alfonse Reinheart
12-14-2010, 03:16 PM
Because, according to the extension spec, anisotropic filtering doesn't work unless you have mipmaps.

BSchare
12-14-2010, 04:20 PM
Because, according to the extension spec, anisotropic filtering doesn't work unless you have mipmaps.

Thank you, and done!

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );

I've noticed a change, but the textures still appear stretched, leading me to believe that something is still wrong with my attempt to filter. Any other suggestions?

mhagain
12-14-2010, 05:51 PM
Your GL_TEXTURE_MAG_FILTER should be just GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR is not a legal value for it.

BSchare
12-14-2010, 07:59 PM
Your GL_TEXTURE_MAG_FILTER should be just GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR is not a legal value for it.

Changed! Thank you too! Though the problem remains. I figured I'd throw a screencap in too.

http://img.photobucket.com/albums/v123/TofuRunner/status.jpg

I know, I know. Very "Intro to Computer Graphics". But as you can see the grass in particular, looks really bad unless you move the camera downward, then the image quality improves. Any ideas?

arekkusu
12-14-2010, 10:43 PM
Because, according to the extension spec, anisotropic filtering doesn't work unless you have mipmaps.
This is false. Anisotropy is orthogonal to other filtering state.

Consider 2D blits:
http://developer.download.nvidia.com/SDK...oDecimation.pdf (http://developer.download.nvidia.com/SDK/9.5/Samples/DEMOS/Direct3D9/src/AnisoDecimation/docs/AnisoDecimation.pdf)