Results 1 to 4 of 4

Thread: OpenGL texture flickering when rendering only parts of texture

  1. #1
    Newbie Newbie
    Join Date
    Jun 2015
    Posts
    4

    OpenGL texture flickering when rendering only parts of texture

    Hi, I have a texture of 64x64 where there are 4 separate textures of 32x32 (For tilesets so I don`t have separate texture for every tile set)

    Now, I know how to use UV etc. the problem is, when I cut it so every peace has it`s own uv rect from texture, I see flickering and lines etc. on screen.

    Here is the example picture

    When I enable mip mapping, I get texture blending between borders like here:

    Blendingproblem.PNG

    When I disable mip mapping, I get flickering, strange lines across those textures etc.

    Capture.jpg

    This are my texture parameters after texture binding:

    Code :
    glTextureParameteri(texture.id, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTextureParameteri(texture.id, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
    glTextureParameteri(texture.id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTextureParameteri(texture.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glGenerateMipmap(GL_TEXTURE_2D);

    Please, could you give me some advice? My UV coordinates are mapped ok (0.0f, 0.0f, 0.5f, 0.5f) for example.

    Thanks.

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    This is all normal, expected behaviour with this kind of setup.

    You should use a texture array instead.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,112
    Linear filtering, tiles and arbitrary scaling don't play well together. Mipmaps can sometimes be an issue, but shouldn't be relevant here unless the scale factor drops below 1/32.

    Array textures will fix the problem, but they require OpenGL 3 (which may be considered excessive for a 2D tile map). You'll also need to use a wrap mode of GL_CLAMP_TO_EDGE instead of GL_REPEAT.

    The problem with linear filtering is that it can result in blending together texels which belong to different tiles. There are ways to avoid the problem without resorting to array textures, but they're more work. They boil down to two basic options:

    1. Prevent the blending from occurring by insetting the texture coordinates by half a texel, so that the texture is never sampled in the region where the texels which would be blended belong to different tiles. This requires either disabling mipmaps or adjusting the inset according to the mipmap level (and disabling blending between mipmaps, as different levels will no longer be aligned).

    2. Ensure that the blending doesn't matter by laying out the tile maps so that there is no discontinuity at the boundary between tiles (which includes the wrap-around boundary if you're using GL_REPEAT). In practice, this may require some degree of redundancy in the tile map.

  4. #4
    Newbie Newbie
    Join Date
    Jun 2015
    Posts
    4
    Quote Originally Posted by GClements View Post
    Linear filtering, tiles and arbitrary scaling don't play well together. Mipmaps can sometimes be an issue, but shouldn't be relevant here unless the scale factor drops below 1/32.

    Array textures will fix the problem, but they require OpenGL 3 (which may be considered excessive for a 2D tile map). You'll also need to use a wrap mode of GL_CLAMP_TO_EDGE instead of GL_REPEAT.

    The problem with linear filtering is that it can result in blending together texels which belong to different tiles. There are ways to avoid the problem without resorting to array textures, but they're more work. They boil down to two basic options:

    1. Prevent the blending from occurring by insetting the texture coordinates by half a texel, so that the texture is never sampled in the region where the texels which would be blended belong to different tiles. This requires either disabling mipmaps or adjusting the inset according to the mipmap level (and disabling blending between mipmaps, as different levels will no longer be aligned).

    2. Ensure that the blending doesn't matter by laying out the tile maps so that there is no discontinuity at the boundary between tiles (which includes the wrap-around boundary if you're using GL_REPEAT). In practice, this may require some degree of redundancy in the tile map.
    Thanks, I will try changing a code a bit or making my UV coordinates not go for example (0, 0, 0.5, 0.5), but (0, 0, 0.5 - 0.05, 0.5 - 0.05).
    Also those array textures seem like a bit of work, also for restructuring the code a bit....

Similar Threads

  1. Replies: 1
    Last Post: 12-26-2014, 04:57 PM
  2. Texture Flickering on the Right Side of the Screen
    By _ShaderRookie_ in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-08-2011, 08:58 AM
  3. Very confused with transparent parts of texture?
    By Andy Gilbert in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-10-2010, 12:16 PM
  4. what is the reason of texture mapping flickering
    By victorswan in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 07-31-2003, 04:38 AM
  5. Texture flickering problem.
    By zenon in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-24-2003, 12:21 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