Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Texture Flicker (Orthographic 2D)

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Texture Flicker (Orthographic 2D)

    I've looked around for a while for a solution to this problem, and to no avail. The problem is that I am drawing tiles of 64.0f by 64.0f, with tile sheets of 128.0f by 128.0f. The size of the tile is divided by the size of the tilesheet to get a texture coordinate (based on the tile it needs to draw).

    I have checked these values, and they are 0.0f, 0.5f and 1.0f which are correct coordinates for the texture drawing. When stationary, the tiles draw fine. When the camera is moving however, I run into a problem and the textures flicker every now and again. It happens very fast but I was able to get a screenshot of one of the flickers occuring.



    I have drawn fat red arrows pointing to the problem. What confuses me is that this problem only occurs on a single row of tiles at a time when it happens, and it only happens while the camera is moving.

    I have read places that setting the projection right and bottom 0.5f less, which is used in the screenshot, and obviously doesn't solve the problem.

    Does anyone know what is happening here? I would post some code but I honestly don't know where the problem is occuring, so request anything needed.

  2. #2
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Texture Flicker (Orthographic 2D)

    Are you double-buffering and v-syncing?

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Re: Texture Flicker (Orthographic 2D)

    I am double-buffering. I have not explicitally enabled v-sync, though the program will not run over 60fps so I assumed it was already v-synced.

    The line does tend to appear on the same place of the window as each tile passes that point. The grass tiles appear to be taking a pixel too many from the sprite sheet (65 pixels instead of 64, though the coordinate is always 0.5f).

    Could it have something to do with the camera coordinates not being integral? The tiles do not move from their vertex coordinates but the camera can end up at a coordinate such as 3.8f for example with the way I have set it up. I don't see this being the problem however, it's just some additional information about what my application is doing.

  4. #4
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Texture Flicker (Orthographic 2D)

    It's hard to tell from your screenshot if this is happening at the same line on the physical display, or at some arbitrary point on the rendered surface.

    If it's the former it seems like a HW problem to me.
    i.e. Some kind of tearing or something.

    If it's the latter then it may be maths related as you say, or could it be some kind of z-fighting? When you draw these texture tiles are they on one QUAD or lots of QUADS, and how are you generating their geometry?

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Re: Texture Flicker (Orthographic 2D)

    The line is happening at the same place. On the screenshot, its a few tiles below the stick figure, and flickers at that location each time the bottom of the tile passes that location (though, it does occur at other places, but again, those places seem to be the same places each time, such as a few tiles above the stick figure also).

    The tiles are drawn using a vertex array, which are drawn as triangle strips

    Code :
    glTexCoordPointer(2, GL_FLOAT, 0, textureCoordData);
    glVertexPointer(3, GL_FLOAT, 0, vertexData);
    glColor4f(1.0f, 1.0f, 1.0f, getAlpha());
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    All the tiles are drawn with a Z value of 0.0f at this time, but they are always drawn in the same order each frame. The texture coordinate is obtained using a coordinate step, which denotes how big each tile is for a texture coordinate (i.e. if the texture is 128.0f and the tile is 64.0f, each tile has a 0.5f texture coordinate increase)

    Code :
    xCoordStep = getWidth() / textures[getTexture()].getWidth();
    yCoordStep = getHeight() / textures[getTexture()].getHeight();

    I do think this method could be problematic in the future, but at the moment it always obtains the values of 0.0f, 0.5f and 1.0f.

    The vertex data for the tiles never changes. The vertecies for each tile touches each other (i.e. one ends at 64.0f, and the next starts at 64.0f).

    However, this problem only occurs when I'm moving the camera. As mentioned, the camera can be located at a non-integral position such as 3.8f. But from what I see, the tile is for some reason taking an extra pixel for the texture even though the coordinate is always at 0.5f, and the line always occurs at the same place in the window as stated in the first paragraph. Here is a screenshot of the tilesheet with an arrow pointing to the row of pixels it seems to be taking.


  6. #6
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Texture Flicker (Orthographic 2D)

    I've seen similar things to this on my landscape code and used a kind of overdraw to get around it.. Basically it was because some of the vertices were not matching up as I expected. So I was coming from that perspective with a couple of my suggestions.

    I can't be much more help really other than to suggest toggling depth buffer writing and also depth testing (if you have it on), but that's just to eliminate weird z stuff as a possibility.

    How is the "stick guy" drawn? It's seems to be a bit significant that it's happening above and below him...

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Re: Texture Flicker (Orthographic 2D)

    I appreciate your help.

    The stick figure is drawn in exactly the same way. Everything drawn on the screen derives from a sprite class, which draws using the vertex buffer as previously mentioned.

    I have been playing about with the projection (since for some reason the tiles weren't drawn at full size), and the problem is consistant now. It was the texture being off by one coordinate, but only when moving the camera. Every tile now has one pixel extra.


    When the camera is not moving however, the texture renders fine.



    So I have pretty much concluded the camera has something to do with it, but I have tried everything and it seems that by just moving the camera, the texture coordinates don't work. Has this been a problem for you?

  8. #8
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Texture Flicker (Orthographic 2D)

    I am by no means an expert on the older FF aspects of OpenGL, having spent a lot of my time with GL working with shaders, but just thinking out-loud perhaps this has something to do with why older texture implementations had the ability to have 1 pixel borders / skirts..

    Maybe someone else with a bit more experience with that could shed some light?

  9. #9
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Texture Flicker (Orthographic 2D)

    Could you show us how you setup tile textures? Do you use linear filtering? What wrapping mode do you use?

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

    Re: Texture Flicker (Orthographic 2D)

    Maybe change texture clamp mode to GL_CLAMP_TO_EDGE ?
    Make sure you don't have antialiasing enabled.
    Try to zoom in, maybe artifacts will be easier to see.

    What is you video card/OS/driver version ?

Page 1 of 2 12 LastLast

Similar Threads

  1. Texture Flicker in the Distance
    By Revanz in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 11-27-2015, 11:09 AM
  2. Texture mapping in orthographic parallel view
    By EpSiLoN in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-20-2003, 05:44 AM
  3. Texture flicker?
    By HemiMG in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-16-2002, 04:16 PM
  4. Flicker .......help!!!!!!
    By akira_lm in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-27-2001, 07:51 PM
  5. Flicker ????
    By yayaya in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-25-2001, 02:47 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