在OpenGL中移动相机时出现毛刺 [英] Glitch when moving camera in OpenGL

查看:456
本文介绍了在OpenGL中移动相机时出现毛刺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone撰写一个基于图块的游戏引擎,除了下面的故障之外它一般工作。基本上,相机将始终保持播放器在屏幕的中心,它移动以正确跟随播放器,并在静止时正确绘制一切。然而,当玩家移动时,玩家正在行进的表面的瓦片如下所示:

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:

与固定(正确)相比:

img src =http://img689.imageshack.us/img689/7026/still.png/>

有没有人知道为什么会这样?

Does anyone have any idea why this could be?

感谢您的回应。浮点错误是我的第一个想法,我试着稍微增加瓷砖的大小,但这没有帮助。将glClearColor更改为红色仍会留下黑色空白,因此也许它不是浮点错误。因为tile一般会使用不同的纹理,我不知道是否可以使用顶点数组(我一直认为相同的纹理必须应用于数组中的所有内容,如果我错了,纠正我)不要认为VBO在OpenGL ES中可用。将滤波设置为最近邻改善了事情,但是毛刺仍然每十帧左右发生一次,像素结果意味着这个解决方案不可行。

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);
}  

这样做有问题吗? ?

推荐答案

我的第一个猜测是浮点舍入错误。这可能导致你的四边形的坐标只是一点点,导致你看到的差距。为了验证这一点,你可能想尝试改变glClearColor(),并看看是否间隙改变颜色。

My first guess would be floating point rounding error. This could cause the co-ordinates for your quads to be just a little bit out, resulting in the gaps you see. to verify this, you might want to try changing glClearColor() and seeing if the gaps change colour with it.

一个解决方案是让瓷砖稍大。

One solution to this would be to make the tiles slightly larger. Only a very small increment is needed (like 0.0001f) to cover over this kind of error.

或者,您可以尝试使用顶点数组 VBO 存储您的地面网格(确保邻接的正方形共享顶点)。我希望这可以解决这个问题,但我不是100%肯定 - 它也应该更快地呈现。

Alternatively, you could try using a Vertex Array or a VBO to store your ground mesh (ensuring that adjoining squares share vertices). I'd expect this to fix the issue, but I'm not 100% sure - and it should also render faster.

这篇关于在OpenGL中移动相机时出现毛刺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆