Crash when moving camera in OpenGL

I am writing a plate-based game engine for the iPhone, and it works, in general, in addition to the following crash. In principle, the camera will always keep the player in the center of the screen, and it moves to properly follow the player and draws correctly when it is stationary. However, while the player is moving, the tile surface of the player comes with a glitch, as shown:

http://img41.imageshack.us/img41/9422/movingy.png

Compared to fixed (correct):

http://img689.imageshack.us/img689/7026/still.png

Can anyone understand why this could be?


Thanks for the answers so far. The floating point error was my first thought, and I tried to slightly increase the size of the tile, but that did not help. Changing glClearColor to red still leaves black gaps, so maybe this is not a floating point error. Since tiles will use different textures in general, I don’t know if vertex arrays can be used (I always thought that the same texture should be applied to the whole array, correct me if I am wrong) and I do not think VBO Available in OpenGL ES. Setting filtering for the closest neighbor improved the situation, but a failure still occurs every ten frames or so, and a pixelly result means that this solution is not viable in any case.

The main difference between what I am doing now and what I have done in the past is that this time I am moving the camera, not the stationary objects in the world (i.e. tiles, the player is still moving). The code I use to move the camera:

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 this, and if there is a solution?

+4
iphone opengl-es camera sprite
source share
3 answers

My first guess would be a floating point rounding error . This can cause the coordinates for your ATVs to be slightly smaller, which will lead to gaps. to check this, you can try changing glClearColor () and see if the spaces with it have changed.

One solution to this would be to make the tiles a little large. Only a very small increment is required (e.g., 0.0001f) to cover this error.

Alternatively, you can try using Vertex Array or VBO to preserve your ground grid (ensuring that adjacent squares separate the vertices). I would expect this to fix the problem, but I'm not 100% sure - and it should also look faster.

+2
source share

This is sometimes caused by filtering problems on border texels. You can try using GL_CLAMP_TO_EDGE in your texture options.

0
source share

Due to filtering .. use the clip to the edge and leave a frame with 1 or 2 pixels. This is why we have an option for BORDER in the call to glTexImage ..


change of the 4th parameter from 0 to 1

0
source share

All Articles