Sign in to follow this  

Texture error when camera moves

This topic is 1114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am making top-down tile based game in LWJGL. It all worked well before I tried to implement camera movement (so the player is always in the center).. When the camera moves (only horizontally) tiles appear lighter (it seems that lines are missing)... I found this: http://stackoverflow.com/questions/5243705/problem-with-gltranslatef but it doesn't answer my question. I do use glViewport / glOrtho....Then it says I must use integers for texture coordinates and vertex positions...I can't do that, because I use texture atlases (image coordinates are not 0 or 1)... Also I use floating-points for updating position... Here's some of my code:

// Camera class
public void follow(Player player) {
	x = (player.x + 16.0f) - WIDTH / 2.0f;
	y = (player.y + 16.0f) - HEIGHT / 2.0f;
}
// I think there is nothing wrong with this code, it gives correct results..

And player update code:

switch (moving) { // when key is pressed, moving is set to corresponding value and destination is set to next tile in that direction
case DOWN:
	y = Math.min(y + speed, destination);
	break;
case UP:
        y = Math.max(y - speed, destination);
        break;
case RIGHT:
	x = Math.min(x + speed, destination);
	break;
case LEFT:
        x = Math.max(x - speed, destination);
	break;
}

Then I use glTranslatef(-camera.x, -camera.y, 0.0f) before I draw anything... I do use glPushMatrix() and glPopMatrix() so that's not a problem....

The guy at Stack Overflow seems to have the same problem but I don't understand how I can fix it... (I use GL_NEAREST and scale everything by 2, by multiplying vertex positions by 2, not using glScalef (however, it gives the exact same results when I do use glScalef))...

I can't take a screenshot because every time I press PrtSc (or press New in Snipping Tool) it becomes normal for that part of second...

Thanks,

Mateja

PS: Sorry for really, really bad explanation of the problem....I've never encountered something like this before.

EDIT:

The problem happens even when I move camera by 1 (x++ instead of updating by player's position)...So it doesn't seem to be a floating-point issue..Weird..

Edited by MatejaS

Share this post


Link to post
Share on other sites

@Sponji I will make a small example and post it here.

@JTippets I guess they are co-planar because they are all at z position 0.0f.... However, I don't think it's z-fighting because everything is 2D...

Thanks for responses, guys :)

Share this post


Link to post
Share on other sites
If you're using OpenGL calls then it's 3D even if you are using ortho and aligned with the xy plane. The symptom you describe of "missing lines" hints very strongly of z fighting, which can occur with co-planar polygons regardless of ortho or camera orientation. For fun, try using differing values for z to see if any difference is made.

Share this post


Link to post
Share on other sites

This topic is 1114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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