Glitch when moving camera in OpenGL

Posted by CG on Stack Overflow See other posts from Stack Overflow or by CG
Published on 2009-12-16T07:01:39Z Indexed on 2010/06/18 15:13 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

I am writing a tile-based game engine for the iPhone and it works in general apart from the following glitch. Basically, the camera will always keep the player in the centre of the screen, and it moves to follow the player correctly and draws everything correctly when stationary. However whilst the player is moving, the tiles of the surface the player is walking on glitch as shown:

Compared to the stationary (correct):

Does anyone have any idea why this could be?


Thanks for the responses so far. Floating point error was my first thought also and I tried slightly increasing the size of the tiles but this did not help. Changing glClearColor to red still leaves black gaps so maybe it isn't floating point error. Since the tiles in general will use different textures, I don't know if vertex arrays can be used (I always thought that the same texture had to be applied to everything in the array, correct me if I'm wrong), and I don't think VBO is available in OpenGL ES. Setting the filtering to nearest neighbour improved things but the glitch still happens every ten frames or so, and the pixelly result means that this solution is not viable anyway.

The main difference between what I'm doing now and what I've done in the past is that this time I am moving the camera rather than the stationary objects in the world (i.e. the tiles, the player is still being moved). The code I'm using to move the camera is:

void Camera::CentreAtPoint( GLfloat x, GLfloat y )
{
 glMatrixMode(GL_PROJECTION); 
 glLoadIdentity();
 glOrthof(x - size.x / 2.0f, x + size.x / 2.0f, y + size.y / 2.0f, y - size.y / 2.0f, 0.01f, 5.0f);
 glMatrixMode(GL_MODELVIEW);
}  

Is there a problem with doing things this way and if so is there a solution?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about opengl-es