Sign in to follow this  
MatejaS

LWJGL glTranslatef causes texture flicker

Recommended Posts

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).

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this