Results 1 to 6 of 6

Thread: Anisotropic Filtering Help

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    3

    Anisotropic Filtering Help

    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;
    }

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,676

    Re: Anisotropic Filtering Help

    Because, according to the extension spec, anisotropic filtering doesn't work unless you have mipmaps.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    3

    Re: Anisotropic Filtering Help

    Quote Originally Posted by Alfonse Reinheart
    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?

  4. #4
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: Anisotropic Filtering Help

    Your GL_TEXTURE_MAG_FILTER should be just GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR is not a legal value for it.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    3

    Re: Anisotropic Filtering Help

    Quote Originally Posted by mhagain
    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.



    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?

  6. #6
    Senior Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    891

    Re: Anisotropic Filtering Help

    Quote Originally Posted by Alfonse Reinheart
    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

Similar Threads

  1. Anisotropic Filtering
    By mhagain in forum OpenGL: General
    Replies: 2
    Last Post: 06-02-2014, 01:31 AM
  2. Anisotropic filtering in GL 3.3+?
    By imported_JoshKlint in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 03-19-2011, 05:54 AM
  3. Anisotropic filtering
    By reggae in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-06-2003, 07:06 AM
  4. Anisotropic filtering
    By B_old in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-30-2002, 08:38 AM
  5. anisotropic filtering
    By Diapolo in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-27-2000, 07:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean