LWJGL glTranslatef causes texture flicker

Started by
5 comments, last by vstrakh 9 years, 2 months ago

Hello,

I am making a platformer game using Java and LWJGL.

I've run into a problem: when the camera moves, the tiles flicker...

I am using glTranslatef to translate...The camera can only move in y direction.

It is flickering more when in windowed mode, but is noticeable in full screen too. I do have v-sync enabled.

This has happened to me before, and I asked a question here on GameDev (http://www.gamedev.net/topic/663208-texture-error-when-camera-moves/), but the answers didn't help me. One of the answers was that it could be z-fighting but I tried to disable GL_DEPTH_TEST, increase clear depth and other stuff but it didn't work.. I'm not sure if it is a problem in code, or with my graphics card and drivers...

Has anyone encountered this? How did you solve it?

Thanks.

PS: Just a note, I am using texture atlases (divide coordinates by texture width/height so they are between 0.0f and 1.0f).

Advertisement

It's not about depth. It's about texture filtering.

To get sharp pictures you must align your polygons, so every sampled texel will be rendered in screen pixel exactly.

When you smoothly move sprite, screen pixel covers adjacent texels. Those will be blended, and you will get impressions of flickering texture.

Thanks for your reply, @vstrakh! :)

I understand what you are saying, but I'm not sure how to implement it in code..

I use min/mag filter GL_NEAREST, because my game is pixel-art. I scale up width/height but not coordinates, so actually I always multiply coordinates by 2...Is this a problem, as I did the same thing in my last post's game?

MatejaS


I'm not sure how to implement it in code..

Probably easiest would be to setup such projection matrix, that your screen space measured in pixels.

I.e. it spans from 0 to window_width, and not from -1 to +1.

Then you manipulate with sprites in pixels, rounding sprite coordinates to closest integers.

Here's little app to play with. It creates 800x600 window, loads png and moves it around, changing scale on the fly.

See if there's flickers.

There is no flickering in your example...

I also have 800x600 projection matrix. I think the problem might be that I scale tile width/height by 2 but not the tile coordinates..I'll try to change that and see what happens.

Thank you very much for your help :)


I think the problem might be that I scale tile width/height by 2 but not the tile coordinates

That's irrelevant. You can scale tile size separately from tile location.

My sample doesn't scale location. Those "-width*0.5*scale" is only to find center of sprite, so that center will move around screen center.

This topic is closed to new replies.

Advertisement