Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Completely disable filtering

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    17

    Completely disable filtering

    I have a texture I read in which I do not want filtered. The reason is that it represents very discrete data about a real-world scenario, and I need the edge between colors to be abrupt. When reading in the texture, my code includes:
    Code :
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    However, when I look at my image it is still very roughly filtered. The filter is only in one axis direction; the other is not filtered. The difference is very stark between using GL_LINEAR and GL_NEAREST, but GL_NEAREST still applies some filter which I can't seem to turn off.

    I am very new at opengl coding, so excuse my lack of useful terminology.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    17

    Re: Completely disable filtering

    If this helps, this is what I'm seeing...


  3. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,661

    Re: Completely disable filtering

    How sure are you this filtering isn't in the source texture data?

    I.e. read back and print your texel values.

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Completely disable filtering

    gluBuild2DMipmaps pre-scales (and thus blurs) the image if it's NPOT. How do you upload the texture data to the gpu?

  5. #5
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Completely disable filtering

    Quote Originally Posted by openglnub
    If this helps, this is what I'm seeing...
    For me, there is no filtering at all on the picture.
    What do you want to see instead ?

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    17

    Re: Completely disable filtering

    Thank you for the replies. I'm away for part of today, but when I get back I'll take a closer look at how I read in the texture. The source (a ppm image) has only three color values, blue, pink, and white. The blending is what I want to avoid. I believe I fill the texture with the values, cell by cell, of the ppm, as I recall.

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    17

    Re: Completely disable filtering

    What I'd like to see...



    Note that there's another blue rectangle drawn in the picture above, so that's a known discrepancy. Also the zoom levels are a bit different.

    I use OpenCV to read in the image (cvLoadImage) to get an IplImage structure. Then (after flipping the image for some coordinate frame problems) I make the following OpenGL calls. Note that channels, width, and height are filled from the OpenCV image structure.

    Code :
    glBindTexture(GL_TEXTURE_2D, textureId); 
     
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0);
     
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 
     
    if( channels == 3)
    {
      gluBuild2DMipmaps(GL_TEXTURE_2D, channels, width, height, GL_RGB, GL_UNSIGNED_BYTE, newData);
    }
    else if( channels == 4)
    {
      gluBuild2DMipmaps(GL_TEXTURE_2D, channels, width, height, GL_RGBA, GL_UNSIGNED_BYTE, newData);
    }

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Completely disable filtering

    Indeed, Ilian Dinev was right : you should not use gluBuild2dMipmaps if you want to keep your source data intact. And there no point in building mipmaps if GL_TEXTURE_MIN_FILTER is GL_NEAREST.

    It sounds like your image is not power-of-two.
    If your hardware supports it, you can use it directly with glTexImage2D :
    http://www.opengl.org/wiki/NPOT_Textures
    Otherwise, you will have to pad the image data up to the nearest power of two in both width and height, and adapt texture coordinates accordingly.

  9. #9
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    17

    Re: Completely disable filtering

    So, if I replace my mipmaps code with a call to glTexImage2D to define the textures, it may work? And if not, I can simply pad to a power-of-2 size?

    When I try this, I no longer see my texture. The computer I'm using is fairly new, but is there any way if I can see whether or not it's capable of displaying NPOT textures?

    Replaced mipmap lines with:
    Code :
    if( channels == 3 )
    {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, newData);
    }
    else if( channels == 4 )
    {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, newData);
    }

  10. #10
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Completely disable filtering

    The internalFormat should be GL_RGB(A)8 instead of just GL_RGB(A), but the problem is more likely to be caused by no NPOT support.


    First you should do a check with a 256*256 texture, so that NPOT problems are ruled out.
    If that does not work, then your problem lies elsewhere...

    If it works, then you probably don't have NPOT support.
    To check if the GL_ARB_texture_non_power_of_two extension is available on your hardware, here is a tutorial about the concept and practice of extensions in OpenGL :
    http://www.opengl.org/sdk/docs/tutor...extensions.php
    I recommend using GLEW or Glee to make things easier.

Page 1 of 3 123 LastLast

Similar Threads

  1. Disabling Texture filtering completely in Modern Opengl
    By PixelClear in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 10-08-2017, 11:45 AM
  2. Can't disable MSAA completely with 8+ MSRT
    By shadocko in forum OpenGL: Drivers
    Replies: 1
    Last Post: 06-08-2010, 02:02 PM
  3. I'm completely new here, and to coding.
    By in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 06-17-2003, 11:02 AM
  4. How to disable texture filtering
    By farid in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-22-2003, 01:07 PM
  5. Help... Completely out of ideas here...
    By tiuborg in forum OpenGL: User Software
    Replies: 1
    Last Post: 12-17-2001, 06:16 PM

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